Ext.define("IceCap.util.Handler", {

	singleton: true,

	config: {
		scaling: {
			colSize: 9.7,
			textSize: 16,
			defaultWidth: 18,
			defaultHeight: 24,
			lineHeight: 28
		},
		sessions: [],
		fixed: true,
		scaleSize: 14,
		marginValue: 4,
		scale: 1,
		serviceUrl: "/icecap/icecap.aspx",
		provider: null,
		measureItem: null,
		boldItem: null,
		normalWidth: 0,
		boldWidth: 0,
		changed: false
	},

	FFW: {
		// FFW identification flag (0 - 1)
		// Bypass (2)
		// Dup or Field Mark Enable (3)
		//  Modified Data Tag (MDT) (4)
		// Field Shift/Edit Specification (5 - 7)
		// Auto Enter (8)
		// Field Exit Required (FER) (9)
		// Monocase (10)
		// Reserved (11)
		// Mandatory Enter (ME) (12)
		// Right Adjust/Mandatory Fill (MF) (13-15)
		IDENT_FLAG: (1 << 0),
		BYPASS: (1 << 1),
		DUP_OR_MARK: (1 << 2),
		MOD_DATA: (1 << 3),
		APLHA_SHIFT: (1 << 4),
		ALPHA_ONLY: (1 << 5),
		NUMERIC_SHIFT: (1 << 6),
		NUMERIC_ONLY: (1 << 7),
		KATAKANA_SHIFT: (1 << 8),
		DIGITS_ONLY: (1 << 9),
		IO_FEATURE: (1 << 10),
		SIGNED_NUMERIC: (1 << 11),
		AUTO_ENTER: (1 << 12),
		EXIT_REQ: (1 << 13),
		MONOCASE: (1 << 14),
		MAND_ENTER: (1 << 15),
		RA_NONE: (1 << 16),
		RA_ZEROFILL: (1 << 17),
		RA_BLANKFILL: (1 << 18),
		RA_FILL: (1 << 19),
		RA_RESERVED: (1 << 20),
		RA_MANDATORY: (1 << 21),
		RA_READONLY: (1 << 22)
	},

	typeMode: {
		OVERWRITE: 1,
		INSERT: 2
	},

	requires: [
		"IceCap.state.session.Provider",
		"IceCap.state.local.Provider",
		"IceCap.util.Watchdog"
	],

	constructor: function(o_config) {

		var i_self = this;
		i_self.initConfig(o_config);

		var i_provider = Ext.widget("icecap-state-local-provider", {});

		i_self.setProvider(i_provider);
		return this;
	},

	getPath: function(o_config) {

		var s_base = IceCap.util.Handler.getServiceUrl();
		var s_session = o_config.session;
		var s_activeTerminals = IceCap.util.Handler.getActiveTerminals();

		if (s_activeTerminals) {
			Ext.apply(o_config, {
				activeTerminals: s_activeTerminals
			});
		}

		return s_session + "" + s_base + "?" + Ext.urlEncode(o_config);
	},

	getX: function(n_col) {
		return Math.ceil(n_col * IceCap.util.Handler.getColSize());
	},

	getY: function(n_lin) {
		return Math.ceil((n_lin -1) * IceCap.util.Handler.getLineHeight());
	},

	toColAndLine: function(o_values) {

		var n_x = o_values.x - IceCap.util.Handler.getColSize();
		var n_y = o_values.y;

		var n_col = Math.ceil(n_x / IceCap.util.Handler.getColSize()) || 1;
		var n_lin = Math.ceil(n_y / IceCap.util.Handler.getLineHeight()) || 1;

		var o_position = Ext.apply({}, {
			col: n_col,
			lin: n_lin
		});

		return o_position;
	},

	getWidth: function (n_col) {


		n_col = n_col || 1;

		var i_self = this;
		var n_value = i_self.getColSize();
		return n_value * n_col;
	},

	getHeight: function(n_lin) {

		n_lin = n_lin || 1;

		var i_self = this;
		var i_element = i_self.getMeasureItem();

		i_element.setHtml("W");

		var n_value = i_element.getHeight();

		i_element.setHtml("");

		return n_value * n_lin;
	},

	getColSize: function() {

		var i_self = this;

		var n_value = i_self.getNormalWidth();

		if (!i_self.getChanged()) {

			var i_element = i_self.getMeasureItem();
			var i_elementBold = i_self.getBoldItem();

			if (window.devicePixelRatio > 1) {

				var i_fieldRule = i_self.getCssRule();
				var i_labelRule = i_self.getLabelCssRule();
				var i_passwordRule = i_self.getPasswordCssRule();

				var i_fieldStyle = i_fieldRule.style;
				var i_labelStyle = i_labelRule.style;
				var i_passwordStyle = i_passwordRule.style;

				i_element.setStyle("font-size", "14px");
				i_element.setStyle("min-height", "22px");
				i_elementBold.setStyle("min-height", "22px");

				i_element.setStyle("line-height", "30px");
				i_elementBold.setStyle("line-height", "30px");

				var n_width = window.screen.width;
				var n_height = window.screen.height;
				i_element.setHtml("W");

				var n_elementHeight = i_element.getHeight();
				var n_elementWidth = i_element.getWidth();

				var n_minheight = 22;
				var n_minWidth = n_elementWidth;
				var n_lineHeight = n_elementHeight;
				var n_fontSize = 14;
				var n_scale = 1;

				i_element.setHtml("");

				if ((80 * n_minWidth) > n_width) {

					n_scale = Math.min(n_width / (80 * n_minWidth), (80 * n_minWidth) / n_width);

					n_fontSize = Math.ceil(n_fontSize - (n_fontSize * n_scale)) ;

					i_fieldStyle.fontSize = i_labelStyle.fontSize = i_passwordStyle.fontSize = n_fontSize + "px";

					i_element.setStyle("font-size", n_fontSize + "px");
					i_elementBold.setStyle("font-size", n_fontSize + "px");
				}
				else {

					if ((24 * n_elementHeight) > n_height - 130) {
						n_scale = Math.min((n_height - 130) / (24 * n_elementHeight), (24 * n_elementHeight) / (n_height - 130));
					}
				}

				if (n_scale < 1) {

					var n_minScale = n_scale;
					var n_lineScale = n_scale;

					if ((24 * n_elementHeight) > n_height - 130) {

						n_lineScale = Math.min((n_height - 130) / (24 * n_elementHeight), (24 * n_elementHeight) / (n_height - 130));
						n_minScale = Math.min((n_height - 130) / (24 * n_elementHeight), (24 * n_elementHeight) / (n_height - 130));
					}

					n_minheight = Math.ceil(Math.max(n_minheight - (n_minheight * n_minScale), n_minheight * n_minScale));
					n_lineHeight = Math.ceil(Math.max(n_lineHeight - (n_lineHeight * n_lineScale), n_lineHeight * n_lineScale));

					i_fieldStyle.minHeight = i_labelStyle.minHeight = i_passwordStyle.minHeight = n_minheight + "px";
					i_fieldStyle.lineHeight = i_labelStyle.lineHeight = i_passwordStyle.lineHeight = n_lineHeight + "px";

					i_element.setStyle("min-height", n_minheight + "px");
					i_elementBold.setStyle("min-height", n_minheight + "px");

					i_element.setStyle("line-height", n_lineHeight + "px");
					i_elementBold.setStyle("line-height", n_lineHeight + "px");
				}
			}

			n_value = i_element.getTextWidth("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW" +
			"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW") / 100;

			i_self.setNormalWidth(n_value);

			n_value = i_elementBold.getTextWidth("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW" +
			"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW") / 100;

			i_self.setBoldWidth(n_value);

			n_value = i_self.getNormalWidth();

			i_self.setChanged(true);
		}

		return n_value;
	},

	getBoldColSize: function() {

		var i_self = this;
		var n_value = Math.ceil(i_self.getBoldWidth());
		return n_value;
	},

	getLineHeight: function() {

		var i_self = this;
		var i_element = i_self.getMeasureItem();

		i_element.setHtml("W");

		var n_value = i_element.getHeight();

		i_element.setHtml("");

		return n_value;
	},

	getMargin: function() {
		return IceCap.util.Handler.getMarginValue() * IceCap.util.Handler.getScale();
	},

	getTextSize: function() {
		var o_scale = IceCap.util.Handler.getScalingObject();
		return o_scale.textSize * IceCap.util.Handler.getScale();
	},

	getDefaultWidth: function () {

		var i_self = this;
		var i_element = i_self.getMeasureItem();
		var n_value = i_element.getTextWidth("W");

		return n_value;
	},

	getDefaultHeight: function() {

		var i_self = this;
		var i_element = i_self.getMeasureItem();

		i_element.setHtml("W");

		var n_value = i_element.getHeight();

		i_element.setHtml("");
		return n_value;
	},

	getData: function(o_config, o_data, f_callback) {

		f_callback = f_callback || Ext.emptyFn;
		o_data = o_data || {};

		Ext.Ajax.request({
			url: IceCap.util.Handler.getPath(o_config),
			method: "POST",
			params: o_data,
			success: function(i_response, i_request) {

				var o_data = Ext.apply({}, {
					input: [],
					output: []
				});
				if (!Ext.String.startsWith(!i_response.responseText.toLowerCase(), "<html")) {

					Ext.USE_NATIVE_JSON = false; // DO THIS TO ALLOW THE PARSE OF FUNCTIONS

					o_data = Ext.decode(i_response.responseText, true) || Ext.apply({}, {
						input: [],
						output: []
					});

					//Ext.USE_NATIVE_JSON = true;
				}
				f_callback(o_data);
			},
			failure: function() {
				f_callback({
					input: [],
					output: []
				});
			}
		});
	},

	getNewSession: function(f_callback) {

		f_callback = f_callback || Ext.emptyFn;

		var s_activeTerminals = IceCap.util.Handler.getActiveTerminals();

		Ext.Ajax.request({
			url: IceCap.util.Handler.getServiceUrl() + "?activeTerminals=" + s_activeTerminals,
			method: "POST",
			success: function(i_response, i_request) {

				var o_data = Ext.decode(i_response.responseText, true) || Ext.apply({}, {
					success: false,
					session: ""
				});

				IceCap.util.Handler.addSession(o_data.session);

				f_callback(o_data);
			},
			failure: function(o_err) {

				var o_data = Ext.apply({}, {
					success: false,
					session: ""
				});
				f_callback(o_data);
			}
		});
	},

	useScale: function(n_scale) {

		var o_scale = IceCap.util.Scale.getFixed()[n_scale];

		if (o_scale) {
			IceCap.util.Handler.setScaling(o_scale);
		}
	},

	addSession: function(s_session) {

		var i_provider = IceCap.util.Handler.getProvider();

		var a_terminals = Ext.Array.from(i_provider.get("activeterminals"));

		var s_terminal = s_session.substring(s_session.length - 2);
		var n_terminal = parseFloat(s_terminal);

		if (isNaN(n_terminal)) {
			n_terminal = 0;
		}

		if (n_terminal && Ext.Array.indexOf(a_terminals, n_terminal) === -1) {
			a_terminals.push(n_terminal);
		}

		i_provider.set("activeterminals", a_terminals);

		var a_sessions = IceCap.util.Handler.getSessions() || [];

		 Ext.Array.push(a_sessions, s_session);

		IceCap.util.Handler.setSessions(a_sessions);
	},

	getActiveTerminals: function() {

		var i_provider = IceCap.util.Handler.getProvider();

		var a_terminals = Ext.Array.from(i_provider.get("activeterminals"));

		if (a_terminals.length === 0) {
			a_terminals.push(0);
		}

		return a_terminals.join(",");
	},

	removeSession: function(s_session) {

		var i_provider = IceCap.util.Handler.getProvider();

		var a_terminals = Ext.Array.from(i_provider.get("activeterminals"));

		var s_terminal = s_session.substring(s_session.length - 2);
		var n_terminal = parseFloat(s_terminal);

		if (isNaN(n_terminal)) {
			n_terminal = 0;
		}

		if (n_terminal) {
			Ext.Array.remove(a_terminals, n_terminal);
		}

		i_provider.set("activeterminals", a_terminals);

		var a_sessions = IceCap.util.Handler.getSessions() || [];

		Ext.Array.remove(a_sessions, s_session);

		IceCap.util.Handler.setSessions(a_sessions);
	},

	isSessionAlive: function(s_session, f_callback) {

		f_callback = f_callback || Ext.emptyFn;

		IceCap.util.Handler.addSession(s_session);

		Ext.Ajax.request({
			url: IceCap.util.Handler.getServiceUrl() + "?activeTerminals=" + IceCap.util.Handler.getActiveTerminals(),
			method: "POST",
			params: {
				isSessionAlive: s_session
			},
			success: function(i_response, i_request) {

				var o_result = Ext.decode(i_response.responseText, true) || Ext.apply({}, {
					success: false,
					message: ""
				});

				f_callback(o_result.success);
			},
			failure: function(o_err) {

				IceCap.util.Handler.removeSession(s_session);

				var o_result = Ext.apply({}, {
					success: false,
					session: ""
				});

				f_callback(o_result.success);
			}
		});
	},

	getScalingObject: function() {

		var b_fixed = IceCap.util.Handler.getFixed();
		var o_return = IceCap.util.Handler.getScaling();
		var n_scale = IceCap.util.Handler.getScaleSize();
		if (!b_fixed) {
			var o_free = IceCap.util.Scale.getFree()[n_scale];
			if (o_free) {
				o_return = o_free;
			}
		}

		return o_return;
	},

	createWindow: function(o_config) {

		var o_icecap = {
			func: o_config.func,
			initFunc: o_config.initFunc,
			responseCallBack: o_config.responseCallBack,
			requestCallBack: o_config.requestCallBack,
			theme: o_config.theme
		};

		var i_icecap = Ext.create("IceCap.view.Main", o_icecap);

		var i_window = Ext.widget("window", Ext.apply(o_config, {
			onEsc: Ext.emptyFn,
			items: [
				i_icecap
			]
		}));

		i_icecap.on({
			destroy: {
				fn: function () {
					if (!i_window.isDestroyed && !i_window.destroying) {
						i_window.close();
					}
				}
			}
		});

		return i_window;
	},

	createIndicators: function(s_hex16) {

		var i_self = this;

		// EXAMPLE
		// WE READ FROM LEFT TO RIGHT BITWISE
		// 0100 0011 0000 0110

		// 1 IN 16 BITS
		// RESULT 0000 0000 0000 0001

		// (1 << 15) SHIFT LEFT 15 BIT
		// RESULT 1000 0000 0000 0000

		var n_hex32 = 0;

		var n_hex16 = parseInt(s_hex16);

		if (!(n_hex16 & (1 << 15)) && (n_hex16 & (1 << 14))) {
			n_hex32 |= IceCap.util.Handler.FFW.IDENT_FLAG;
		}

		if (n_hex16 & (1 << 13) || (n_hex16 & (1 << 10 | 1 << 9 | 1 << 8) == (1 << 10 | 1 << 9))) {
			n_hex32 |= IceCap.util.Handler.FFW.BYPASS;
		}
		if (n_hex16 & (1 << 12)) {
			n_hex32 |= IceCap.util.Handler.FFW.DUP_OR_MARK;
		}
		if (n_hex16 & (1 << 11)) {
			n_hex32 |= IceCap.util.Handler.FFW.MOD_DATA;
		}

		n_hex32 |= i_self.ffw_spec(n_hex16);

		if (n_hex16 & (1 << 7)) {
			n_hex32 |= IceCap.util.Handler.FFW.AUTO_ENTER;
		}
		if (n_hex16 & (1 << 6)) {
			n_hex32 |= IceCap.util.Handler.FFW.EXIT_REQ;
		}
		if (n_hex16 & (1 << 5)) {
			n_hex32 |= IceCap.util.Handler.FFW.MONOCASE;
		}
		if (n_hex16 & (1 << 3)) {
			// n_hex32 |= IceCap.util.Handler.FFW.MAND_ENTER;
		}

		n_hex32 |= i_self.ffw_ra(n_hex16);

		return n_hex32;
	},

	ffw_spec: function(n_flag) {

		if (n_flag & (1 << 10) && n_flag & (1 << 9) && n_flag & (1 << 8)) {
			return IceCap.util.Handler.FFW.SIGNED_NUMERIC;
		}
		if (n_flag & (1 << 10) && n_flag & (1 << 9) && !(n_flag & (1 << 8))) {
			return IceCap.util.Handler.FFW.IO_FEATURE;
		}
		if (n_flag & (1 << 10) && !(n_flag & (1 << 9)) && n_flag & (1 << 8)) {
			return IceCap.util.Handler.FFW.DIGITS_ONLY;
		}
		if (n_flag & (1 << 10) && !(n_flag & (1 << 9)) && !(n_flag & (1 << 8))) {
			return IceCap.util.Handler.FFW.KATAKANA_SHIFT;
		}
		if (!(n_flag & (1 << 10)) && n_flag & (1 << 9) && n_flag & (1 << 8)) {
			return IceCap.util.Handler.FFW.NUMERIC_ONLY;
		}
		if (!(n_flag & (1 << 10)) && n_flag & (1 << 9) && !(n_flag & (1 << 8))) {
			return IceCap.util.Handler.FFW.NUMERIC_SHIFT;
		}
		if (!(n_flag & (1 << 10)) && !(n_flag & (1 << 9)) && n_flag & (1 << 8)) {
			return IceCap.util.Handler.FFW.ALPHA_ONLY;
		}

		return IceCap.util.Handler.FFW.APLHA_SHIFT;
	},

	ffw_ra: function(n_flag) {

		if (!(n_flag & (1 << 2)) && !(n_flag & (1 << 1)) && !(n_flag & (1 << 0))) {
			return IceCap.util.Handler.FFW.RA_NONE;
		}
		if ((n_flag & (1 << 2)) && !(n_flag & (1 << 1)) && (n_flag & (1 << 0))) {
			return IceCap.util.Handler.FFW.RA_ZEROFILL;
		}
		if ((n_flag & (1 << 2)) && (n_flag & (1 << 2)) && !(n_flag & (1 << 0))) {
			return IceCap.util.Handler.FFW.RA_BLANKFILL;
		}
		if ((n_flag & (1 << 2)) && (n_flag & (1 << 2)) && (n_flag & (1 << 0))) {
			return IceCap.util.Handler.FFW.RA_MANDATORY;
		}

		return IceCap.util.Handler.FFW.RA_RESERVED;
	},

	messageBox: function (o_config) {

		var i_self = this;

		o_config = o_config || {};

		Ext.applyIf(o_config, {
			message: "",
			icon: Ext.Msg.INFO,
			cancelFn: Ext.emptyFn,
			yesFn: Ext.emptyFn,
			noFn: Ext.emptyFn,
			yesText: "",
			noText: "",
			cancelText: "",
			title: "",
			closable: true
		});

		var s_msg = o_config.message || o_config.msg;
		var s_icon = o_config.icon;

		var s_yes = o_config.yesText;
		var f_yes = o_config.yesFn;

		var s_cancel = o_config.cancelText;
		var f_cancel = o_config.cancelFn;

		var f_close = o_config.cancelFn;

		var s_no = o_config.noText;
		var f_no = o_config.noFn;

		var s_title = o_config.title;

		var b_closable = o_config.closable;

		var b_first = true;

		var o_text = {};
		var s_default = "";

		if (s_yes) {
			o_text.yes = s_yes;
			s_default = "button-yes";
		}

		if (s_no) {
			o_text.no = s_no;
			if (!s_default) {
				s_default = "button-no";
			}
		}

		if (s_cancel) {
			o_text.cancel = s_cancel;
			if (!s_default) {
				s_default = "button-no";
			}
		}


		var i_msgBox = Ext.widget("window", {
			title: s_title,
			modal: true,
			draggable: false,
			ui: "icecap-message",
			layout: "fit",
			listeners: {
				destroy: {
					fn: function () {
						f_close();
					}
				}
			}
		});



		var a_items = [];

		if (o_text.cancel) {

			a_items.push({
				tabIndex: 2,
				xtype: "button",
				itemId: "button-cancel",
				text: o_text.cancel,
				minWidth: 80,
				handler: function (i_button) {
					f_cancel();
					i_msgBox.close();
				}
			});

			b_first = false;
		}

		if (o_text.no) {

			a_items.push({
				tabIndex: 1,
				xtype: "button",
				itemId: "button-no",
				text: o_text.no,
				minWidth: 80,
				handler: function (i_button) {

					f_no();
					i_msgBox.close();
				}
			});
		}

		if (a_items.length > 0) {

			a_items.unshift({
				xtype: "tbspacer",
				width: 8
			});

			a_items.push({
				xtype: "tbfill"
			});
		}



		if (o_text.yes) {

			a_items.push({
				tabIndex: 0,
				xtype: "button",
				text: o_text.yes,
				itemId: "button-yes",
				ui: "primary-button",
				minWidth: 80,
				handler: function (i_button) {

					f_yes();
					i_msgBox.close();
				}
			});
		}

		if (a_items.length > 1) {

			a_items.push({
				xtype: "tbspacer",
				width: 8
			});
		}

		var i_component = Ext.widget("component", {
			hidden: true,
			cls: Ext.baseCSSPrefix + "message-box-icon"
		});

		i_msgBox.add({
			xtype: "panel",
			minWidth: 300,
			layout: {
				type: "hbox",
				align: "stretch"
			},
			items: [
				i_component,
				{
					xtype: "container",
					flex: 1,
					html: s_msg
				}
			]
		});

		var s_cls = i_msgBox.messageIconCls;

		if (s_cls) {
			i_component.removeCls(s_cls);
		}

		if (s_icon) {
			//i_component.show();
			i_component.addCls(Ext.baseCSSPrefix + 'dlg-icon');
			i_component.addCls(i_msgBox.messageIconCls = s_icon);
		}
		else {
			i_component.removeCls(Ext.baseCSSPrefix + 'dlg-icon');
			//i_component.hide();
		}

		if (a_items.length > 0) {

			var i_toolbar = Ext.widget("toolbar", {
				ui: "footer",
				dock: "bottom",
				items: a_items,
				layout: a_items.length > 1 ? "hbox" : "center",
				listeners: {
					afterrender: {
						fn: function (i_toolbar) {

							if (s_default) {
								var i_button = i_toolbar.getComponent(s_default);

								if (i_button) {
									i_button.focus(false, 10);
								}
							}
						},
						buffer: 100
					}
				}
			});

			i_msgBox.addDocked(i_toolbar);
		}

		var a_bindings = i_self.getFKeys();

		i_msgBox.show();

		var i_keyMap = Ext.create("Ext.util.KeyMap", {
			target: i_msgBox.getEl(),
			binding: a_bindings
		});

		i_msgBox.mon(i_msgBox, "beforedestroy" , function(i_window) {
			i_keyMap.destroy();
		});

		return i_msgBox;
	},

	getInputFields: function(i_component) {

		var a_fields = i_component.queryBy(function (i_search) {
			var b_return = false;

			if (i_search.isXType("field") && !i_search.isXType("displayfield")) {
				b_return = i_search.inputEl && i_search.inputEl.isInputField();
			}

			return b_return;
		})

		return a_fields;
	},

	getFontSize: function() {

		var i_self = this;

		var i_cssRule = i_self.getCssRule();
		var s_font = i_cssRule.style.fontSize || "14px";
		var s_number = s_font.replace("px");
		var n_value = parseFloat(s_number);

		return n_value;
	},

	getCssRule: function() {

		var i_self = this;

		var i_cssRule = Ext.util.CSS.getRule(".x-form-text-icecap-field", true) || {
			style: {
				fontFamily: "Lucida Console, Andale Mono, monospace",
				fontSize: "14px",
				fontWeight: "400",
				minHeight: "22px"
			}
		};

		return i_cssRule;
	},

	getLabelCssRule: function () {

		var i_self = this;

		var i_cssRule = Ext.util.CSS.getRule(".x-form-display-field-icecap-display", true) || {
			style: {
				fontFamily: "Lucida Console, Andale Mono, monospace",
				fontSize: "14px",
				fontWeight: "400",
				minHeight: "22px"
			}
		};

		return i_cssRule;
	},

	getPasswordCssRule: function () {

		var i_self = this;

		var i_cssRule = Ext.util.CSS.getRule(".x-form-text-icecap-password-field", true) || {
			style: {
				fontFamily: "Lucida Console, Andale Mono, monospace",
				fontSize: "14px",
				fontWeight: "400",
				minHeight: "22px"
			}
		};

		return i_cssRule;
	},

	toWindow: function(i_item) {

		var i_self = this

		i_item.setResizeMode(2);

		setTimeout(function() {
			i_item.focus();
		}, 10);

		var i_window = Ext.widget("window", {
			layout: "fit",
			constrain: true,
			maximizable: true,
			collapsible: true,
			onEsc: Ext.emptyFn,
			listeners: {
				afterrender: {
					fn: function (i_window) {

						var i_header = i_window.header;

						if (i_header) {

							var i_tabTool = Ext.widget("tool", {
								iconCls: "pf-tab_pane",
								tooltip: "To tab",
								handler: function () {

									var i_panel = i_window.down("panel");

									if (i_panel) {

										i_panel.setTitle(i_window.title);

										IceCap.app.fireEvent("toTab", i_panel);

										i_window.close();
									}
								}
							});

							i_header.add(1, i_tabTool);
							i_item.show();

						}
					}
				}
			},
			items: [
				i_item
			]
		});

		i_window.setTitle(i_item.title);

		i_item.setTitle("");

		i_window.show();
	},

	createElements: function() {

		var i_self = this;
		var i_cssRule = i_self.getCssRule();

		var o_style = i_cssRule.style;
		var s_minHeight = o_style.minHeight || "0px";
		var n_minheight = parseFloat(s_minHeight.replace("px"));
		var s_lineHeight = (n_minheight + 8) + "px";

		var i_element = Ext.getBody().createChild({
			tag: "span",
			role: "presentation",
			cls: Ext.baseCSSPrefix + "textmetrics",
			style: {
				position: "absolute",
				left: "-10000px",
				top: "-10000px",
				"font-family": o_style.fontFamily,
				"line-height": s_lineHeight,
				"font-size": o_style.fontSize,
				"white-space": "pre",
				"font-weight": o_style.fontWeight
			}
		});

		var s_fontSize = o_style.fontSize || "14px";
		var n_fontSize = parseFloat(s_fontSize.replace("px"));

		var i_boldElement = Ext.getBody().createChild({
			tag: "span",
			role: "presentation",
			cls: Ext.baseCSSPrefix + "textmetrics",
			style: {
				position: "absolute",
				left: "-10000px",
				top: "-10000px",
				"font-family": o_style.fontFamily,
				"line-height": s_lineHeight,
				"font-size": n_fontSize - 1 + "px",
				"white-space": "pre",
				"font-weight": "bold"
			}
		});

		i_self.setMeasureItem(i_element);
		i_self.setBoldItem(i_boldElement);

		var n_normal = i_element.getTextWidth("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW" +
			"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW") / 100;

		var n_bold = i_boldElement.getTextWidth("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW" +
			"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW") / 100;

		i_self.setNormalWidth(n_normal);
		i_self.setBoldWidth(n_bold);
	},

	getFKeys: function () {

		var i_self = this;

		var a_keys = [
			{
				key: Ext.event.Event.F1,
				shift: false,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F2,
				shift: false,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F3,
				shift: false,
				alt: false,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F4,
				shift: false,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F5,
				shift: false,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F6,
				shift: false,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F7,
				shift: false,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F8,
				shift: false,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F9,
				shift: false,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F10,
				shift: false,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F11,
				shift: false,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F12,
				shift: false,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			}
		];

		a_keys = a_keys.concat(i_self.getFShiftKeys());

		return a_keys;
	},

	getFShiftKeys: function () {

		var i_self = this;

		var a_keys = [
			{
				key: Ext.event.Event.F1,
				shift: true,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F2,
				shift: true,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F3,
				shift: true,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F4,
				shift: true,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F5,
				shift: true,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F6,
				shift: true,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F7,
				shift: true,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F8,
				shift: true,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F9,
				shift: true,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F10,
				shift: true,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F11,
				shift: true,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			},
			{
				key: Ext.event.Event.F12,
				shift: true,
				fn: function (n_key, i_event) {
					i_event.stopEvent();
				}
			}
		];

		return a_keys;
	},
	getRandomName: function() {

		var s_random = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);

		var s_name = Ext.id(null, s_random + "-");
		return s_name;

	}

}, function() {
	var i_cssRule = Ext.util.CSS.getRule(".x-form-text-icecap-field", true);

	if (!i_cssRule) {

		Ext.Loader.loadScriptsSync([
			"/icecap/app/theme/icecap-theme/icecap-theme-debug.js",
			"/icecap/app/theme/icecap-theme/resources/icecap-theme-all-debug.css"
		]);
	}
	IceCap.util.Handler.createElements();
});

Ext.define("IceCap.util.Scale", {

	singleton: true,

	config: {
		fixed: null,
		free: null
	},

	constructor: function(o_config) {

		var i_self = this;
		i_self.initConfig(o_config);

		i_self.setFixed({
			"16": {
				"textSize": 16,
				"colSize": 9.7,
				"defaultWidth": 18,
				"defaultHeight": 24,
				"lineHeight": 28
			},
			"15": {
				"textSize": 15,
				"colSize": 9.1,
				"defaultWidth": 17,
				"defaultHeight": 22,
				"lineHeight": 26
			},
			"14": {
				"textSize": 14,
				"colSize": 8.45,
				"defaultWidth": 17,
				"defaultHeight": 20,
				"lineHeight": 24
			},
			"13": {
				"textSize": 13,
				"colSize": 7.9,
				"defaultWidth": 15,
				"defaultHeight": 19,
				"lineHeight": 22
			},
			"12": {
				"textSize": 12,
				"colSize": 7.4,
				"defaultWidth": 14,
				"defaultHeight": 17,
				"lineHeight": 20
			},
			"11": {
				"textSize": 11,
				"colSize": 6.8,
				"defaultWidth": 13,
				"defaultHeight": 15,
				"lineHeight": 18
			}
		});

		i_self.setFree({
			"14": {
				"textSize": 13,
				"colSize": 12.2,
				"defaultWidth": 20,
				"defaultHeight": 20,
				"lineHeight": 24
			}
		});
	}
});
Ext.define("IceCap.util.Breakout", {

	alternateClassName: [
		"IceCap.breakout"
	],

	singleton: true,

	constructor: function(o_config) {

		var i_self = this;
		i_self.initConfig(o_config);
	},

	googleMap: function(o_data) {

		var i_self = this;

		o_data = o_data || {};

		if (s_title.toLowerCase() == "work with customers") {

			var s_url = "http://www.icebreak.org/geoCoding.html";

			var o_params = {
				address: "dk" + o_data.c5 + "," + o_data.c4
			};

			s_url = s_url + "?" + Ext.Object.toQueryString(o_params);

			Ext.GlobalEvents.fireEvent(i_self, "onAddWebContainer", {
				url: s_url
			});
		}
	},

	krak: function(o_data) {

		var i_self = this;

		o_data = o_data || {};

		if (s_title.toLowerCase() == 'work with customers') {

			var s_url = 'http://www.krak.dk/'
					+ o_data.c3.replace(' ', '+')
					+ '/'
					+ o_data.c4.replace(' ', '+')
					+ '+'
					+ o_data.c5
					+ '/søg.cs';

			Ext.GlobalEvents.fireEvent(i_self, "onAddWebContainer", {
				url: s_url
			});
		}
	}
});
Ext.define("IceCap.component.Marker", {

	xtype: "icecap-marker",

	alias: [
		"widget-icecap-marker"
	],

	extend: "Ext.Component",

	hidden: true,

	width: "90%",

	height: "90%",

	config: {
		inUse:  false,
		xValue: 0,
		yValue: 0
	},

	listeners: {
		afterrender: {
			fn: function(i_marker) {

				i_marker.update();
			}
		},
		show: {
			fn: function(i_marker) {

				i_marker.update();
			}
		}
	},

	renderTpl: [
		"<div id=\"{id}-outer\" data-ref=\"outerEl\" ",
			"style=\"",
			"width:100%;",
			"height:100%;",
			"background-color:transparent;",
		"\">",
			"<div id=\"{id}-body\" data-ref=\"bodyEl\" ",
				"style=\"",
				"width:100%;",
				"height:100%;",
				"background-color:transparent;",
			"\">",
				"<div id=\"{id}-frameBody\" data-ref=\"frameBody\">",
						"<div id=\"{id}-markerVertical\" class=\"icecap-marker-vertical-{ui}\" data-ref=\"markerVertical\" ",
							"style=\"",
							"width: 0px;",
							"height: 100%;",
							"top: 0px;",
							"left: 0px;",
							"clear: Both;",
						"\"></div>",
						"<div id=\"{id}-markerHorizontal\" class=\"icecap-marker-horizontal-{ui}\" data-ref=\"markerHorizontal\" ",
							"style=\"",
							"height: 0px;",
							"width: 100%;",
							"top: 0px;",
							"left: 0px;",
						"\"></div>",
				"</div>",
			"</div>",
		"</div>"
	],

	childEls: [
		{
			name: "outerEl",
			itemId: "outer"
		},
		{
			name: "frameBody",
			itemId: "frameBody"
		},
		{
			name: "markerVerticalEl",
			itemId: "markerVertical"
		},
		{
			name: "markerHorizontalEl",
			itemId: "markerHorizontal"
		},

	],

	constructor: function(o_config) {

		var i_self = this;

		i_self.callParent(arguments);
	},

	updateInUse: function(value) {

		var i_self = this;

		i_self[value ? "show" : "hide"]();

		i_self.fireEvent(value ? "show" : "hide", i_self);
	},

	updateXValue: function(value) {

		var i_self = this;

		if (i_self.rendered) {

			var i_markerVertical = i_self.markerVerticalEl;
			i_markerVertical.setLeft(value);
		}
	},

	updateYValue: function(value) {

		var i_self = this;

		if (i_self.rendered) {

			var i_markerHorizontal = i_self.markerHorizontalEl;
			i_markerHorizontal.setTop(value);
		}
	},

	update: function() {

		var i_self = this;

		var n_x = i_self.getXValue();
		var n_y = i_self.getYValue();

		i_self.updateXValue(n_x);
		i_self.updateYValue(n_y);
	},

	move: function(a_position) {

		var i_self = this;

		i_self.setXValue(a_position[0]);
		i_self.setYValue(a_position[1]);
	},

	toggle: function() {

		var i_self = this;

		var b_InUse = i_self.getInUse();

		i_self.setInUse(!b_InUse);
	}
});
Ext.define("IceCap.component.Cursor", {

	xtype: "icecap-cursor",

	alias: [
		"widget-icecap-cursor"
	],

	extend: "Ext.Component",

	hidden: true,

	width: 9,

    height: 0,

    baseCls: Ext.baseCSSPrefix + "icecap-cursor",

	config: {
		inUse:  false,
		xValue: 0,
        yValue: 0,
        theme: "default"
	},

	listeners: {
        beforerender: {
            fn: function (i_cursor) {

                var i_self = this;

                var o_data = i_self.renderData || i_self.data || {};



                Ext.applyIf(o_data, {
                    width: i_self.width
                });

                i_self.renderData = i_self.data = o_data;
            }
        },
		afterrender: {
			fn: function(i_cursor) {

				i_cursor.update();
			}
		},
		show: {
			fn: function(i_cursor) {

				i_cursor.update();
			}
		}
	},

	renderTpl: [
        "<span id=\"{id}-cursor\" role=presentation data-ref=\"cursorEl\"",
        "style=\"",
            "width:{width}px;",
			"position: absolute !important;",
        "\">",
        "</span>"
	],

	childEls: [
		{
            name: "cursorEl",
            itemId: "cursor"
		},
    ],

	constructor: function(o_config) {

		var i_self = this;

        i_self.callParent(arguments);
    },

    initComponent: function() {

        var i_self = this;
        i_self.cls = ["iceCap-cursor", i_self.getTheme()].filter(Boolean).join("-");
    },

	updateInUse: function(value) {

		var i_self = this;

		i_self[value ? "show" : "hide"]();
	},

	updateXValue: function(value) {

		var i_self = this;

		if (i_self.rendered) {
            i_self.setLocalX(value);
		}
	},

	updateYValue: function(value) {

		var i_self = this;

		if (i_self.rendered) {

            i_self.setLocalY(value);
		}
	},

	update: function() {

		var i_self = this;

		var n_x = i_self.getXValue();
		var n_y = i_self.getYValue();

		i_self.updateXValue(n_x);
		i_self.updateYValue(n_y);
	},

	move: function(a_position) {

		var i_self = this;

		i_self.setXValue(a_position[0]);
		i_self.setYValue(a_position[1]);
	},

	toggle: function() {

		var i_self = this;

		var b_InUse = i_self.getInUse();

		i_self.setInUse(!b_InUse);
	}
});
Ext.define("IceCap.component.Input", {

    xtype: "icecap-input",

    alias: [
        "widget-icecap-input"
    ],

    mixins: {
        field: "Ext.form.field.Field"
    },

    extend: "Ext.Component",

    baseCls: "x-field",

    height: 24,

    width: 100,

    maxLength: 0,

    renderTpl: [
        "<input id=\"{id}-input\"",
            "role=\"textbox\"",
            "type=\"text\"",
            "data-ref=\"inputEl\" ",
            "isInputField=true ",
            "<tpl if=\"maxLength\">",
                "maxlength={maxLength} ",
            "</tpl>",
            "<tpl if=\"value\"> value=\"{[Ext.util.Format.htmlEncode(values.value)]}\"</tpl>",
            "class=\"x-form-text-icecap-field x-form-trigger-wrap-icecap-field icecap-inputEl\" ",
            "style=\"height:100%;",
                    "display:block;",
                    "width:100%;",
                    "overflow:hidden;",
        "\"></input>"
    ],

    childEls: [
        {
            name: "inputEl",
            itemId: "input"
        },
    ],

    listeners: {
        afterrender: {
            fn: function() {

                var i_self = this;
                var i_inputEl = i_self.inputEl;

                i_inputEl.on({
                    focus: {
                        fn: function() {
                            i_inputEl.addCls("x-form-trigger-wrap-focus");
                        }
                    },
                    blur: {
                        fn: function () {
                            i_inputEl.removeCls("x-form-trigger-wrap-focus");
                        }
                    },
                    input: {
                        fn: function() {

                            var value = i_inputEl.getValue();
                            i_self.fireEvent("change", i_self, value);
                        }
                    },
                    keyup: {
                        fn: function(i_event) {
                            i_self.fireEvent("keyup", i_self, i_event);
                        }
                    },
                    keydown: {
                        fn: function (i_event) {
                            i_self.fireEvent("keydown", i_self, i_event);
                        }
                    }
                });

            }
        },
        beforerender: {
            fn: function () {

                var i_self = this;

                var o_data = i_self.renderData || i_self.data || {};

                Ext.applyIf(o_data, {
                    width: i_self.width || 100,
                    height: i_self.height || 30,
                    maxLength: i_self.maxLength || 0,
                    value: i_self.value
                });

                i_self.renderData = i_self.data = o_data;
            }
        }
    },

    constructor: function () {

        var i_self = this;

        i_self.callParent(arguments);
    },

    initComponent: function () {

        var i_self = this;

        i_self.initField();
        i_self.xtypesMap.field = true;
    },

    getValue: function() {

        var i_self = this;

        var value = i_self.mixins.field.getValue.call(i_self);

        if (i_self.inputEl) {
            value = i_self.inputEl.getValue();
        }

        return value;
    },

    setValue: function (value) {

        var i_self = this;

        i_self.mixins.field.setValue.call(i_self, value);

        if (i_self.inputEl) {
            i_self.inputEl.dom.value = value;
        }

        return value;
    },

    getFocusEl: function() {

        var i_self = this;
        var i_element;

        if (i_self.inputEl) {
            i_element = i_self.inputEl;
        }

        return i_element;
    }

});
Ext.define("IceCap.component.Selector", {

    xtype: "icecap-selector",

    alias: [
        "widget-icecap-selector"
    ],

    extend: "Ext.Component",

    hidden: true,

    baseCls: Ext.baseCSSPrefix + "icecap-selector",

    listeners: {
        beforerender: {
            fn: function (i_selector) {

                var i_self = this;

                var o_data = i_self.renderData || i_self.data || {};

                Ext.applyIf(o_data, {
                    width: i_self.width || 0,
                    height: i_self.height || 0,
                });

                i_self.renderData = i_self.data = o_data;
            }
        },
        afterrender: {
            fn: function (i_selector) {

                i_selector.el.dom.setAttribute("draggable", false);
                i_selector.update();
            }
        },
        show: {
            fn: function (i_selector) {

                i_selector.update();
            }
        }
    },

    renderTpl: [
        "<span id=\"{id}-selector\" draggable=false role=presentation data-ref=\"selectorEl\"",
        "style=\"",
            "border:1px dotted black;",
            "position: absolute;",
            "width: 100%;",
            "height: 100%;",
        "\">",
        "</span>"
    ],

    childEls: [
        {
            name: "selectorEl",
            itemId: "selector"
        },
    ],

    config: {
        top: 0,
        left: 0,
        selecting: false,
        theme: ""
    },

    constructor: function (o_config) {

        var i_self = this;

        i_self.callParent(arguments);
    },

    initComponent: function () {

        var i_self = this;
        i_self.cls = ["iceCap-selector", i_self.getTheme()].filter(Boolean).join("-");

        i_self.callParent(arguments);

        i_self.mon(Ext.getDoc(), "mousedown", function(i_event) {

            i_self.setWidth(0);
            i_self.setHeight(0);
            i_self.setTop(i_event.getY());
            i_self.setLeft(i_event.getX());
            i_self.update();

            i_self.setSelecting(true);
        });

        i_self.mon(Ext.getDoc(), "mousemove", function (i_event) {

            if (i_self.getSelecting()) {

                var n_left = i_event.getX();
                var n_top = i_event.getY();

                i_self.calculateArea(n_left, n_top);
                i_self.update();
            }
        });

        i_self.mon(Ext.getDoc(), "mouseup", function (i_event) {

            i_self.setWidth(0);
            i_self.setHeight(0);
            i_self.setSelecting(false);
            i_self.update();

        });
    },

    update: function() {

        var i_self = this;

        if (i_self.rendered) {

            i_self.setX(i_self.getLeft());
            i_self.setY(i_self.getTop());
        }
    },

    updateSelecting: function(b_selecting) {

        var i_self = this;

        if (i_self.rendered) {
            i_self[b_selecting ? "show": "hide"]();
        }
    },

    calculateArea: function(n_x, n_y) {

        var i_self = this;
        var n_left = i_self.getLeft();
        var n_top = i_self.getTop();

        var n_xMin = Math.min(n_left, n_x);
        var n_xMax = Math.max(n_left, n_x);

        var n_yMin = Math.min(n_top, n_y);
        var n_yMax = Math.max(n_top, n_y);

        var n_width = n_xMax - n_xMin;
        var n_height = n_yMax - n_yMin;

        i_self.setWidth(n_width);
        i_self.setHeight(n_height);
    }
});
Ext.define("IceCap.ux.form.panel.Panel4Area", {

	extend: "Ext.panel.Panel",

	alias: [
		"widget.iceCapPanel4Area"
	],

	layout: "form",

	border: false,

	bodyPadding: 5,

	defaultType: "textfield",

	focusable: false,

	listeners: {
		activate: {
			fn: function(i_panel) {

				var a_fields = i_panel.query("field[focusable]");

				if (a_fields.length > 0) {
					var i_field = a_fields[0];
					i_field.focus(true, 10);
				}
			}
		}
	},

	initComponent: function () {

		var i_self = this;

		var a_items = Ext.Array.slice(i_self.items, 0);

		Ext.Array.each(a_items, function(o_field) {

			o_field.value = o_field.value || o_field.dta;
			o_field.fieldLabel = o_field.fieldLabel || o_field.label;

			o_field.readOnly = o_field.type === "output";

			var o_meta = o_field.metaData || {
				xtype: "textfield"
			};

			delete o_field.metaData;

			Ext.apply(o_field, o_meta);
		});

		i_self.items = a_items;

		i_self.callParent();

		i_self.enableBubble("onAddWebContainer");
	}
});
Ext.define("IceCap.ux.form.panel.TabPanel", {

	extend: "Ext.tab.Panel",

	alias: [
		"widget.tabPanel"
	],

	listeners: {
		afterrender: {
			fn: function(i_panel) {

				var i_self = this;

				i_self.initKeyMap();
			}
		}
	},

	config: {
		keyMap: null
	},

	initComponent: function() {

		var i_self = this;

		i_self.callParent(arguments);
	},

	initKeyMap: function() {

		var i_self = this;

		var a_bindings = [{
			key: "1234567890",
			ctrl: true,
			alt: false,
			handler: function(n_keyCode, i_event) {

				i_event.stopEvent();

				var n_tab = n_keyCode - 49;

				var a_items = i_self.items;

				if (n_tab > a_items.length) {
					n_tab = 0;
				}

				i_self.setActiveTab(n_tab);
			}
		}];

		var i_keyMap = Ext.create("Ext.util.KeyMap", {
			target: i_self.getEl(),
			binding: a_bindings
		});

		i_self.setKeyMap(i_keyMap);
	}
});
Ext.define("IceCap.ux.grid.editor.Controller", {
	extend: "Ext.app.ViewController",

	alias: "controller.icecap.ux.grid.editor.main"
});
Ext.define("IceCap.ux.grid.editor.Main", {

	extend: "Ext.grid.Panel",

	alias: [
		"widget.iceCapEditorGrid",
		"widget.iceCapGrid"
	],

	requires: [
		"IceCap.ux.grid.editor.Controller"
	],

	config: {
		gridConfig: null,
		toolbar: null,
		pagingToolbar: null,
		keys: [],
		extraToolbarButtons: [],
		rowMenu: null,
		defaultOption: "ENTER",
		needFocus: false,
		focusTo: 0,
		theme: ""
	},

	flex: 1,

	listeners: {
		afterrender: {
			fn: function(i_panel) {

				var i_self = this;
				var i_store = i_self.getStore();
				var i_view = i_self.getView();
				var a_records = i_store.getRange()

				Ext.suspendLayouts();

				i_self.getView().setHeight(a_records.length * IceCap.util.Handler.getLineHeight());

				Ext.resumeLayouts(true);

				i_self.setTabIndex(i_self.initialConfig.tabIndex || -1);

				var i_navigationModel = i_self.getNavigationModel();
				var i_keyNav = i_navigationModel.keyNav;

				if (Ext.isArray(i_keyNav)) {
					i_keyNav = i_keyNav[0];
				}
				
				var i_map = i_keyNav.map;

				var i_tabBinding = Ext.Array.findBy(i_map.bindings, function(i_binding) {
					return i_binding.key == Ext.event.Event.TAB;
				});

				i_map.removeBinding(i_tabBinding);

				var i_enterBinding = Ext.Array.findBy(i_map.bindings, function(i_binding) {
					return i_binding.key == Ext.event.Event.ENTER;
				});

				i_map.removeBinding(i_enterBinding);

				i_keyNav.defaultEventAction = "";
				i_map.ignoreInputFields = false;

				i_map.addBinding({
					ctrl: false,
					shift: false,
					alt: false,
					key: Ext.event.Event.TAB,
					handler: function(n_key, i_event) {

						var i_selectionModel = i_self.getSelectionModel();
						var i_current = i_selectionModel.getCurrentPosition();

						var i_store = i_self.getStore();

						if (i_current.rowIdx != (i_store.getTotalCount() - 1)) {
							i_event.stopEvent();
						}

						i_self.getSelectionModel().selectNext(false);
					}
				});

				i_map.addBinding({
					ctrl: false,
					shift: true,
					alt: false,
					key: Ext.event.Event.TAB,
					handler: function(n_key, i_event) {

						var i_selectionModel = i_self.getSelectionModel();
						var i_current = i_selectionModel.getCurrentPosition();

						if (i_current.rowIdx > 0) {
							i_event.stopEvent();
						}
						i_selectionModel.selectPrevious(false);
					}
				});

				i_map.addBinding({
					key: Ext.event.Event.ENTER,
					handler: function(n_key, i_event) {

						var i_selectionModel = i_self.getSelectionModel();
						var i_current = i_selectionModel.getCurrentPosition();

						i_event.stopEvent();

						if (i_current) {

							var i_record = i_current.record;

							var s_id = i_record.getId().split("g.").pop();

							var s_defaultOption = i_self.getDefaultOption();

							var o_data = {
								field: s_id,
								option: s_defaultOption,
								col: Ext.Number.from(i_record.get("col"), 0),
								lin: Ext.Number.from(i_record.get("lin"), 0)
							};

							i_self.fireEvent("fieldoption", [o_data]);
						}
					}
				});

				if (i_self.getNeedFocus()) {

					var i_view = i_self.getView();
					i_view.select(i_self.getFocusTo() - 1);
				}
			}
		},
		itemcontextmenu: {
			fn: function(i_view, i_record, i_html, n_index, i_event) {

				var i_self = this;

				i_event.stopEvent();

				var a_position = i_event.getXY();

				var i_menu = i_self.getRowMenu();

				i_menu.showAt(a_position);
			}
		},
		itemdblclick: {
			fn: function (i_view, i_record, i_item, n_index, i_event, o_options) {

				var i_self = this;

				i_event.stopEvent();

				var s_id = i_record.getId().split("g.").pop();

				var s_defaultOption = i_self.getDefaultOption();

				var o_data = {
					field: s_id,
					option: s_defaultOption,
					col: Ext.Number.from(i_record.get("col"), 0),
					lin: Ext.Number.from(i_record.get("lin"), 0)
				};

				i_self.fireEvent("fieldoption", [o_data]);
			}
		},
		select: {
			fn: function(i_selectionModel, i_record) {

				var i_self = this;
				var o_gridConfig = i_self.getGridConfig();
				var i_columnManager = i_self.getColumnManager();

				if (o_gridConfig.showOption) {

					var i_column = i_columnManager.getHeaderByDataIndex(o_gridConfig.optionDataIndex);

					if (i_column) {
						var i_textfield = i_column.getWidget(i_record);
						i_textfield.focus(10, true);
					}
				}
			}
		}
	},

	initComponent: function() {

		var i_self = this;

		var o_viewConfig = {
			focus: function () {

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

				var i_selectionModel = i_self.getSelectionModel();
				var i_current = i_selectionModel.getCurrentPosition();

				if (!i_current) {
					i_self.select(0, false);
				}
				else {
					var i_record = i_current.record;

					i_selectionModel.deselectAll(false);
					i_self.select(i_record);
				}
			},
			getRowClass: function () {
				var i_view = this;
				var i_grid = i_view.grid;
				return "iceCap-row-" + i_grid.getTheme();
			},
			cls: "iceCap-row-" + i_self.getTheme()
		};

		Ext.apply(i_self, {
			viewConfig: o_viewConfig
		});

		var i_store = i_self.createStore();
		var a_columns = i_self.createColumns();

		var o_config = i_self.getGridConfig();

		var i_selectionModel = Ext.create("Ext.selection.RowModel", {
			mode: "MULTI"
		});

		Ext.apply(i_self, {
			store: i_store,
			columns: a_columns,
			enableColumnMove: o_config.enableColumnMove || false,
			selModel: i_selectionModel
		});

		i_self.callParent(arguments);

		if (o_config.showToolbar) {
			i_self.createToolbar();
		}

		i_self.addDocked(i_self.createPagingToolbar());

		i_self.createRowMenu();
	},

	createStore: function() {

		var i_self = this;

		var o_config = i_self.getGridConfig();

		var o_store = o_config.store;
		var o_meta = o_store.metaData;

		var i_store = Ext.create("Ext.data.Store", {
			fields: o_meta.fields,
			autoload: false,
			proxy: {
				type: "memory",
				reader: {
					type: "json"
				}
			},
			data: o_store.rows
		});

		return i_store;
	},

	createColumns: function() {

		var i_self = this;

		var o_config = i_self.getGridConfig();

		var a_return = [];

		var a_columns = o_config.header || [];

		var a_quick = o_config.quickOption || [];

		Ext.Array.each(a_columns, function(o_config, n_index) {

			var o_column = Ext.clone(o_config);

			if (Ext.isFunction(o_column.renderer) &&
					o_column.renderer == (window.renderOptionField ||
					o_column.renderer == window.renderField)
				) {

				var o_option = Ext.Array.findBy(a_quick, function(o_values) {
					return o_values.dataIndex == o_column.dataIndex;
				}) || {};

				Ext.apply(o_column, {
					xtype: "widgetcolumn",
					widget: {
						xtype: "iField",
						metaData: {
							len: o_option.len || 10,
							ffw: o_option.ffw,
							fieldStyle: {
								"text-align": "right"
							}
						},
						listeners: {
							fieldfocus: {
								fn: function(i_field) {

									var i_store = i_self.getStore();

									var i_widgetRecord = i_field.getWidgetRecord();

									var n_index = i_store.find(i_widgetRecord.idProperty, i_widgetRecord.get(i_widgetRecord.idProperty));

									if (n_index > -1) {
										var i_view = i_self.view;
										i_view.select(i_widgetRecord);
									}
								}
							},
							specialKey: {
								fn: function(i_field, i_event) {

									var i_store = i_self.getStore();

									var a_range = i_store.getRange();

									var a_options = [];

									var i_column = i_field.getWidgetColumn();

									Ext.Array.each(a_range, function(i_record) {

										var s_id = i_record.getId().split("g.").pop();

										var i_widget = i_column.getWidget(i_record);

										if (i_widget.getValue()) {

											var o_data = {
												field: s_id,
												option: i_widget.getValue(),
												col: Ext.Number.from(i_record.get("col"), 0),
												lin: Ext.Number.from(i_record.get("lin"), 0)
											};

											a_options.push(o_data);
										}
									});

									i_self.fireEvent("fieldoption", a_options);
								}
							}
						}
					}
				});

				delete o_column.renderer;
			}
			else {
				o_column.renderer = function (value, i_meta, i_record, n_row, n_col) {

					var atr = i_record.get("atr" + (n_col + 1));
					i_meta.tdCls = ["iceCap-output", atr || 20, i_self.getTheme()].filter(Boolean).join("-");

					return value;
				};
			}

			o_column.width = o_column.width || null;
			o_column.flex = o_column.width ? null : 1;

			a_return.push(o_column);
		});

		return a_return;
	},

	createToolbar: function() {

		var i_self = this;

		var o_config = i_self.getGridConfig();

		var a_bottom = Ext.Array.from(o_config.bottomKeys);

		var a_keys = i_self.getKeys();

		var a_extraButtons = o_config.extraToolbarButtons || [];

		var a_omited = Ext.Array.filter(a_bottom, function(o_key) {
			return o_key.key;
		});

		var a_filtered = Ext.Array.filter(a_keys, function(o_key) {

			var i_found = Ext.Array.findBy(a_omited, function(o_filtered) {
				return o_key.id == o_filtered.key;
			});

			return !i_found;
		});

		var a_buttons = i_self.createButtons(a_filtered);

		if (a_extraButtons.length > 0) {

			a_extra = Ext.Array.filter(a_extraButtons, function(o_key) {

				var i_found = Ext.Array.findBy(a_omited, function(o_filtered) {
					return o_key.id == o_filtered.key;
				});

				return !i_found;
			});

			var a_return = i_self.createButtons(a_extra);

			a_buttons = a_buttons.concat(a_return);
		}

		if (a_buttons.length > 0) {
			var i_toolbar = Ext.widget("toolbar", {
				dock: "top",
				items: a_buttons
			});

			i_self.setToolbar(i_toolbar);

			i_self.addDocked(i_toolbar);
		}
	},

	createPagingToolbar: function() {

		var i_self = this;
		var i_store = i_self.getStore();

		var i_toolbar = Ext.widget("toolbar", {
			dock: "bottom",
			items: [
				{
					xtype: "button",
					iconCls: "icecap-icon-page-prev",
					handler: function() {

						i_self.fireEvent("key", "ROLLDOWN");
					}
				},
				'->',
				{
					xtype: "button",
					iconCls: "icecap-icon-page-next",
					handler: function() {

						i_self.fireEvent("key", "ROLLUP");
					}
				}
			]
		});

		i_self.setPagingToolbar(i_toolbar);

		return i_toolbar;
	},

	createRowMenu: function() {

		var i_self = this;
		var o_config = i_self.getGridConfig();

		var a_items = [];

		var s_options = o_config.defaultOption || "";

		var a_defaultsOptions = s_options.split(",");

		var n_position = 99;

		var s_defaultOption = "";

		Ext.Array.each(o_config.menu, function(o_item) {

			var i_item = Ext.widget("menuitem", {
				text: o_item.text + " ( " + o_item.id + " )",
				option: o_item.id,
				breakout: o_item.breakout || false,
				icon: "/system/snapOnIcon.aspx.png?keyword=" + escape(o_item.text) + "&default=folder.png&insertRoot=true",
				handler: function(i_menuitem) {

					var a_selected = i_self.getSelection();

					var f_breakout = eval(i_menuitem.breakout);

					if (!i_menuitem.breakout) {

						var a_options = [];

						Ext.Array.each(a_selected, function(i_record) {

							var s_id = i_record.getId().split("g.").pop();

							var o_data = {
								field: s_id,
								option: i_menuitem.option,
								col: Ext.Number.from(i_record.get("col"), 0),
								lin: Ext.Number.from(i_record.get("lin"), 0)
							};

							a_options.push(o_data);
						});

						i_self.fireEvent("fieldoption", a_options);
					}
					else {
						if (Ext.isFunction(f_breakout)) {

							Ext.Array.each(a_selected, function(i_record) {
								f_breakout(i_record.getData());
							});
						}
					}
				}
			});

			var n_index = a_defaultsOptions.indexOf(o_item.id);

			if (n_index > -1) {
				if (n_index < n_position) {
					n_position = n_index;
					s_defaultOption = o_item.id;
				}
			}

			a_items.push(i_item);
		});

		var i_found = Ext.Array.findBy(a_items, function(i_item) {
			return i_item.option == s_defaultOption;
		});

		if (i_found) {
			i_found.text = "<strong>" + i_found.text + "</strong>";
		}

		var i_menu = Ext.widget("menu", {
			items: a_items
		});

		i_self.setRowMenu(i_menu);
		i_self.setDefaultOption(s_defaultOption);
	},

	createButtons: function(a_config) {

		var i_self = this;

		var a_buttons = [];

		Ext.Array.each(a_config, function(o_config) {

			var o_key = {
				xtype: "button",
				key: o_config.id ? o_config.id : o_config.key,
				text: o_config.text,
				icon: "/system/snapOnIcon.aspx.png?keyword=" + escape(o_config.text) + "&default=folder.png&insertRoot=true",
				iconCls: o_config.iconCls,
				handler: function(i_button) {
					i_self.fireEvent("key", i_button.key);
				}
			};

			a_buttons.push(o_key);
		});

		return a_buttons;
	}

}, function() {

	Ext.apply(window, {
		onRowRightClick: Ext.emptyFn,
		renderField: function (val, meta, rec, row, col) {
			var atr = rec.data["atr" + (col + 1)],
			io = rec.data["io" + (col + 1)];

			if (io != "b" && io != "i") {
				return val;
			}

			var html = "<div id=\"" + Ext.id() + "." + rec.id + ".c" + (col + 1) + "\"";
			return html + "></div>";
		},
		renderOptionField: function(value, i_meta, i_record, n_row, n_col) {

			var s_attr = i_record.get("atr" + (n_col + 1));
			var s_html = "";

			s_html = "<div id=\"win-opt-" + n_row + "\""  ;

			if (!Ext.isEmpty(s_attr)) {
				s_html += " class=\"iceCap-output-" + s_attr + "\"";
			}

			s_html += "></div>";

			return s_html;
		},
		renderQuickKeyField: function(val, meta, rec, row, col) {
			var atr = rec.data['atr' + (col + 1)],
			html;

			if (rec.id.indexOf('q.') > -1) {
				html = '<div id=' + Ext.id() + '.qCol.' + col + '"';
				if (!Ext.isEmpty(atr)) {
					html += ' class="iceCap-output-' + atr + '"';
				}

				html += '></div>';
			}
			else if (!Ext.isEmpty(atr)) {
				html = '<div class="iceCap-output-' + atr + '">' + val + '</div>';
			}
			else {
				html = val;
			}
			return html;
		}
	});
});
Ext.define("IceCap.ux.container.Column", {
	
	extend: "Ext.Container",

	alias: [
		"widget.iColumn"
	],

	defaults: {
		xtype: "container",
		layout: {
			type: "form"
		},
		defaults: {
			autoEl: {},
			style: "padding:8px 0 0 5px"
		}
	},

	layout: {
		type: "column"
	},

	flex: 1,
	focusable: false,

  	constructor: function(o_config) {

		var i_self = this;

		i_self.name = i_self.id || o_config.id;

		delete i_self.id;
		delete o_config.id;

		i_self.callParent([o_config]);
	},

 	initComponent: function() {

 		var i_self = this;

 		i_self.callParent(arguments);
 	}
});Ext.define("IceCap.ux.form.label.Label", {
	
	extend: "Ext.form.field.Display",

	alias: [
		"widget.iLabel"
	],

	config: {
		theme: "default"
	},

	focusable: false,

	initComponent: function () {

		var i_self = this;

		var o_config = i_self.initialConfig;

		var s_value = o_config.text;

		if (o_config.ta == "right" && !o_config.off) {
			//o_config.col += o_config.len - o_config.dta.length;
		}

		if (o_config.off) {
			s_value = Ext.String.leftPad(s_value, s_value.length + o_config.off);
		}

		var o_field = {
			value: s_value,
			htmlEncode: true,
			cls: ["icecap-field", i_self.getTheme()].filter(Boolean).join("-")
		};

		var o_style = {
			"font": "normal " + IceCap.util.Handler.getTextSize() + "px Segoe UI,Segoe,DejaVu Sans,Trebuchet MS,Verdana,sans-serif",
			"margin-top": IceCap.util.Handler.getMargin() + "px !important",
			"min-height": "0px !important"
		};

		Ext.apply(o_field, {
			fieldStyle: o_style
		});

		if (o_config.atr == "27") {
			o_field.hidden = true;
		}

		Ext.apply(i_self, o_field);

		i_self.callParent();

		if (o_config.atr == 23) {

			i_self.addCls("icecap-invalid");
		}
	}
});Ext.define("IceCap.ux.form.field.Field", {

	extend: "Ext.form.FieldContainer",

	alias: [
		"widget.iField"
	],

	config: {
		theme: "default",
		field: null
	},

	border: false,

	layout: "fit",

	mixins: [
		"Ext.form.field.Field"
	],

	listeners: {
		focus: {
			fn: function(i_container) {

				var i_field = i_container.getField();
				i_field.focus(true, 10);
			}
		}
	},

	initComponent: function () {

		var i_self = this;

		var o_config = i_self.initialConfig;

		var n_inputWidth = o_config.width || 80;

		var n_default = IceCap.util.Handler.getDefaultWidth();
		var n_width = n_default;
		if (o_config.len > 1) {
			n_width = ((o_config.len - 1) * IceCap.util.Handler.getColSize()) + n_default;
		}

		if (o_config.len > n_inputWidth) {
			var n_temp = n_inputWidth - o_config.col;
			n_width = ((n_temp - 1) * IceCap.util.Handler.getColSize()) + n_default;
		}

		Ext.apply(i_self, {
			width: n_width
		});

		i_self.callParent();

		i_self.createField();

		var i_field = i_self.getField();

		if (o_config.atr == 25) {

			if (o_field.readOnly) {
				i_self.addCls("icecap-invalid");
			}
			else {
				i_field.markInvalid(true);
			}
		}
	},

	focus: function() {

		var i_self = this;
		var i_field = i_self.getField();

		i_field.focus(true, 10);
		i_self.fireEvent("fieldfocus", i_self);
	},

	createField: function() {

		var i_self = this;

		var o_config = i_self.initialConfig;

		var o_meta = o_config.metaData || {};

		var o_field = {
			inputType: "text",
			xtype: "textfield"
		};

		Ext.apply(o_field, i_self.applyFFW(o_config));

		var s_type = o_field.xtype || "textfield";
		var b_password = o_config.atr == "27";

		if (o_field.readOnly) {

			o_field.xtype = s_type = "displayfield";

			Ext.apply(o_field.fieldStyle, {
				"padding": "1px 3px 2px 3px",
				"margin-top": IceCap.util.Handler.getMargin() + "px !important",
				"margin-left": "1px",
				"border": "1px solid transparent"
			});
		}

		var o_listeners = Ext.apply({}, o_meta.listeners);
		delete o_meta.listeners;

		var a_field = ["icecap-field", i_self.getTheme()];

		var a_pass = [b_password ? "iceCap-input-password" : "iceCap-input-" + (o_config.atr || 20)];

		a_pass.push(i_self.getTheme());

		var a_cls = [a_field.filter(Boolean).join("-"), a_pass.filter(Boolean).join("-")];

		var s_cls = a_cls.join(" ");

		Ext.Object.merge(o_field, {
			enforceMaxLength: true,
			maxLength: o_config.len,
			flex: 1,
			minWidth: IceCap.util.Handler.getDefaultWidth(),
			lin: o_config.lin,
			col: o_config.col,
			emuId: o_config.name,
			value: o_config.dta || "",
			cls: s_cls,
			enableKeyEvents: true,
			selectOnFocus: true,
			listeners: {
				afterrender: {
					fn: function(i_field) {

						if (i_field.inputEl && !i_field.metaField) {
							i_field.inputEl.setMinHeight(0);
							i_field.inputEl.setHeight(IceCap.util.Handler.getDefaultHeight());

							i_field.inputEl.set({
								autocomplete: "off"
							});
						}
					}
				},
				specialKey: {
					fn: function(i_field, i_event) {

						if (i_event.getKey() == Ext.event.Event.ENTER) {
							i_self.fireEvent("specialKey", i_self, i_event);
						}
					}
				},
				focus: {
					fn: function(i_field) {

						i_self.fireEvent("fieldfocus", i_self);
					}
				}
			}
		}, o_meta);

		var o_clone = Ext.clone(o_field);

		if (o_meta.xtype) {

			o_clone.metaField = true;

			o_clone.xtype = s_type = o_meta.xtype;

			delete o_clone.cls;
			delete o_clone.fieldStyle;
			delete o_clone.inputType;
		}

		delete o_clone.width;

		var i_field = Ext.widget(o_clone.xtype, o_clone);

		i_self.setField(i_field);

		i_self.add(i_field);
	},

	getValue: function() {

		var i_self = this;
		var i_field = i_self.getField();
		return i_field.getValue();
	},

	setValue: function(value) {

		var i_self = this;
		var i_field = i_self.getField();
		return i_field.setValue(value);
	},

	applyFFW: function(o_config) {

		var i_self = this;
		var s_hex = o_config.ffw;
		var b_fixed = IceCap.util.Handler.getFixed();

		var o_field = {
			xtype: "textfield"
		};

		var o_fieldStyle = {
			font: "normal " + IceCap.util.Handler.getTextSize() + "px Segoe UI,Segoe,DejaVu Sans,Trebuchet MS,Verdana,sans-serif"
		};

		if (b_fixed) {

			Ext.apply(o_fieldStyle, {
				font: "normal " + IceCap.util.Handler.getTextSize() + "px Lucida Console, Courier New, monospace"
			});
		}

		if (o_config.ta) {

			Ext.apply(o_fieldStyle, {
				"text-align": o_config.ta
			});
		}

		if (s_hex) {

			var n_hex = parseInt(s_hex);

			var n_sanHex = IceCap.util.Handler.createIndicators(s_hex);

			if (n_sanHex & IceCap.util.Handler.FFW.BYPASS) {

				Ext.apply(o_field, {
					readOnly: true
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.ALPHA_ONLY) {

				Ext.apply(o_field, {
					maskRe: new RegExp("[a-z A-Z ,.-]")
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.NUMERIC_ONLY) {

				Ext.apply(o_field, {
					maskRe: new RegExp("[+\\-,. 0-9]")
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.DIGITS_ONLY) {

				Ext.apply(o_field, {
					maskRe: new RegExp("[0-9]")
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.MOD_DATA) {

				Ext.apply(o_field, {
					listeners: {
						afterrender: {
							fn: function(i_field) {

								i_field.originalValue = 0xFF;
							},
							single: true
						}
					}
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.AUTO_ENTER) {

				// THIS WE DONT NEED IN THE MODERN WORLD...

				// Ext.apply(o_field, {
				// 	listeners: {
				// 		blur: {
				// 			fn: function(i_field) {
				// 				i_self.doKeyEvent("ENTER");
				// 			}
				// 		}
				// 	}
				// });
			}

			if (n_sanHex & IceCap.util.Handler.FFW.MONOCASE) {

				Ext.apply(o_fieldStyle, {
					"text-transform": "uppercase"
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.MAND_ENTER) {

				Ext.apply(o_field, {
					allowBlank: false
				});
			}

			if (o_config.atr == "27" && n_hex & (1 << 13)) {

				Ext.apply(o_field, {
					hidden: true,
					disabled: true
				});
			}
		}

		Ext.apply(o_field, {
			fieldStyle: o_fieldStyle
		});

		return o_field;
	}
});
Ext.define("IceCap.ux.form.panel.fusionChart", {

	extend: "Ext.panel.Panel",

	alias: [
		"widget.FUSIONCHART"
	],

	header: false,

	width: 500,

	height: 500,

	bodyPadding: 5,

	focusable: false,

	layout: "fit",

	config: {
		chartData: [],
		chartType: ""
	},

	border: false,

	constructor: function(o_config) {

		var i_self = this;


		Ext.apply(o_config, {
			chartData: o_config.data ? Ext.Array.from(o_config.data) : []
		});

		delete o_config.data;

		i_self.callParent([o_config]);

	},

	initComponent: function() {

		var i_self = this;
		i_self.callParent();

		var i_chart = i_self.createChart();

		i_self.add(i_chart);

	},

	createChart: function() {

		var i_self = this;

		var s_type = i_self.getChartType().toLowerCase();

		var i_chart;
		switch (s_type) {
			case "column3d":
				i_chart = i_self.createColumn3D(i_self.getChartData());
				break;
			case "column":
				i_chart = i_self.createColumn(i_self.getChartData());
				break;
			default:
				break;
		}

		return i_chart;
	},

	createColumn3D: function(a_input) {

		var a_data = [];

		var a_fields = [
			"category",
			"value"
		];

		Ext.Array.each(a_input, function(a_value) {

			var value = a_value[1] || 0;

			if(value) {
				value = value.replace(".", "").replace(",", ".");
				value = parseFloat(value);
			}

			var o_record = {
				category: a_value[0],
				value: value
			};

			a_data.push(o_record);
		});

		a_data = a_data.reverse();

		var i_store = Ext.create("Ext.data.Store", {
			proxy: {
				type: "memory",
				reader: {
					type: "json",
					rootProperty: "rows",
					totalProperty: "totalRows"
				}
			},
			fields: a_fields,
			data: a_data
		});

		var i_chart = Ext.widget("cartesian", {
			store: i_store,
			flex: 1,
			insetPadding: 40,
			axes: [
				{
					type: "numeric",
					position: "right",
					grid: true,
					fields: "value",
					label: {
						rotate: {
							degrees: -30
						}
					}
				},
				{
					type: "category3d",
					fields: "category",
					position: "bottom"
				}
			],
			series: {
				type: "bar3d",
				xField: "category",
				yField: "value",
				style: {
					maxBarWidth: 50,
					minGapWidth: 20
				},
				label: {
					field: "value",
					display: "insideEnd",
					renderer: function (value) {
						return value.toFixed(2);
					}
				}
			}
		});

		return i_chart;
	},

	createColumn: function (a_input) {

		var a_data = [];

		var a_fields = [
			"category",
			"value"
		];

		Ext.Array.each(a_input, function (a_value) {

			var value = a_value[1] || 0;

			if (value) {
				value = value.replace(".", "").replace(",", ".");
				value = parseFloat(value);
			}

			var o_record = {
				category: a_value[0],
				value: value
			};

			a_data.push(o_record);
		});

		a_data = a_data.reverse();

		var i_store = Ext.create("Ext.data.Store", {
			proxy: {
				type: "memory",
				reader: {
					type: "json",
					rootProperty: "rows",
					totalProperty: "totalRows"
				}
			},
			fields: a_fields,
			data: a_data
		});

		var i_chart = Ext.widget("cartesian", {
			store: i_store,
			flex: 1,
			insetPadding: 40,
			axes: [
				{
					type: "numeric",
					position: "right",
					grid: true,
					fields: "value",
					label: {
						rotate: {
							degrees: -30
						}
					}
				},
				{
					type: "category",
					fields: "category",
					position: "bottom"
				}
			],
			series: {
				type: "bar",
				xField: "category",
				yField: "value",
				style: {
					maxBarWidth: 50,
					minGapWidth: 20
				},
				label: {
					field: "value",
					display: "insideEnd",
					renderer: function (value) {
						return value.toFixed(2);
					}
				}
			}
		});

		return i_chart;
	}
});
Ext.define("IceCap.ux.form.field.SimpleComboBox", {

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

	alias: [
		"widget.COMBOBOX"
	],

	valueField: "key",

	displayField: "value",

	typeAhead: true,

	mode: "local",

	forceSelection: true,

	triggerAction: "all",

	selectOnFocus: true,

	minChars: 1,

	config: {
		valueMap: []
	},

	listeners: {
		keydown: {
			fn: function(i_field, i_event) {

				var n_key = i_event.getKey();
				
				if (i_field.isExpanded) {
					if (n_key == Ext.event.Event.DOWN || n_key == Ext.event.Event.UP) {
						i_event.stopEvent();
					}
				}
			}
		}
	},

	initComponent: function() {

		var i_self = this;
		var i_store = i_self.createStore();

		i_self.store = i_store;
		i_self.callParent();
	},

	createStore: function() {

		var i_self = this;

		var a_data = [];

		var a_valueData = i_self.getValueMap();

		Ext.Array.each(a_valueData, function(a_value) {

			if (a_value.length >= 2) {
				var o_data = {
					key: a_value[0],
					value: a_value[1]
				};

				a_data.push(o_data);
			}
		});

		var i_store = Ext.create("Ext.data.Store", {
			fields: [
				{
					name: "key",
					type: "auto"
				},
				{
					name: "value",
					type: "auto"
				}
			],
			autoLoad: true,
			data: a_data
		});

		return i_store;
	}
});
Ext.define("IceCap.ux.form.field.sqlComboBox", {

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

	alias: [
		"widget.DDSQL"
	],

	minChars: 1,

	valueField: "KEY",

	displayField: "VALUE",

	typeAhead: true,

	mode: "remote",

	triggerAction: "all",

	selectOnFocus: true,

	matchFieldWidth: false,

	editable: true,

	config: {
		sqlVoucher: ""
	},

	listeners: {
		keydown: {
			fn: function(i_field, i_event) {

				var n_key = i_event.getKey();
				
				if (i_field.isExpanded) {
					if (n_key == Ext.event.Event.DOWN || n_key == Ext.event.Event.UP) {
						i_event.stopEvent();
					}
				}
			}
		}
	},

	initComponent: function() {

		var i_self = this;
		var i_store = i_self.createStore();

		i_self.store = i_store;
		i_self.callParent();

		var i_model = i_store.getModel();

		var value = i_self.getValue();
		var rawValue = i_self.getRawValue();

		var i_created = i_model.create({
			KEY: rawValue,
			VALUE: value
		});

		if (i_created.get(i_created.idProperty)) {
			i_store.add(i_created);
		}
	},

	initValue: function() {

		var i_self = this;

		var i_store = i_self.getStore();

		var i_model = i_store.getModel();

		var value = i_self.value || null;

		var a_loaded = [];

		if (Ext.isEmpty(value)) {
			value = null;
		}

		var a_values = Ext.Array.from(value);

		var n_load = a_values.length;

		if (n_load) {
			var a_load = [];

			var a_result = [];

			Ext.Array.each(a_values, function(value) {

				var i_test = i_model.create({});
				i_test.set(i_model.idProperty, value);

				if (i_test.get(i_model.idProperty) === value) {
					a_load.push(value);
				}
			});

			if (a_load.length > 0) {

				i_store.load({
					callback: function(a_records, i_store) {

						a_records = Ext.Array.from(a_records);

						if (a_records.length === 0) {
							value = null;
						}

						i_self.suspendCheckChange++;
						i_self.setValue(value);
						i_self.suspendCheckChange--;
					}
				});

				i_self.originalValue = i_self.lastValue = value;
				i_self.resetOriginalValue();
			}
			else {

				i_self.suspendCheckChange++;
				i_self.setValue(null);
				i_self.suspendCheckChange--;
				i_self.originalValue = i_self.lastValue = null;
				i_self.resetOriginalValue();
			}
		}
		else {
			i_self.originalValue = i_self.lastValue = i_self.getValue();
			i_self.resetOriginalValue();
		}
	},

	createStore: function() {

		var i_self = this;

		var i_store = Ext.create("Ext.data.Store", {
			fields: [
				{
					name: "KEY",
					type: "auto"
				},
				{
					name: "VALUE",
					type: "auto"
				}
			],
			pageSize: i_self.pageSize || 25,
			proxy: {
				url: "/icecap/DDSQL.aspx?runSql=runsql&sqlVoucher=" + i_self.getSqlVoucher(),
				type: "ajax",
				reader: {
					type: "json"
				}
			},
			idProperty: "VALUE"
		});

		return i_store;
	}
});
Ext.define("IceCap.ux.form.field.sqlSearchBox", {

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

	alias: [
		"widget.DDSEARCH"
	],

	minChars: 1,
	maxLength: 10,
	valueField: "KEY",
	displayField: "VALUE",
	forceSelection: false,
	typeAhead: false,
	pageSize: 25,
	matchFieldWidth: false,

	config: {
		sqlVoucher: ""
	},

	listeners: {
		keydown: {
			fn: function(i_field, i_event) {

				var n_key = i_event.getKey();
				
				if (i_field.isExpanded) {
					if (n_key == Ext.event.Event.DOWN || n_key == Ext.event.Event.UP) {
						i_event.stopEvent();
					}
				}
			}
		},
		select: {
			fn: function(i_field, i_record, n_number) {

				var a_fields = i_record.getFields();

				Ext.Array.each(a_fields, function(i_recordField) {

					var a_elements = document.getElementsByName(i_recordField.name);

					if (a_elements.length > 0) {

						var i_element = Ext.get(a_elements[0]);
						var i_component = i_element.component;

						var value = i_record.get(i_recordField.name);

						if (i_component) {
							i_component.setValue(value);
						}
						else {
							i_element.dom.value = value;
						}
					}
				});
			}
		}
	},

	initComponent: function() {

		var i_self = this;
		var i_store = i_self.createStore();

		i_self.store = i_store;
		i_self.tpl = i_self.createTemplate();

		i_self.callParent();
	},

	createTemplate: function() {

		var i_template = new Ext.XTemplate(
			"<tpl for=\".\">",
				"<li role=\"option\" class=\"x-boundlist-item\" style=\"text-overflow: ellipsis; white-space: nowrap; overflow:hidden;\">",
					"{VALUE}",
				"</li>",
			"</tpl>"
		);

		return i_template;
	},

	createStore: function() {

		var i_self = this;

		var i_store = Ext.create("Ext.data.Store", {
			fields: [
				{
					name: "KEY",
					type: "auto"
				},
				{
					name: "VALUE",
					type: "auto"
				}
			],
			pageSize: i_self.pageSize || 25,
			proxy: {
				url: "/icecap/DDSQL.aspx?runSql=runsql&sqlVoucher=" + i_self.getSqlVoucher(),
				type: "ajax",
				reader: {
					type: "json"
				}
			}
		});

		return i_store;
	}
});
Ext.define("IceCap.ux.form.field.LINKFIELD", {

	extend: "Ext.form.field.Text",

	alias: [
		"widget.LINKFIELD"
	],

	triggers: {
		switch: {
			cls: "icecap-form-link-trigger",
			overCls: "no-overcls",
			clickCls: "no-clickcls",
			weight: 1,
			scope: "this",
			handler: function(i_trigger) {

				var i_field = this;

				if (!i_field.getValue()) {
					Ext.MessageBox.alert("Message", "Url required");
				}
				else {
					window.open(i_field.getValue(), i_field.getValue(), "");
				}
			}
		}
	},

	validationEvent: false,
	validateOnBlur: false,

	initComponent: function () {

		var i_self = this;
		i_self.callParent();
	}
});
Ext.define("IceCap.ux.form.field.AdvancedComboBox", {

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

	alias: [
		"widget.DDLIB"
	],

	minChars: 1,  // character needed to start server search,
	maxLength: 10,
	displayField: "key",
	forceSelection: false,
	valueField: "key",
	typeAhead: false,
	pageSize: 25,
	hideTrigger: false,
	matchFieldWidth: false,

	listeners: {
		keydown: {
			fn: function(i_field, i_event) {

				var n_key = i_event.getKey();
				
				if (i_field.isExpanded) {
					if (n_key == Ext.event.Event.DOWN || n_key == Ext.event.Event.UP) {
						i_event.stopEvent();
					}
				}
			}
		},
	},

	initComponent: function() {

		var i_self = this;
		i_self.tpl = i_self.createTemplate();

		var i_store = Ext.create("Ext.data.Store", {
			proxy: {
				url: "/icecap/ddlibs.aspx?func=getRows",
				type: "ajax",
				reader: {
					type: "json"
				}
			},
			pageSize: i_self.pageSize || 25,
			fields: [
				{
					name: "key",
					type: "auto"
				},
				{
					name: "value",
					type: "auto"
				}
			],
			autoLoad: true
		});

		i_self.store = i_store;

		i_self.callParent();
	},

	createTemplate: function() {

		var i_template = new Ext.XTemplate(
			"<tpl for=\".\">",
				"<li role=\"option\" class=\"x-boundlist-item\" style=\"text-overflow: ellipsis; white-space: nowrap; overflow:hidden;\">",
					"<b>{key} - </b> {value}",
				"</li>",
			"</tpl>"
		);

		return i_template;
	}
});
Ext.define("IceCap.ux.form.field.CommandField", {

	extend: "Ext.form.field.TextArea",

	alias: [
		"widget.CommandField"
	],

	config: {
		fldNo: 0
	},

	cls: "iceCap-input-field"

});
Ext.define("IceCap.ux.form.field.LibraryFileDependency", {

	extend: "Ext.form.field.Text",

	alias: [
		"widget.LibraryFileDependency"
	],

	listeners: {
		blur: {
			fn: function(i_field) {

				var i_self = this;
				var i_ownerCt = i_self.ownerCt;

				var i_owner = Ext.getCmp(i_ownerCt.id);

				var a_inputs = i_owner.query("input");

				Ext.Array.each(a_inputs, function(i_input) {

					if (i_input.getStore) {

						var i_store = i_input.getStore();
						var i_proxy = i_store.getProxy();

						var o_params = i_proxy.getExtraParams();

						Ext.apply(o_params, {
							lib: i_field.getValue()
						});

						i_store.load();
					}
				});
			}
		}
	}
});
Ext.define("IceCap.ux.form.field.FileLibraryDependency", {

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

	alias: [
		"widget.FileLibraryDependency"
	],

	valueField: "obj",
	displayField: "txt",
	fieldLabel: "File",

	typeAhead: true,

	mode: "remote",

	triggerAction: "all",

	selectOnFocus: true,

	matchFieldWidth: false,

	editable: true,

	config: {
		lib: "qtemp",
		obj: "*all",
		typ: "*all",
		atr: "*all"
	},

	initComponent: function() {

		var i_self = this;
		i_self.tpl = i_self.createTemplate();

		var i_store = Ext.create("Ext.data.Store", {
			params: {
				lib: i_self.getLib(),
				obj: i_self.getObj(),
				typ: i_self.getTyp(),
				atr: i_self.getAtr()
			},
			proxy: {
				url: "/icecap/ddlibs.aspx?func=getRows",
				type: "ajax",
				reader: {
					type: "json"
				}
			},
			fields: [
				{
					name: "obj",
					type: "auto"
				},
				{
					name: "txt",
					type: "auto"
				}
			],
			autoLoad: true
		});

		i_self.store = i_store;

		i_self.callParent();
	},

	createTemplate: function() {

		var i_template = new Ext.XTemplate(
			"<tpl for=\".\">",
				"<li role=\"option\" class=\"x-boundlist-item\" style=\"text-overflow: ellipsis; white-space: nowrap; overflow:hidden;\">",
					"<b>{key} - </b> {value}",
				"</li>",
			"</tpl>"
		);

		return i_template;
	}
})
Ext.define("IceCap.ux.form.field.RadioGroup", {

	extend: "Ext.form.RadioGroup",

	alias: [
		"widget.RADIOGROUP"
	],

	config: {
		valueMap: []
	},

	layout: {
		type: "hbox",
		align: "stretch"
	},

	flex: 1,

	defaults: {
		margin: "0 20 0 0"
	},

	initComponent: function() {

		var i_self = this;

		i_self.items = i_self.createButtons();

		i_self.on({
			afterender: {
				fn: function(i_field) {

					var value = i_field.value;

					if (value) {

						i_field.setValue(value);
					}
				}
			},
			specialkey: {
				fn: function(i_field, e) {

					if (e.keyCode == 39 || e.keyCode == 37) {

						var n_index = 0;

						var b_found = false;

						var n_len = i_field.items.length;

						var a_items = i_field.getBoxes();

						Ext,Array.each(a_items, function(i_radio) {
							if (i_radio.innerWrap.id == e.target.id) {
								b_found = true;
							}
							if (!b_found) {
								n_index++;
							}
						});

						if (e.keyCode == 39) {
							n_index++;
						}
						else if (e.keyCode == 37) {
							n_index--;
						}
						if (b_found) {

							var i_radio;

							if (n_index == n_len) {
								i_radio = i_field.items.get(0);
							}
							else {
								if (n_index < 0) {
									i_radio = i_field.items.get(n_len - 1);
								}
								else {
									i_radio = i_field.items.get(n_index);
								}
							}

							i_radio.innerWrap.focus();

							i_field.setValue(i_radio.inputValue);
						}
					}
				}
			}
		});

		i_self.width = null;
		i_self.flex = 1;

		i_self.callParent(arguments);

		return i_self;
	},

	createButtons: function(a_values) {

		var i_self = this;
		var a_values = i_self.getValueMap();
		var a_return = [];

		Ext.Array.each(a_values, function(o_input) {

			var o_radio = {
				inputValue: o_input.key,
				boxLabel: o_input.value,
				name: i_self.name,
				flex: 1
			};
			a_return.push(o_radio);
		});

		return a_return;
	},

	getValue: function() {

		var i_self = this;
		var value = i_self.value;

		var a_items = i_self.getBoxes();

		Ext.Array.each(a_items, function(i_radio) {
			if (i_radio.inputValue == value) {
				value = i_radio.getGroupValue();
			}
		});

		return value;
	},

	setValue: function(value) {

		var i_self = this;

		var a_items = i_self.getBoxes();

		Ext.Array.each(a_items, function(i_radio) {
			if (i_radio.inputValue == value) {
				i_radio.setValue(true);
			}
			else {
				i_radio.setValue(false);
			}
		});

		i_self.value = value;
	},

	setFocus: function() {

		var i_self = this;
		var b_found = false;

		var a_items = i_self.getBoxes();

		Ext.Array.each(a_items, function(i_radio) {
			if (i_radio.checked) {
				b_found = true;
				i_radio.innerWrap.focus();
				i_self.setValue(i_radio.inputValue);
			}
		});

		if (!b_found) {
			var i_radio = i_self.items.get(0);
			i_radio.innerWrap.focus(true);
			i_self.setValue(i_radio.inputValue);
		}
	}
});
Ext.define("IceCap.ux.container.CommandPanel", {
	
	extend: "Ext.panel.Panel",

	alias: [
		"widget.COMMANDPANEL"
	],
    
    focusable: false,

    width:280,

    height:24,

    border: false,

    header: false,

 	initComponent: function() {

         var i_self = this;
         
         i_self.buttons = i_self.createButtons();

        i_self.callParent(arguments);

        i_self.add(i_self.createItems());
     },
     
     createItems: function() {

        var a_items = [];

        var i_store = Ext.create("Ext.data.Store", {
            autoLoad: true,
			fields: [
				"cmd",
				"description"
			],
			data:[
				{
					cmd: "wrksplf",
					description: "Work with spooled files"
				},
				{
					cmd: "wrksplf",
					description: "Work with spooled files"
				}
			]
        });

        var i_comboBox = Ext.widget("combobox", {
            store: i_store,
            displayField: "description",
            valueField: "cmd",
            width: 250,
            editable: false,
            selectOnFocus: true,
            emptyText: "Select a command and click OK..."
        });

        a_items.push(i_comboBox);

        return a_items;
     },

     createButtons: function() {

        var i_self = this;

        var a_buttons = [];

        var i_bntOK = Ext.widget("button", {
            text: "OK",
            handler: function() {
                debugger;
            }
        });

        a_buttons.push(i_bntOK);

        return a_buttons;
     }
});Ext.define("IceCap.ux.container.GMapPanel", {
	extend: "Ext.panel.Panel",

	alias: "widget.icecap-gmappanel",

	config: {
		center: null,
		mapOption: {},
		scaleControl: true,
		geoCoder: null,
		map: null,
		markers: [],
		zoom: 7,
		stored: null,
		added: [],
        api: "//maps.googleapis.com/maps/api/js",
        gestureHandling: "cooperative"
	},

	border: false,

	listeners: {
		afterrender: {
			fn: function(i_panel) {

				var i_self = this;

				var o_google = window.google || {};

				if (o_google.maps) {
					i_self.initMap();
				}
				else {
					var i_entry = Ext.Boot.getEntry(i_self.getApi(), {
						crossDomain: true,
						listeners: [
							function(i_entry) {
								o_google = window.google || {};
								if (o_google.maps) {
									i_self.initMap();
								}
								else {
									Ext.raise("Error loading google maps api at :" + i_self.getApi());
								}
							}
						]
					});
					i_entry.load(false);
				}
			},
			buffer: 10
		},
		beforedestroy: {
			fn: function(i_panel) {

				var i_self = this;
				var a_markers = i_self.getAdded();

				Ext.Array.each(a_markers, function(i_marker) {
					i_marker.setMap(null);
				});

				i_self.setAdded(null);
				i_self.setMap(null);
				i_self.setStored(null);
				i_self.setCenter(null);
				i_self.setGeoCoder(null);
			}
		}
	},

	initComponent: function() {

		var i_self = this;
		i_self.callParent();
	},

	initMap: function() {

		var i_self = this;

		var o_center = i_self.getCenter() || {
			lat: 55.846330,
			lng: 10.593858
		};

		var o_stored = i_self.getStored() || "";

		if (o_stored) {
			if (o_stored.lat && o_stored.lng) {
				o_center = o_stored;
			}
		}

		if (o_center) {
			if (o_center.geoCodeAddr) {
				i_self.lookupCode(o_center.geoCodeAddr, o_center.marker);
			}
			else {
				i_self.createMap(o_center);
			}
		}
		else {
			Ext.raise("center is required");
		}
	},

	createMap: function(o_center, o_marker) {

		var i_self = this;
		var a_markers = i_self.getMarkers();
		var google = window.google;

		var o_options = Ext.apply({}, i_self.mapOptions);

		o_options = Ext.applyIf(o_options, {
			zoom: i_self.getZoom(),
			center: o_center,
			mapTypeId: google.maps.MapTypeId.MAP,
            scaleControl: i_self.getScaleControl(),
            gestureHandling: i_self.getGestureHandling()
		});

		var i_map = new google.maps.Map(i_self.body.dom, o_options);

		i_self.setMap(i_map);

		if (o_marker) {
			i_self.addMarker(Ext.applyIf(o_marker, {
				position: o_center
			}));
		}

		Ext.Array.each(a_markers, i_self.addMarker, i_self);

		i_self.setCenter(o_center);

		i_self.fireEvent("mapready", i_self, i_map);
	},

	addMarker: function(o_config) {

		var i_self = this;
		var google = window.google;

		o_config = Ext.apply({
			map: i_self.getMap()
		}, o_config);

		if (!o_config.position) {
			o_config.position = new google.maps.LatLng(o_config.lat, o_config.lng);
		}
		var i_marker = new google.maps.Marker(o_config);

		Ext.Object.each(i_marker.listeners, function(s_name, f_handler) {
			google.maps.event.addListener(i_marker, s_name, f_handler);
		});

		var a_added = i_self.getAdded();
		a_added.push(i_marker);

		return i_marker;
	},

	removeMarker: function(i_marker) {

		var i_self = this;
		var a_added = i_self.getAdded();

		Ext.Array.remove(a_added, i_marker);

		i_marker.setMap(null);
	},

	lookupCode: function(addr, marker) {

		var i_self = this;
		var i_geocoder = i_self.getGeoCoder();
		var google = window.google;

		if (!i_geocoder) {
			i_geocoder = new google.maps.Geocoder();
			i_self.setGeoCoder(i_geocoder);
		}

		i_geocoder.geocode({
			address: addr
		}, Ext.Function.bind(i_self.onLookupComplete, i_self, [marker], true));
	},

	lookupAddr: function(addr, f_callback) {

		var i_self = this;

		f_callback = f_callback || function(o_data) {
			var i_element = i_self.getEl();
			if (i_element && i_element.dom) {
				if (i_self.getMap()) {
					var i_map = i_self.getMap();
					if (o_data[0]) {
						i_map.setCenter(o_data[0].geometry.location);

						var a_markers = i_self.getAdded();

						Ext.Array.each(a_markers, function(i_marker) {
							i_marker.setMap(null);
						});

						i_self.setAdded([]);

						i_self.addMarker({
							position: o_data[0].geometry.location
						});
					}
				}
				else {
					if (o_data[0]) {
						i_self.setStored(o_data[0].geometry.location);
					}
				}
			}
			else {
				if (o_data[0]) {
					i_self.setStored(o_data[0].geometry.location);
				}
			}
		};

		var i_geocoder = i_self.getGeoCoder();
		var google = window.google;

		if (!i_geocoder) {
			i_geocoder = new google.maps.Geocoder();
			i_self.setGeoCoder(i_geocoder);
		}

		i_geocoder.geocode({
			address: addr
		}, Ext.Function.bind(f_callback, i_self, [{}], true));
	},

	onLookupComplete: function(o_data, response, marker) {

		var i_self = this;

		if (response != "OK") {
			Ext.MessageBox.alert("Error", "An error occured: \"" + response + "\"");
			return;
		}
		var i_element = i_self.getEl();
		if (i_element.dom) {
			i_self.createMap(o_data[0].geometry.location, marker);
		}
		else {
			i_self.setStored(o_data[0].geometry.location);
		}
	},

	afterComponentLayout: function(w, h) {

		var i_self = this;

		i_self.callParent(arguments);
		i_self.redraw();
	},

	redraw: function() {

		var i_self = this;
		var google = window.google;
		var i_map = i_self.getMap();

		if (i_map) {
			google.maps.event.trigger(i_map, "resize");
		}
	}

});

Ext.define("IceCap.controller.Window", {
	extend: "Ext.app.ViewController",

	alias: "controller.icecap.view.window",

	onSendData: function(o_config, o_data) {

		var i_controller = this;
		var o_saved = Ext.clone(o_config);
		var i_view = i_controller.getView();
		var s_session = i_view.getSessionValue();

		var o_options = i_view.getOptions();

		o_data = Ext.apply(o_data, {
			i18nLearning: false
		});

		Ext.apply(o_config, {
			session: s_session
		});

		Ext.apply(o_config, o_options);

		if (!i_view.getWorking()) {
			i_view.setWorking(true);
			i_view.doTimer();
			IceCap.util.Handler.getData(o_config, o_data, function(o_inputData) {

				if (o_inputData.statusUpdate) {

					i_view.setWorking(false);
					i_view.updateMessage(o_inputData);
					if (o_inputData.status > -1) {
						i_view.doCreateFromData(o_inputData);
					}
					i_controller.onSendData(o_saved, o_data);
				}
				else {

					i_view.setLoading(false);
					i_view.cancelTimer();

					var f_callback = i_view.getResponseCallBack() || Ext.emptyFn;

					if (f_callback != Ext.emptyFn) {

						f_callback(o_inputData);
					}

					var o_plugin = o_inputData.plugin || Ext.apply({}, {
						require: []
					});

					var a_require = o_plugin.require || [];
					var s_run = o_plugin.run || "";

					i_controller.doRequire(a_require, function() {

						if (s_run) {
							eval(s_run);
						}

						if (o_inputData.close) {
							i_view.fireEvent("applicationClose", true);
						}
						else {

							i_view.setWorking(false);
							i_view.doCreateFromData(o_inputData);
						}
					});
				}
			});
		}
	},

	onWheel: function(i_event) {

		var i_controller = this;
		var i_view = i_controller.getView();

		var b_hasGrid = i_view.query("gridpanel").length > 0;
		var b_mappanel = i_view.query("icecap-gmappanel").length > 0;

		var n_delta = i_event.getWheelDelta();
		var s_event = "";

		if (n_delta > 0) {
			s_event = "ROLLDOWN";
		}
		else {
			s_event = "ROLLUP";
		}

		if (!b_hasGrid && !b_mappanel && !i_event.ctrlKey) {
			i_controller.doKeyEvent(s_event);
		}
	},

	onDblClick: function(i_event) {

		var i_controller = this;
		var i_view = i_controller.getView();
		var i_cursor = i_view.getCursor();

		var b_fireEvent = i_view.getEnterOnDblClick();

		if (b_fireEvent) {

			var i_body = i_view.body;
			var a_local = i_body.getOffsetsTo(window);

			var o_click = Ext.apply({
				x: i_event.pageX - a_local[0],
				y: i_event.pageY - a_local[1]
			});

			var o_position = IceCap.util.Handler.toColAndLine(o_click);

			var i_currentField = i_view.getCurrentField();

			if (i_currentField) {
				o_position = Ext.apply(o_position, {
					lin: i_currentField.lin,
					col: i_currentField.col
				});
				if (i_currentField.inputEl && i_currentField.getValue()) {
					o_position = IceCap.util.Handler.toColAndLine(o_click);
				}
			}
			else {
				i_cursor.moveCursor(o_position);
				i_cursor.show();
			}

			i_view.setCurrentPosition(o_position);
			i_controller.doKeyEvent("ENTER");
		}
	},

	onClick: function (i_event) {

		var i_controller = this;
		var i_view = i_controller.getView();
		var o_inputData = i_view.getInputData();
		var i_cursor = i_view.getCursor();
		var i_content = i_view.getContent();

		var i_activeComponent = Ext.ComponentManager.getActiveComponent();

		var i_body = i_view.body;
		var a_local = i_body.getOffsetsTo(window);

		var o_click = Ext.apply({
			x: i_event.pageX - a_local[0],
			y: i_event.pageY - a_local[1]
		});

		var o_position = IceCap.util.Handler.toColAndLine(o_click);

		if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {

			var i_currentField = i_view.getCurrentField();

			var a_metaFields = o_inputData.metaFields || [];

			if (i_currentField) {
				o_position = Ext.apply(o_position, {
					lin: i_currentField.lin,
					col: i_currentField.col
				});
				if (i_currentField.inputEl && i_currentField.getValue()) {
					o_position = IceCap.util.Handler.toColAndLine(o_click);
				}
			}
			else {

				var a_inputs = IceCap.util.Handler.getInputFields(i_view);

				var o_box = Ext.apply({
					x: IceCap.util.Handler.getX(o_position.col),
					y: IceCap.util.Handler.getY(o_position.lin),
					width: IceCap.util.Handler.getColSize(),
					height: 1
				});

				var b_intersect = false;

				Ext.Array.each(a_inputs, function (i_field) {

					var i_element = i_field.getEl();

					if (i_element) {

						var o_bound = i_element.dom.getBoundingClientRect();

						var o_rect = Ext.apply({}, {
							x: IceCap.util.Handler.getX(i_field.col),
							y: IceCap.util.Handler.getY(i_field.lin),
							width: o_bound.width,
							height: o_bound.height
						});

						if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {

							b_intersect = true;
							i_field.focus(false, 10);

							var n_start = o_position.col - i_field.col;
							var i_inputEl = i_field.inputEl;
							i_inputEl.dom.selectionStart = i_inputEl.dom.selectionEnd = n_start;

							return false;
						}
					}
				});

				if (!b_intersect) {
					i_cursor.moveCursor(o_position);

					i_cursor[a_metaFields.length === 0 ? "show" : "hide"]();
				}
			}
		}

		i_view.setCurrentPosition(o_position);
	},

	doArrowKeys: function(n_direction) {

		var i_controller = this;
		var i_view = i_controller.getView();
		var a_fields = IceCap.util.Handler.getInputFields(i_view);
		var n_tabIndex = i_view.getCurrentTabIndex();
		var n_lastTabIndex = i_view.getLastTabIndex();
		var n_part = n_direction ? 1 : -1;

		var i_lastFocus;

		Ext.Array.each(a_fields, function(i_field) {
			if (i_field.getTabIndex() === n_tabIndex) {
				i_lastFocus = i_field;
				return false;
			}
		});

		var b_found = false;

		if (i_lastFocus) {

			var n_lin = i_lastFocus.lin;
			var n_col = i_lastFocus.col;
			var n_next = n_lin + n_part;

			Ext.Array.each(a_fields, function(i_field) {
				if (i_field.lin === n_next && i_field.col === n_col) {
					b_found = true;
					n_tabIndex = i_field.getTabIndex();
					i_field.focus(false, 10);
					return false;
				}
			});
		}

		if (!b_found) {

			n_tabIndex = i_view.getCurrentTabIndex() + n_part;

			if (n_direction) {
				if (n_tabIndex > n_lastTabIndex) {
					n_tabIndex = 1;
				}
			}
			else {
				if (n_tabIndex < 1) {
					n_tabIndex = n_lastTabIndex;
				}
			}

			Ext.Array.each(a_fields, function(i_field) {
				if (i_field.getTabIndex() === n_tabIndex) {
					i_field.focus(false, 10);
					return false;
				}
			});
		}

		i_view.setCurrentTabIndex(n_tabIndex);
	},

	doTabKey: function(n_direction) {

		var i_controller = this;
		var i_view = i_controller.getView();
		var a_fields = IceCap.util.Handler.getInputFields(i_view);
		var n_tabIndex = i_view.getCurrentTabIndex();
		var n_lastTabIndex = i_view.getLastTabIndex();
		var n_part = n_direction ? 1 : -1;

		n_tabIndex = i_view.getCurrentTabIndex() + n_part;

		if (n_direction) {
			if (n_tabIndex > n_lastTabIndex) {
				n_tabIndex = 1;
			}
		}
		else {
			if (n_tabIndex < 1) {
				n_tabIndex = n_lastTabIndex;
			}
		}

		Ext.Array.each(a_fields, function(i_field) {
			if (i_field.getTabIndex() === n_tabIndex) {
				i_field.focus(false, 10);
				return false;
			}
		});

		i_view.setCurrentTabIndex(n_tabIndex);
	},

	doKeyEvent: function(s_value) {

		var i_controller = this;
		var i_view = i_controller.getView();

		var i_currentField = i_view.getCurrentField();
		var o_position = i_view.getCurrentPosition();

		var o_data = {
			key: s_value
		};

		var i_content = i_view.getContent();
		var i_form = i_content.getForm();
		var i_collectionField = i_form.getFields();
		var o_values = {};

		Ext.Array.each(i_collectionField.items, function(i_field) {
			if (i_field.isDirty()) {
				var value = i_field.getSubmitValue ? i_field.getSubmitValue() : i_field.getValue();
				o_values[i_field.itemId || i_field.initialConfig.id || i_field.name] = value;
			}
		});

		Ext.Object.each(o_values, function(s_key, value) {
			var s_id = "ses2.win." + s_key;
			o_data[s_id] = value;
		});

		if (i_currentField) {

			o_data = Ext.apply(o_data, {
				csrLin: i_currentField.lin,
				csrCol: i_currentField.col
			});

			if (i_currentField.inputEl && i_currentField.getValue()) {

				o_data = Ext.apply(o_data, {
					csrCol: o_position.col > 1 ? o_position.col : i_currentField.col
				});
			}
		}
		else {

			o_data = Ext.apply(o_data, {
				csrLin: o_position.lin,
				csrCol: o_position.col
			});
		}

		var f_callback = i_view.getRequestCallBack() || Ext.emptyFn;

		if (f_callback != Ext.emptyFn) {

			f_callback(o_data);
		}

		i_controller.onSendData({
			func: ""
		}, o_data);
	},

	doFKey: function(s_value) {

		var i_controller = this;

		i_controller.doKeyEvent(s_value);
	},

	doRequire: function(a_require, f_callback) {

		f_callback = f_callback || Ext.emptyFn;

		var a_require = a_require || [];

		if (a_require.length > 0) {

			var a_external = Ext.Array.filter(Ext.Array.map(a_require, function(s_value) {
				if (s_value.indexOf("/") > -1) {
					return s_value;
				}
			}), function(value) {
				return value;
			});

			var a_internal = Ext.Array.filter(Ext.Array.map(a_require, function(s_value) {
				if (s_value.indexOf("/") < 0) {
					return s_value;
				}
			}), function(value) {
				return value;
			});

			if (a_external.length > 0) {
				Ext.Loader.loadScriptsSync(a_external);
			}

			if (a_internal.length > 0) {
				Ext.syncRequire(a_internal);
			}
		}

		f_callback();
	}
});
Ext.define("IceCap.view.Window", {
	extend: "Ext.window.Window",

	layout: "fit",

	requires: [
		"IceCap.controller.Window"
	],

	config: {
		inputData: null,
		lastTabIndex: 1,
		currentTabIndex: 1,
		content: null,
		keyArea: null,
		working: false,
		needFocus: 1,
		currentPosition: {
			col: 1,
			lin: 1
		},
		statusBar: null,
		main: null,
		sessionValue: "",
		cursor: null,
		timer: null,
		theme: "",
		requestCallBack: Ext.emptyFn,
		responseCallBack: Ext.emptyFn,
		enterOnDblClick: false,
		marker: null,
		markerActive: false,
		options: {},
		typeMode: 1,
		edit: false
	},

	closable: false,

	modal: false,

	controller: "icecap.view.window",

	listeners: {
		afterrender: {
			fn: function(i_panel) {

				var i_self = i_panel;

				i_self.addKeyEvents();

				var i_content = i_self.getContent();

				if (i_content) {

					var o_inputData = i_self.getInputData();

					var a_fields = IceCap.util.Handler.getInputFields(i_content);
					var b_found = false;
					var b_error = false;

					Ext.Array.each(a_fields, function(i_field) {
						if (i_field.getTabIndex() === i_self.getNeedFocus()) {
							if (!b_error) {
								setTimeout(function() {
									i_field.focus(false, 10);
								}, 10);
							}
							b_found = true;

							return false;
						}
					});

					if (!b_found) {

						i_self.setCurrentPosition({
							col: 2,
							lin: 1
						});

						if (!b_error) {
							setTimeout(function() {
								i_self.focus(true, 10);
							}, 10);
						}
					}
				}
			},
			buffer: 100
		},
		dblclick: {
			fn: "onDblClick",
			element: "body"
		},
		click: {
			fn: "onClick",
			element: "body"
		},
		wheel: {
			fn: "onWheel",
			element: "body"
		},
		fieldoption: {
			fn: function(a_config) {

				var i_self = this;
				var i_controller = i_self.getController();

				var o_data = {};

				Ext.apply(o_data, {
					key: "ENTER"
				});

				Ext.Array.each(a_config, function(o_config) {

					var s_field = o_config.field;

					o_data[s_field] = o_config.option;

					Ext.apply(o_data, {
						csrCol: o_config.col,
						csrLin: o_config.lin
					});
				});

				i_self.setCurrentPosition({
					col: o_data.csrCol,
					lin: o_data.csrLin
				});

				i_controller.onSendData({
					func: ""
				}, o_data);
			}
		},
		key: {
			fn: function(s_value) {

				var i_self = this;
				var i_controller = i_self.getController();

				i_controller.doKeyEvent(s_value);
			}
		}

	},

	onKeyDown: Ext.emptyFn, // THIS IS NEEDED TO OVERRIDE Ext.util.Floating

	initComponent: function() {

		var i_self = this;

		var o_params = Ext.Object.fromQueryString(window.location.search);

		Ext.Object.each(o_params, function(s_key, value) {
			o_params[s_key] = Ext.decode(value, true) || value;
		});

		var o_options = Ext.apply(i_self.options, o_params.options || {});

		Ext.apply(i_self, {
			theme: i_self.theme || o_params.theme || ""
		});

		i_self.callParent(arguments);

		i_self.setTypeMode(IceCap.util.Handler.typeMode.INSERT);

		i_self.add(i_self.createLayout());

		i_self.enableBubble([
			"onAddWebContainer",
			"toWindow",
			"applicationClose"
		]);

		i_self.recreate();
	},

	createStatusBar: function() {

		var i_self = this;

		var i_statusbar = Ext.widget("toolbar", {
			dock: "bottom",
			cls: "icecap-statusbar",
			hidden: false,
			ui: "statusbar",
			height: 30,
			layout: {
				type: "hbox",
				align: "top"
			},
			items: [
				{
					xtype: "label",
					itemId: "icecap-message",
					listeners: {
						afterrender: {
							fn: function(i_label) {

								var i_tpl = Ext.create("Ext.XTemplate",
									"<ul style=\"list-style: none;",
												"margin:10px;",
												"padding:0;",
									"\">",
										"<tpl for=\".\">",
											"<li>{text}</li>",
										"</tpl>",
									"</ul>"
								);

								Ext.create("Ext.tip.ToolTip", {
									target: i_label.getEl(),
									html: "",
									anchor: true,
									defealtAlign: "b50-t50",
									listeners: {
										beforeshow: {
											fn: function (i_tip) {

												var b_hasError = i_label.hasCls("icecap-statusbar-error");

												var o_inputData = i_self.getInputData();

												var a_messages = Ext.Array.from(o_inputData.message);

												if (b_hasError && a_messages.length > 0) {
													var s_value = i_tpl.apply(a_messages);
													i_tip.update(s_value);
												}
												else {
													return b_hasError;
												}
											}
										}
									}
								});
							}
						},
						click: {
							element: "el",
							fn: function (i_event, i_element) {

								var o_input = {
									col: 3,
									lin: 24
								};

								i_self.setCurrentPosition(o_input);

								var i_cursor = i_self.getCursor();
								i_cursor.moveCursor(o_input);

								i_self.doKeyEvent("F1");
							}
						},
					}
				},
				"->",
				{
					xtype: "component",
					cls: "pf-gearwheel",
					height: 24,
					hidden: true,
					autoEl: {
						tab: "span"
					},
					style: {
						"cursor": "pointer"
					},
					listeners: {
						click: {
							element: "el",
							fn: function() {

								var i_element = this;
								var b_edit = i_self.getEdit();

								b_edit = !b_edit;

								if (b_edit) {
									i_element.addCls("x-base-color");
								}
								else {
									i_element.removeCls("x-base-color");
								}

								i_self.setEdit(b_edit);
							}
						}
					}
				},
				{
					xtype: "label",
					itemId: "icecap-position"
				},
				{
					xtype: "label",
					text: " INS",
					itemId: "icecap-typemode"
				}
			],
			setText: function (s_text) {

				var i_toolbar = this;

				var i_message = i_toolbar.getComponent("icecap-message");

				if (i_message) {
					i_message.setText(s_text);
				}
			}
		});

		return i_statusbar;
	},

	createLayout: function() {

		var i_self = this;
		var o_inputData = i_self.getInputData();

		return i_self.createContent();
	},

	createContent: function() {

		var i_self = this;

		var i_panel = Ext.widget("panel", {
			layout: {
				type: "vbox",
				align: "stretch"
			},
			cls: ["icecap-window", i_self.getTheme()].join("-"),
			border: false,
			focusable: true,
			tabIndex: -1,
			items: i_self.createItems()
		});

		i_self.setMain(i_panel);

		return i_panel;
	},

	createItems: function() {

		var i_self = this;

		var o_inputData = i_self.getInputData();

		var a_items = [];

		var i_keyArea = Ext.widget("panel", {
			layout: {
				type: "column"
			},
			border: false,
			focusable: false,
			minHeight: 50,
			height: null,
			defaults: {
				margin: "0 5 5 0"
			},
			cls: ["icecap-panel", i_self.getTheme()].join("-"),
			ui: "icecap-keyarea"
		});

		var i_center = Ext.widget("form", {
			border: false,
			layout: "absolute",
			flex: 1,
			ui: ["icecap", i_self.getTheme()].filter(Boolean).join("-")
		});

		a_items.push(i_center);
		a_items.push(i_keyArea);

		i_self.setContent(i_center);

		var i_statusbar = i_self.createStatusBar();

		i_self.addDocked([
			i_statusbar
		]);


		i_self.setStatusBar(i_statusbar);
		i_self.setKeyArea(i_keyArea);

		i_self.updateMessage(o_inputData);

		return a_items;
	},

	createFields: function () {

		var i_self = this;
		var o_inputData = i_self.getInputData();

		var a_fields = [];

		var n_tabIndex = 1;
		var n_focus = o_inputData.focus;

		var n_inputWidth = o_inputData.width || 80;

		var a_sliced = Ext.Array.from(o_inputData.input || []);

		Ext.Array.each(a_sliced, function (o_config, n_index) {

			var n_width = (IceCap.util.Handler.getWidth(o_config.len) + (IceCap.util.Handler.getWidth() / 2));

			var o_meta = o_config.metaData || {};

			var o_field = {
				inputType: "text",
				xtype: "icecap-input",
				ui: "icecap-field"
			};

			var s_type = o_field.xtype || "icecap-input";
			var n_x = IceCap.util.Handler.getX(o_config.col) - 3;
			var n_y = IceCap.util.Handler.getY(o_config.lin);
			var b_password = o_config.atr == "27";

			if (o_config.len > n_inputWidth) {
				var n_temp = n_inputWidth - o_config.col;
				n_width = (IceCap.util.Handler.getWidth(n_temp) + (IceCap.util.Handler.getWidth() / 2));
			}


			if (o_config.hasOwnProperty("colsize") && o_config.hasOwnProperty("rows")) {

				var s_data = o_config.dta || "";

				o_field.xtype = s_type = "textarea";
				o_field.height = IceCap.util.Handler.getHeight() * o_config.rows;
				o_field.preventScrollbars = true;

				var a_split = s_data.split("\n");

				var s_result = "";

				var n_split = a_split.length;

				Ext.Array.each(a_split, function (s_part, n_index) {

					var regex = new RegExp(".{" + o_config.colsize + "}", "g");

					var a_match = s_part.match(regex);

					if (a_match) {
						s_result += s_part;
					}
					else {
						if (n_index != n_split - 1) {
							s_result += s_part + "\n";
						}
						else {
							s_result += s_part;
						}
					}
				});

				o_config.dta = s_result;


				o_field.getSubmitValue = function () {

					var i_field = this;

					var s_value = i_field.stripReturns(i_field.getRawValue());

					var regex = new RegExp(".{1," + o_config.colsize + "}", "g");

					var a_split = s_value.match(regex) || [];

					return a_split.join("\n");
				};

			}

			var o_listeners = Ext.apply({}, o_meta.listeners);
			delete o_meta.listeners;

			var a_field = ["icecap-field", i_self.getTheme()];

			var a_pass = [b_password ? "iceCap-input-password" : "iceCap-input-" + (o_config.atr || 20)];

			a_pass.push(i_self.getTheme());

			var a_cls = [a_field.filter(Boolean).join("-"), a_pass.filter(Boolean).join("-")];

			var s_cls = a_cls.join(" ");

			if (isNaN(n_x)) {
				n_x = IceCap.util.Handler.getColSize();
			}

			if (isNaN(n_y)) {
				n_y = IceCap.util.Handler.getLineHeight();
			}

			var s_ui = b_password ? "icecap-password-field" : "icecap-field";

			if (!o_meta.xtype) {
				Ext.apply(o_field, i_self.applyFFW(o_config));
			}

			var i_field;

			var s_name = IceCap.util.Handler.getRandomName();

			if (o_field.readOnly) {

				o_field.xtype = s_type = "displayfield";
				s_ui = "icecap-display";
				s_cls = (["iceCap-output-" + (o_config.atr || 20), i_self.getTheme()].filter(Boolean).join("-"));

				o_field = {
					autoEl: {
						tag: "span"
					},
					html: o_config.dta || "",
					x: n_x,
					y: n_y,
					name: s_name,
					cls: ["x-form-display-field-icecap-display", s_cls].join(" "),
					style: {
						"white-space": "pre"
					},
					listeners: {
						afterrender: {
							fn: function (i_field) {
								i_field.el.dom.setAttribute("draggable", false);
							}
						}
					}
				};

				if (o_config.atr == "27") {
					o_field.hidden = true;
				}

				if (o_config.atr == "22") {

					Ext.apply(o_field.style, {
						"font-size": (IceCap.util.Handler.getFontSize() - 1) + "px",
						"font-weight": "bold;",
						"letter-spacing": (IceCap.util.Handler.getColSize() - IceCap.util.Handler.getBoldColSize()) + "px",
						"word-spacing": "0.02em;"
					});
				}

				i_field = Ext.widget("component", o_field);

			}
			else {

				Ext.Object.merge(o_field, {
					width: n_width,
					enforceMaxLength: true,
					maxLength: o_config.len,
					minWidth: IceCap.util.Handler.getDefaultWidth(),
					tabIndex: !o_field.readOnly ? n_tabIndex : -1,
					focusable: !o_field.readOnly,
					lin: o_config.lin,
					col: o_config.col,
					emuId: o_config.id,
					value: o_config.dta || "",
					itemId: o_config.id,
					name: s_name,
					inputAttrTpl: "spellcheck=false autocomplete=\"new-password\" name=\"" + s_name + "\"",
					x: n_x,
					y: n_y,
					cls: s_cls,
					enableKeyEvents: true,
					selectOnFocus: false,
					ui: s_ui,
					listeners: {
						afterrender: {
							fn: function (i_field) {

								if (i_field.inputEl && !i_field.metaField) {

									if (i_field.xtype == "textarea") {
										i_field.inputEl.dom.setAttribute("rows", o_config.rows);
									}

									if (i_field.getTabIndex() === i_self.getNeedFocus()) {

										i_field.focus(false, 10, function () {
											var o_inputData = i_self.getInputData();

											var s_value = i_field.getValue();
											var n_col = i_field.col;
											var n_diff = 0;

											if (n_col < o_inputData.csrCol) {
												n_diff = o_inputData.csrCol - n_col;
												i_field.inputEl.el.dom.selectionEnd = i_field.inputEl.el.dom.selectionStart = i_field.inputEl.el.dom.selectionStart + n_diff;
											}

											var o_position = {
												col: o_inputData.csrCol,
												lin: o_inputData.csrLin
											};

											i_self.setCurrentPosition(o_position);

											var i_cursor = i_self.getCursor();
											i_cursor.moveCursor(o_position);
											i_cursor.hide();
										});
									}
								}
							}
						},
						change: {
							fn: function (i_field, value) {

								var s_direction = i_field.inputEl.el.dom.selectionDirection;

								var n_curpos = s_direction == "forward" ? i_field.inputEl.el.dom.selectionEnd : i_field.inputEl.el.dom.selectionStart;

								value = value || "";

								if (value.length == i_field.maxLength && n_curpos == i_field.maxLength) {
									i_self.doNavigationKey(1, true);
								}
							}
						},
						focus: {
							fn: function (i_field) {

								var n_tabIndex = i_field.getTabIndex();
								i_self.setCurrentTabIndex(n_tabIndex);

								var o_position = {
									col: i_field.col,
									lin: i_field.lin
								};
								i_self.setCurrentPosition(o_position);

								var i_cursor = i_self.getCursor();
								i_cursor.moveCursor(o_position);
								i_cursor.hide();
							}
						},
						keyup: {
							fn: function (i_field, i_event) {

								if (i_field.xtype === "icecap-input") {

									var value = i_field.getValue();

									var s_direction = i_field.inputEl.el.dom.selectionDirection;

									var n_start = s_direction == "forward" ? i_field.inputEl.el.dom.selectionEnd : i_field.inputEl.el.dom.selectionStart;
									var n_add = value.length * IceCap.util.Handler.getWidth();

									if (n_start != value.length) {
										n_add = n_start * IceCap.util.Handler.getWidth();
									}

									var o_input = Ext.apply({
										x: i_field.getLocalX() + n_add,
										y: i_field.getLocalY()
									});

									var o_position = IceCap.util.Handler.toColAndLine(o_input);
									i_self.setCurrentPosition(o_position);

									var i_cursor = i_self.getCursor();
									i_cursor.moveCursor(o_position);
								}
							}
						},
						keydown: {
							fn: function (i_field, i_event) {

								var i_regext = new RegExp("^\\w{1}$");

								var value = i_field.getValue();

								if (i_event.ctrlKey) {

									var o_input = {};
									var o_position = {};
									var o_box = {};
									var i_main = i_self.getMain();
									var i_cursor = i_self.getCursor();
									var a_inputs = IceCap.util.Handler.getInputFields(i_self);
									var b_intersect = false;
									var n_selection = 0;

									var i_inputEl = i_field.inputEl;

									if (i_event.keyCode == Ext.event.Event.DOWN ||
										i_event.keyCode == Ext.event.Event.UP) {

										n_selection = i_inputEl.dom.selectionEnd;

										i_event.stopEvent();

										o_position = {
											col: i_field.col + n_selection,
											lin: i_field.lin
										};

										if (i_event.keyCode == Ext.event.Event.DOWN) {
											o_position.lin++;
										}
										else {
											o_position.lin--;
										}

										i_self.setCurrentPosition(o_position);

										i_cursor.moveCursor(o_position);

										o_input = {
											x: IceCap.util.Handler.getX(o_position.col),
											y: IceCap.util.Handler.getY(o_position.lin)
										};

										Ext.apply(o_box, {
											width: i_cursor.getWidth(),
											height: i_cursor.getHeight()
										}, o_input);

										Ext.Array.each(a_inputs, function (i_field) {

											var o_bound = i_field.el.dom.getBoundingClientRect();

											var o_rect = Ext.apply({}, {
												x: i_field.getLocalX(),
												y: i_field.getLocalY(),
												width: o_bound.width,
												height: o_bound.height
											});

											if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
												b_intersect = true;
												i_field.focus(false, 10);
												return false;
											}
										});

										if (!b_intersect) {

											i_field.blur();
											i_cursor.show();

											i_main.focus(true, 10);
										}
									}
									if (i_event.keyCode == Ext.event.Event.LEFT ||
										i_event.keyCode == Ext.event.Event.RIGHT) {

										n_selection = i_event.keyCode == Ext.event.Event.LEFT ? i_inputEl.dom.selectionStart : i_inputEl.dom.selectionEnd;

										i_event.stopEvent();

										if (n_selection === 0 && i_event.keyCode === Ext.event.Event.LEFT) {

											o_position = {
												col: i_field.col,
												lin: i_field.lin
											};

											o_position.col--;

											o_input = {
												x: IceCap.util.Handler.getX(o_position.col),
												y: IceCap.util.Handler.getY(o_position.lin)
											};

											i_self.setCurrentPosition(o_position);

											i_cursor.moveCursor(o_position);

											Ext.apply(o_box, {
												width: i_cursor.getWidth(),
												height: i_cursor.getHeight()
											}, o_input);


											Ext.Array.each(a_inputs, function (i_field) {

												var o_bound = i_field.el.dom.getBoundingClientRect();

												var o_rect = Ext.apply({}, {
													x: IceCap.util.Handler.getX(i_field.col),
													y: IceCap.util.Handler.getY(i_field.lin),
													width: o_bound.width,
													height: o_bound.height
												});

												if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
													b_intersect = true;
													i_field.focus(false, 10);
													return false;
												}
											});

											if (!b_intersect) {

												i_field.blur();
												i_cursor.show();

												i_main.focus(true, 10);
											}
										}
										else if (n_selection == value.length && i_event.keyCode == Ext.event.Event.RIGHT) {

											o_position = {
												col: i_field.col + i_field.maxLength,
												lin: i_field.lin
											};

											if (o_position.col > o_inputData.width) {
												o_position.col = o_inputData.width;
											}

											o_position.col++;

											o_input = {
												x: IceCap.util.Handler.getX(o_position.col),
												y: IceCap.util.Handler.getY(o_position.lin)
											};


											i_self.setCurrentPosition(o_position);
											i_cursor.moveCursor(o_position);

											Ext.apply(o_box, {
												width: i_cursor.getWidth(),
												height: i_cursor.getHeight()
											}, o_input);

											Ext.Array.each(a_inputs, function (i_field) {

												var o_bound = i_field.el.dom.getBoundingClientRect();

												var o_rect = Ext.apply({}, {
													x: IceCap.util.Handler.getX(i_field.col),
													y: IceCap.util.Handler.getY(i_field.lin),
													width: o_bound.width,
													height: o_bound.height
												});

												if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
													b_intersect = true;
													i_field.focus(false, 10);
													return false;
												}
											});

											if (!b_intersect) {

												i_field.blur();
												i_cursor.show();

												i_main.focus(true, 10);
											}
										}
									}
								}
								else {

									if (i_field.xtype == "textarea") {

										if (i_event.keyCode == Ext.event.Event.UP) {

											var s_value = i_field.stripReturns(i_field.getRawValue());

											var regex = new RegExp("^.*\n$|.{1," + o_config.colsize + "}", "gm");

											var a_lines = s_value.match(regex) || [];
											var a_newLines = s_value.split("\n");

											var n_start = i_field.inputEl.dom.selectionStart;

											var n_row = 1;
											var n_char = 0;
											var b_last = i_field.inputEl.dom.selectionStart == i_field.inputEl.dom.value.length;

											Ext.Array.each(a_lines, function (s_part, n_index) {

												n_char += s_part.length;

												if (n_char <= n_start) {
													n_row++;
												}
												else {
													return false;
												}
											});

											if (n_row > 1) {

												i_event.stopEvent();

												n_char = 0;
												var n_left = 0;
												var n_current = 0;
												var n_nextLine = 0;

												n_start = n_start - (a_newLines.length - 1);

												Ext.Array.each(a_lines, function (s_part, n_index) {

													n_char += s_part.length;

													var n_count = 0;

													n_left = 0;

													while (n_count < s_part.length) {
														n_count++;
														if (n_current < n_start) {
															n_current++;
															n_left++;
														}
													}

													if (n_char < n_start) {
														n_row++;
													}
													else {
														n_nextLine = n_index - 1;
														return false;
													}
												});

												if (n_nextLine == -1) {
													n_nextLine = 0;
												}

												var n_newPos = 0;

												Ext.Array.each(a_lines, function (s_part, n_index) {

													if (n_index < n_nextLine) {
														n_newPos += s_part.length;
													}
													else {
														n_newPos += n_left;
														return false;
													}
												});

												i_event.stopEvent();
												i_field.inputEl.dom.setSelectionRange(n_newPos, n_newPos);
											}
										}

										if (i_event.keyCode == Ext.event.Event.DOWN) {

											var s_value = i_field.stripReturns(i_field.getRawValue());
											var n_length = s_value.length;

											var regex = new RegExp("^.*\n$|.{1," + o_config.colsize + "}", "g");
											var n_pos = i_field.inputEl.dom.selectionStart;

											var a_lines = s_value.match(regex) || [];
											var a_newLines = s_value.split("\n");

											if (a_lines.length < o_config.rows && a_newLines.length < o_config.rows) {

												i_event.stopEvent();

												s_value = s_value + "\n";

												i_field.setValue(s_value);

												i_field.inputEl.dom.setSelectionRange(s_value.length, s_value.length);
											}
											else {
												var n_row = 1;
												var n_char = 0;
												var n_left = 0;
												var n_current = 0;
												var n_nextLine = 0;

												Ext.Array.each(a_lines, function (s_part, n_index) {

													n_char += s_part.length;

													var n_count = 0;

													n_left = 0;

													while (n_count < s_part.length) {
														n_count++;
														if (n_current < n_pos) {
															n_current++;
															n_left++;
														}
													}

													if (n_char <= n_pos) {
														n_row++;
													}
													else {
														n_nextLine = n_index + 1;
														return false;
													}
												});

												if (n_nextLine < a_lines.length || n_nextLine < a_newLines.length) {

													var n_newPos = 0;

													Ext.Array.each(a_lines, function (s_part, n_index) {

														if (n_index < n_nextLine) {
															n_newPos += s_part.length;
														}
														else {
															n_newPos += n_left + (a_newLines.length - 1);
															return false;
														}
													});

													if (n_row < o_config.rows) {
														i_event.stopEvent();
														i_field.inputEl.dom.setSelectionRange(n_newPos, n_newPos);
													}
												}
											}

										}
									}
									else if (i_field.xtype == "icecap-input") {

										var n_typeMode = i_self.getTypeMode();

										if (n_typeMode == IceCap.util.Handler.typeMode.OVERWRITE) {

											var s_direction = i_field.inputEl.el.dom.selectionDirection;

											var n_curpos = s_direction == "forward" ? i_field.inputEl.el.dom.selectionEnd : i_field.inputEl.el.dom.selectionStart;

											var s_key = String.fromCharCode(i_event.keyCode);

											if (n_curpos < value.length && i_regext.test(s_key)) {

												var a_values = value.split("");
												a_values[n_curpos] = i_event.browserEvent.key;
												value = a_values.join("");
												i_field.setValue(value);
												i_field.inputEl.el.dom.selectionEnd = i_field.inputEl.el.dom.selectionStart = n_curpos + 1;
												i_event.stopEvent();
											}
										}
									}
								}
							}
						}
					}
				}, o_meta);

				var o_clone = Ext.clone(o_field);

				if (o_meta.xtype) {

					o_clone.metaField = true;

					o_clone.xtype = s_type = o_meta.xtype;

					delete o_clone.cls;
					delete o_clone.fieldStyle;
					delete o_clone.inputType;
					delete o_clone.ui;
				}

				if (o_config.type == "grid") {

					s_type = "iceCapGrid";

					Ext.apply(o_clone, {
						xtype: s_type,
						gridConfig: o_config.grid,
						width: IceCap.util.Handler.getWidth(n_inputWidth)
					});

					delete o_clone.cls;
					delete o_clone.fieldStyle;
					delete o_clone.inputType;
					delete o_clone.listeners;
					delete o_clone.grid;

					Ext.apply(o_clone, {
						listeners: {
							fieldoption: {
								fn: function (a_config) {
									i_self.fireEvent("fieldoption", a_config);
								}
							},
							key: {
								fn: function (s_key) {
									i_self.fireEvent("key", s_key);
								}
							}
						}
					});
				}

				i_field = Ext.widget(s_type, o_clone);

				var o_on = {};

				Ext.Object.each(o_listeners, function (s_key, value) {

					if (Ext.isFunction(value)) {
						o_on[s_key] = Ext.apply({}, {
							fn: value,
							scope: i_self
						});
					}
					else if (Ext.isObject(value)) {
						value.scope = i_self;
						o_on[s_key] = value;
					}
				});

				i_field.on(o_on);
			}

			if (!i_field.readOnly) {
				n_tabIndex++;
			}

			if (o_config.atr == 25) {

				if (o_field.readOnly) {
					i_field.addCls("icecap-invalid");
				}
				else {
					i_field.markInvalid(true);
				}
			}

			a_fields.push(i_field);
		});

		n_tabIndex = n_tabIndex - 1;
		i_self.setLastTabIndex(n_tabIndex);
		i_self.setCurrentTabIndex(o_inputData.focus);

		i_self.setNeedFocus(n_focus);

		return a_fields;
	},

	createLabels: function() {

		var i_self = this;
		var o_inputData = i_self.getInputData();

		var i_cssRule = IceCap.util.Handler.getCssRule();
		var o_style = i_cssRule.style;

		var a_fields = [];

		if (!i_self.getEdit()) {


			var a_lines = [];
			var a_temp = [];

			Ext.Array.each(o_inputData.output, function (o_config) {

				var o_line = Ext.Array.findBy(a_lines, function (o_line) {
					return o_line.lin == o_config.lin;
				});

				if (o_line) {
					o_line.items.push(o_config);
				}
				else {
					o_line = {
						items: [o_config],
						lin: o_config.lin,
						col: o_config.col
					};

					a_lines.push(o_line);
				}
			});

			Ext.Array.each(a_lines, function (o_line) {

				var a_items = [];

				Ext.Array.each(o_line.items, function (o_item) {

					var o_atr = Ext.Array.findBy(a_items, function (o_atr) {
						return (o_atr.atr || "") == (o_item.atr || "");
					});

					if (!o_atr) {
						o_atr = {
							lin: o_item.lin,
							items: [o_item],
							atr: o_item.atr || ""
						};

						a_items.push(o_atr);
					}
					else {
						o_atr.items.push(o_item);
					}
				});

				o_line.atr = a_items;
			});

			Ext.Array.each(a_lines, function (o_line) {

				Ext.Array.each(o_line.atr, function (o_atr) {

					var n_col = 0;
					var n_current = 0;
					var s_value = "";

					var o_field = {
						value: ""
					};

					Ext.Array.each(o_atr.items, function (o_config) {

						var s_data = o_config.dta || o_config.label || o_config.text || "";

						if (o_config.off) {
							s_data = Ext.String.leftPad(s_data, s_data.length + o_config.off);
						}

						if (n_col === 0) {

							n_col = o_config.col;
							n_current = n_col + s_data.length;
							s_value = s_data;
						}
						else {

							var n_diff = o_config.col - n_current;

							if (n_diff > 0) {
								s_data = Ext.String.leftPad(s_data, s_data.length + n_diff);
							}

							n_current = n_current + s_data.length;

							s_value = s_value + s_data;
						}
					});

					Ext.apply(o_field, {
						col: n_col,
						lin: o_line.lin,
						value: s_value,
						atr: o_atr.atr
					});

					a_temp.push(o_field);
				});
			});

			Ext.Array.each(a_temp, function (o_config) {

				var s_value = o_config.value;

				if (s_value) {

					var n_x = IceCap.util.Handler.getX(o_config.col);
					var n_y = IceCap.util.Handler.getY(o_config.lin);

					var s_cls = (["iceCap-output-" + (o_config.atr || 20), i_self.getTheme()].filter(Boolean).join("-"));

					var o_field = {
						autoEl: {
							tag: "span"
						},
						html: s_value,
						x: n_x,
						y: n_y,
						cls: ["x-form-display-field-icecap-display", s_cls].join(" "),
						style: {
							"white-space": "pre"
						},
						listeners: {
							afterrender: {
								fn: function (i_field) {
									i_field.el.dom.setAttribute("draggable", false);
								}
							}
						}
					};


					if (o_config.atr == "27") {
						o_field.hidden = true;
					}

					if (o_config.atr == "22") {

						Ext.apply(o_field.style, {
							"font-size": (IceCap.util.Handler.getFontSize() - 1) + "px",
							"font-weight": "bold;",
							"letter-spacing": (IceCap.util.Handler.getColSize() - IceCap.util.Handler.getBoldColSize()) + "px",
							"word-spacing": "0.02em;"
						});
					}

					var i_field = Ext.widget("component", o_field);
					a_fields.push(i_field);
				}
			});
		}
		else {

			var editor = new Ext.Editor({
				updateEl: true,
				alignment: "l-l",
				autoSize: {
					width: "boundEl"
				},
				field: {
					xtype: "textfield",
					ui: "icecap-field"
				}
			});

			Ext.Array.each(o_inputData.output, function (o_config) {

				var s_value = o_config.dta || "";

				if (s_value) {

					var n_x = IceCap.util.Handler.getX(o_config.col);
					var n_y = IceCap.util.Handler.getY(o_config.lin);

					var s_cls = (["iceCap-output-" + (o_config.atr || 20), i_self.getTheme()].filter(Boolean).join("-"));

					var o_field = {
						autoEl: {
							tag: "span"
						},
						html: s_value,
						x: n_x,
						y: n_y,
						cls: ["x-form-display-field-icecap-display", s_cls].join(" "),
						style: {
							"white-space": "pre"
						},
						listeners: {
							mouseover: {
								element: "el",
								fn: function() {

									var i_element = this;
									i_element.addCls("x-base-background-color");
								}
							},
							mouseout: {
								element: "el",
								fn: function() {

									var i_element = this;
									i_element.removeCls("x-base-background-color");
								}
							},
							afterrender: {
								fn: function (i_field) {
									i_field.el.dom.setAttribute("draggable", false);

									var i_tpl = Ext.create("Ext.XTemplate",
										"<div style=\"width: 300px; overflow:hidden; white-space:nowrap;\">",
											"<div>Lin: {lin}</div>",
											"<div>Col: {col}</div>",
											"<div>Color: {color}</div>",
											"<div style=\"overflow:hidden; white-space: nowrap; text-overflow:ellipsis;\">Font: {font}</div>",
										"</div>"
									);

									Ext.create("Ext.tip.ToolTip", {
										target: i_field.el,
										html: "",
										anchor: true,
										defealtAlign: "b0-t0",
										listeners: {
											beforeshow: {
												fn: function (i_tip) {

													var o_data = {
														lin: o_config.lin,
														col: o_config.col,
														color: o_style.color,
														font: [
															o_style.fontSize,
															o_style.fontFamily
														].join(" ")
													};

													var s_value = i_tpl.apply(o_data);
													i_tip.update(s_value);
												}
											}
										}
									});
								}
							}
						}
					};


					if (o_config.atr == "27") {
						o_field.hidden = true;
					}

					if (o_config.atr == "22") {

						Ext.apply(o_field.style, {
							"font-size": (IceCap.util.Handler.getFontSize() - 1) + "px",
							"font-weight": "bold;",
							"letter-spacing": (IceCap.util.Handler.getColSize() - IceCap.util.Handler.getBoldColSize()) + "px",
							"word-spacing": "0.02em;"
						});
					}

					var i_field = Ext.widget("component", o_field);
					a_fields.push(i_field);

					i_field.on({
						afterrender: {
							fn: function(i_field) {
								i_field.el.on({
									click: {
										fn: function() {
											editor.startEdit(i_field.getEl());
											editor.field.focus(50, false);
										}
									}
								});
							}
						}
					});
				}
			});
		}

		return a_fields;
	},

	createKeys: function() {

		var i_self = this;
		var o_inputData = i_self.getInputData();
		var a_disabledKey = o_inputData.disabledKeys || [];
		var a_buttons = [];

		var i_template = Ext.create("Ext.XTemplate",
			"{id}={text}"
		);

		Ext.Array.each(o_inputData.keys, function(o_config) {

			var s_template = i_template.apply(o_config);

			var o_found = Ext.Array.findBy(a_disabledKey, function(o_disabled) {
				return o_config.id == o_disabled.id;
			});

			o_found = o_found || {
				showKey: 1
			};

			var b_hidden = Number(o_found.showKey) < 1  || false;

			var i_button = Ext.widget("button", {
				text: s_template,
				key: o_config.id,
				focusable: false,
				hidden: b_hidden,
				handler: function(i_button) {
					i_self.doKeyEvent(i_button.key);
				}
			});

			a_buttons.push(i_button);
		});

		return a_buttons;
	},

	createMetaFields: function() {

		var i_self = this;
		var o_inputData = i_self.getInputData();

		var a_fields = [];
		var n_tabIndex = i_self.getLastTabIndex() || 1;

		var a_sliced = Ext.Array.slice(o_inputData.metaFields || []);

		Ext.Array.each(a_sliced, function(o_config) {

			var n_x = o_config.x;
			var n_y = o_config.y;

			if (!o_config.x) {
				n_x = Math.ceil((IceCap.util.Handler.getX(o_config.col) + (IceCap.util.Handler.getColSize() / 2)));
			}

			if (!o_config.y) {
				n_y = IceCap.util.Handler.getY(o_config.lin);
			}

			if (isNaN(n_x)) {
				n_x = IceCap.util.Handler.getColSize();
			}

			if (isNaN(n_y)) {
				n_y = IceCap.util.Handler.getLineHeight();
			}

			var o_listeners = o_config.listeners || {};

			Ext.apply(o_config, {
				tabIndex: n_tabIndex,
				keys: Ext.Array.slice(o_inputData.keys),
				theme: i_self.getTheme(),
				x: n_x,
				y: n_y,
				listeners: {
					fieldoption: {
						fn: function(a_config) {
							i_self.fireEvent("fieldoption", a_config);
						}
					},
					key: {
						fn: function(o_config) {
							i_self.fireEvent("key", o_config);
						}
					}
				}
			});

			n_tabIndex++;

			o_config.xtype = o_config.xtype || o_config.type || "icecap-input";

			o_config.name = o_config.id;

			delete o_config.id;

			var i_field = Ext.widget(o_config.xtype, o_config);

			var o_on = {};

			Ext.Object.each(o_listeners, function(s_key, value) {

				if (Ext.isFunction(value)) {
					o_on[s_key] = Ext.apply({}, {
						fn: value,
						scope: i_self
					});
				}
				else if (Ext.isObject(value)) {
					value.scope = i_self;
					o_on[s_key] = value;
				}
			});

			i_field.on(o_on);

			a_fields.push(i_field);
		});

		i_self.setLastTabIndex(n_tabIndex);

		return a_fields;
	},

	doCreateFromData: function(o_inputData) {

		var i_self = this;
		i_self.fireEvent("toWindow", i_self, o_inputData);
	},

	recreate: function() {

		var i_self = this;

		var i_content = i_self.getContent();
		var i_keyArea = i_self.getKeyArea();
		var i_main = i_self.getMain();
		var o_inputData = i_self.getInputData();

		var b_fixed = o_inputData.hasOwnProperty("fixed") ? o_inputData.fixed : true;

		IceCap.util.Handler.setFixed(b_fixed);

		i_self.suspendLayouts();

		if (o_inputData.title) {
			i_self.setTitle(o_inputData.title);
		}

		var a_created = i_self.createFields();
		a_created = a_created.concat(i_self.createLabels());
		a_created = a_created.concat(i_self.createMetaFields());
		a_created.push(i_self.createCursor());
		a_created.push(i_self.createMarker());

		i_content.removeAll(true);
		i_keyArea.removeAll(true);

		i_content.add(a_created);

		var a_keys = i_self.createKeys();
		i_keyArea.add(a_keys);

		i_keyArea[a_keys.length === 0 ? "hide" : "show"]();

		var i_marker = i_self.getMarker();
		i_marker.setInUse(i_self.getMarkerActive());

		i_self.updateMessage(o_inputData);


		IceCap.util.Handler.setFixed(true);

		i_self.resumeLayouts(true);

		if (i_content) {
			a_fields = IceCap.util.Handler.getInputFields(i_content);

			var b_found = false;
			var b_error = false;

			if (o_inputData.msgBox && o_inputData.msgBox.text) {
				b_error = true;
			}

			if (a_fields.length > 0) {

				b_found = Ext.Array.findBy(a_fields, function (i_field) {
					return i_field.getTabIndex() === i_self.getNeedFocus();
				});
			}

			if (!b_found) {

				i_self.setCurrentPosition({
					col: o_inputData.csrCol || 1,
					lin: o_inputData.csrLin || 1
				});
			}

			if (b_error) {
				i_self.onError(o_inputData);
			}
			else {
				i_self.findFocus();
			}
		}
	},

	getCurrentField: function() {

		var i_self = this;

		var a_fields = IceCap.util.Handler.getInputFields(i_self);
		var n_tabIndex = i_self.getCurrentTabIndex();
		var i_currentField;

		Ext.Array.each(a_fields, function(i_field) {
			if (i_field.getTabIndex() === n_tabIndex && i_field.hasFocus) {
				i_currentField = i_field;
				return false;
			}
		});

		return i_currentField;
	},

	doKeyEvent: function(s_value, i_event) {

		if (i_event) {
			i_event.stopEvent();
		}

		var i_self = this;

		var i_controller = i_self.getController();

		var o_inputData = i_self.getInputData() || {};

		var a_disabledKeys = Ext.Array.from(o_inputData.disabledKeys || []);

		var o_found = Ext.Array.findBy(a_disabledKeys, function (o_key) {
			return s_value == o_key.id;
		});

		if (!o_found) {
			i_controller.doKeyEvent(s_value);
		}
		else {

			Ext.Msg.show({
				title: "Error",
				msg: "Funktionstasten er ikke tilladt",
				icon: Ext.MessageBox.INFO,
				buttons: Ext.MessageBox.OK,
				fn: function () {
					i_self.findFocus();
				}
			});
		}
	},

	doNavigationKey: function(n_direction, b_tab, i_event) {

		if (i_event) {
			i_event.stopPropagation();
			i_event.preventDefault();
		}

		var i_self = this;
		var i_controller = i_self.getController();
		i_controller[b_tab ? "doTabKey" : "doArrowKeys"](n_direction);
	},

	addKeyEvents: function() {

		var i_self = this;

		var a_bindings = [
			{
				key: Ext.event.Event.PAGE_DOWN,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;
					i_self.doKeyEvent("ROLLUP", i_event);
				}
			},
			{
				key: Ext.event.Event.PAGE_UP,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;
					i_self.doKeyEvent("ROLLDOWN", i_event);
				}
			},
			{
				key: Ext.event.Event.ENTER,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;
					i_self.doKeyEvent("ENTER", i_event);
				}
			},
			{
				key: Ext.event.Event.ESC,
				fn: function(n_key, i_event) {

					i_event.preventDefault();

					var i_key = this;
					var i_self = i_key.target.component;
					i_self.doKeyEvent("ATTN", i_event);
				}
			},
			{
				key: Ext.event.Event.UP,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {

						if (!i_event.target.type) {

							i_event.stopEvent();

							var i_cursor = i_self.getCursor();
							var o_position = i_self.getCurrentPosition();

							var a_inputs = IceCap.util.Handler.getInputFields(i_self);

							o_position.lin--;

							if (o_position.lin < 1) {
								o_position.lin = 1;
							}

							var o_box = Ext.apply({
								x: IceCap.util.Handler.getX(o_position.col),
								y: IceCap.util.Handler.getY(o_position.lin),
								width: i_cursor.getWidth(),
								height: i_cursor.getHeight()
							});

							var b_intersect = false;

							Ext.Array.each(a_inputs, function(i_field) {

								var o_bound = i_field.el.dom.getBoundingClientRect();

								var o_rect = Ext.apply({}, {
									x: IceCap.util.Handler.getX(i_field.col),
									y: IceCap.util.Handler.getY(i_field.lin),
									width: o_bound.width,
									height: o_bound.height
								});

								if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
									b_intersect = true;
									i_field.focus(false, 10);


									var n_start = o_position.col - i_field.col;
									var i_inputEl = i_field.inputEl;
									i_inputEl.dom.selectionStart = i_inputEl.dom.selectionEnd = n_start;

									return false;
								}
							});

							if (!b_intersect) {

								i_cursor.moveCursor(o_position);
							}
							i_self.setCurrentPosition(o_position);
						}
						else {
							i_self.doNavigationKey(0, false, i_event);
						}
					}
				}
			},
			{
				key: Ext.event.Event.DOWN,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {

						if (!i_event.target.type) {

							i_event.stopEvent();

							var i_cursor = i_self.getCursor();
							var o_position = i_self.getCurrentPosition();
							var o_inputData = i_self.getInputData();
							var o_window = o_inputData.window;

							var a_inputs = IceCap.util.Handler.getInputFields(i_self);

							o_position.lin++;

							if (o_position.lin > o_window.height) {
								o_position.lin = o_window.height;
							}

							var o_box = Ext.apply({
								x: IceCap.util.Handler.getX(o_position.col),
								y: IceCap.util.Handler.getY(o_position.lin),
								width: i_cursor.getWidth(),
								height: i_cursor.getHeight()
							});

							var b_intersect = false;

							Ext.Array.each(a_inputs, function(i_field) {

								var o_bound = i_field.el.dom.getBoundingClientRect();

								var o_rect = Ext.apply({}, {
									x: IceCap.util.Handler.getX(i_field.col),
									y: IceCap.util.Handler.getY(i_field.lin),
									width: o_bound.width,
									height: o_bound.height
								});

								if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
									b_intersect = true;
									i_field.focus(false, 10);

									var n_start = o_position.col -i_field.col;
									var i_inputEl = i_field.inputEl;
									i_inputEl.dom.selectionStart = i_inputEl.dom.selectionEnd = n_start;

									return false;
								}
							});

							if (!b_intersect) {

								i_cursor.moveCursor(o_position);
							}
							i_self.setCurrentPosition(o_position);
						}
						else {
							i_self.doNavigationKey(1, false, i_event);
						}
					}
				}
			},
			{
				key: Ext.event.Event.LEFT,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {

						if (!i_event.target.type) {
							i_event.stopEvent();

							var i_cursor = i_self.getCursor();
							var o_position = i_self.getCurrentPosition();

							var a_inputs = IceCap.util.Handler.getInputFields(i_self);

							o_position.col--;

							if (o_position.col < 1) {
								o_position.col = 1;
							}

							var o_box = Ext.apply({
								x: IceCap.util.Handler.getX(o_position.col),
								y: IceCap.util.Handler.getY(o_position.lin),
								width: i_cursor.getWidth(),
								height: i_cursor.getHeight()
							});

							var b_intersect = false;

							Ext.Array.each(a_inputs, function(i_field) {

								var o_bound = i_field.el.dom.getBoundingClientRect();

								var o_rect = Ext.apply({}, {
									x: IceCap.util.Handler.getX(i_field.col),
									y: IceCap.util.Handler.getY(i_field.lin),
									width: o_bound.width,
									height: o_bound.height
								});

								if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
									b_intersect = true;
									i_field.focus(false, 10);
									return false;
								}
							});

							if (!b_intersect) {

								i_cursor.moveCursor(o_position);
							}

							i_self.setCurrentPosition(o_position);
						}
					}
				}
			},
			{
				key: Ext.event.Event.RIGHT,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {

						if (!i_event.target.type) {

							i_event.stopEvent();

							var i_cursor = i_self.getCursor();
							var o_position = i_self.getCurrentPosition();
							var o_inputData = i_self.getInputData();

							var a_inputs = IceCap.util.Handler.getInputFields(i_self);

							o_position.col++;

							if (o_position.col > o_inputData.width) {
								o_position.col = o_inputData.width;
							}

							var o_box = Ext.apply({
								x: IceCap.util.Handler.getX(o_position.col),
								y: IceCap.util.Handler.getY(o_position.lin),
								width: i_cursor.getWidth(),
								height: i_cursor.getHeight()
							});

							var b_intersect = false;

							Ext.Array.each(a_inputs, function(i_field) {

								var o_bound = i_field.el.dom.getBoundingClientRect();

								var o_rect = Ext.apply({}, {
									x: IceCap.util.Handler.getX(i_field.col),
									y: IceCap.util.Handler.getY(i_field.lin),
									width: o_bound.width,
									height: o_bound.height
								});

								if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
									b_intersect = true;
									i_field.focus(false, 10);
									return false;
								}
							});

							if (!b_intersect) {

								i_cursor.moveCursor(o_position);
							}

							i_self.setCurrentPosition(o_position);
						}
					}
				}
			},
			{
				key: Ext.event.Event.TAB,
				shift: false,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {

						i_self.doNavigationKey(1, true, i_event);
					}
				}
			},
			{
				key: Ext.event.Event.TAB,
				shift: true,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {

						i_self.doNavigationKey(0, true, i_event);
					}
				}
			},
			{
				key: Ext.event.Event.NUM_PLUS,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_field = i_self.getCurrentField();

					if (i_field) {

						var n_start = i_field.inputEl.el.dom.selectionStart;

						var s_text = i_field.getValue();

						s_text = s_text.substr(0, n_start);

						i_field.setValue(s_text);

						i_self.doNavigationKey(1, true, i_event);
					}
				}
			},
			{
				key: Ext.event.Event.HOME,
				ctrl: true,
				alt: false,
				fn: function(n_key, i_event) {

					i_event.stopEvent();

					var i_key = this;
					var i_self = i_key.target.component;

					var b_markerActive = i_self.getMarkerActive();
					var i_marker = i_self.getMarker();

					i_self.setMarkerActive(!b_markerActive);

					i_marker.toggle();
				}
			},
			{
				key: Ext.event.Event.INSERT,
				ctrl: false,
				alt: false,
				fn: function (n_key, i_event) {

					var n_type = i_self.getTypeMode();
					switch (n_type) {
						case IceCap.util.Handler.typeMode.OVERWRITE:
							n_type = IceCap.util.Handler.typeMode.INSERT;
							break;
						default:
							n_type = IceCap.util.Handler.typeMode.OVERWRITE;
							break;
					}

					i_self.setTypeMode(n_type);
				}
			}
		];

		a_bindings = a_bindings.concat(i_self.getFKeys());

		var i_keyMap = Ext.create("Ext.util.KeyMap", {
			target: i_self.getEl(),
			binding: a_bindings
		});
	},

	getFKeys: function() {

		var i_self = this;

		var a_keys = [
			{
				key: Ext.event.Event.F1,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F1", i_event);
				}
			},
			{
				key: Ext.event.Event.F2,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F2", i_event);
				}
			},
			{
				key: Ext.event.Event.F3,
				shift: false,
				alt: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F3", i_event);
				}
			},
			{
				key: Ext.event.Event.F4,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F4", i_event);
				}
			},
			{
				key: Ext.event.Event.F5,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F5", i_event);
				}
			},
			{
				key: Ext.event.Event.F6,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F6", i_event);
				}
			},
			{
				key: Ext.event.Event.F7,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F7", i_event);
				}
			},
			{
				key: Ext.event.Event.F8,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F8", i_event);
				}
			},
			{
				key: Ext.event.Event.F9,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F9", i_event);
				}
			},
			{
				key: Ext.event.Event.F10,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F10", i_event);
				}
			},
			{
				key: Ext.event.Event.F11,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F11", i_event);
				}
			},
			{
				key: Ext.event.Event.F12,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F12", i_event);
				}
			}
		];

		a_keys = a_keys.concat(i_self.getFShiftKeys());

		return a_keys;
	},

	getFShiftKeys: function() {

		var i_self = this;

		var a_keys = [
			{
				key: Ext.event.Event.F1,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F13", i_event);
				}
			},
			{
				key: Ext.event.Event.F2,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F14", i_event);
				}
			},
			{
				key: Ext.event.Event.F3,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F15", i_event);
				}
			},
			{
				key: Ext.event.Event.F4,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F16", i_event);
				}
			},
			{
				key: Ext.event.Event.F5,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F17", i_event);
				}
			},
			{
				key: Ext.event.Event.F6,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F18", i_event);
				}
			},
			{
				key: Ext.event.Event.F7,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F19", i_event);
				}
			},
			{
				key: Ext.event.Event.F8,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F20", i_event);
				}
			},
			{
				key: Ext.event.Event.F9,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F21", i_event);
				}
			},
			{
				key: Ext.event.Event.F10,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F22", i_event);
				}
			},
			{
				key: Ext.event.Event.F11,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F23", i_event);
				}
			},
			{
				key: Ext.event.Event.F12,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F24", i_event);
				}
			}
		];

		return a_keys;
	},

	createCursor: function () {

		var i_self = this;
		var o_inputData = i_self.getInputData();

		var i_cursor = Ext.widget("icecap-cursor", {
			theme: i_self.getTheme(),
			width: IceCap.util.Handler.getWidth(),
			listeners: {
				show: {
					fn: function (i_cursor) {

						var i_marker = i_self.getMarker();
						var b_active = i_marker.getInUse();

						if (b_active) {
							i_marker.show();
						}
					}
				},
				render: {
					fn: function (i_item) {
						i_item.hide();
					}
				},
				afterrender: {
					fn: function (i_cursor) {

						var i_content = i_self.getContent();

						var a_fields = IceCap.util.Handler.getInputFields(i_content);

						if (a_fields.length === 0) {

							i_cursor.show();

							i_cursor.moveCursor({
								col: o_inputData.csrCol || 1,
								lin: o_inputData.csrLin || 1
							});
						}
					}
				}
			},
			moveCursor: function (o_position) {

				var i_cursor = this;
				var i_marker = i_self.getMarker();

				var n_x = IceCap.util.Handler.getX(o_position.col);
				var n_y = IceCap.util.Handler.getY(o_position.lin + 1);

				var a_pos = [
					n_x,
					n_y
				];

				i_cursor.move([
					n_x,
					n_y - 11
				]);
				i_marker.move([
					n_x - 7,
					n_y - 12
				]);

				i_self.updateCurrentPosition(o_position);
			}
		});

		i_self.setCursor(i_cursor);

		return i_cursor;
	},

	createMarker: function() {

		var i_self = this;

		var i_marker = Ext.widget("icecap-marker", {
			hidden: true,
			active: false,
			inUse: false,
			ui: i_self.getTheme() || "default"
		});

		i_self.setMarker(i_marker);

		return i_marker;
	},

	findFocus: function() {

		var i_self = this;
		var i_main = i_self.getMain();
		var i_content = i_self.getContent();

		var a_fields = IceCap.util.Handler.getInputFields(i_content);

		if (a_fields.length > 0) {

			var i_field = a_fields[0];
			i_field.focus(false, 10);
		}
		else {
			i_main.focus(false, 10);
		}
	},

	doTimer: function() {

		var i_self = this;

		var i_timer = i_self.getTimer();
		if (!i_timer) {
			i_timer = new Ext.util.DelayedTask(function() {
				i_self.setLoading(true);
			});

			i_self.setTimer(i_timer);

			i_timer.delay(1000);
		}
	},

	cancelTimer: function() {

		var i_self = this;

		var i_timer = i_self.getTimer();

		if (i_timer) {
			i_timer.cancel();
			i_self.setTimer(null);
		}
	},

	onError: function(o_inputData) {

		var i_self = this;

		Ext.Msg.show({
			title: "Server Message",
			msg: o_inputData.msgBox.text,
			icon: Ext.MessageBox.INFO,
			buttons: Ext.MessageBox.OK,
			fn: function(btn) {
				i_self.findFocus();
			}
		});
	},

	updateMessage: function (o_inputData) {

		var i_self = this;
		var i_statusbar = i_self.getStatusBar();

		var a_messages = Ext.Array.from(o_inputData.message);

		var a_result = [];

		if (a_messages.length > 1) {

			a_result.push(a_messages[0].text);
		}
		else {
			Ext.Array.each(a_messages, function(o_message) {
				a_result.push(o_message.text);
			});
		}

		var i_messageLabel = i_statusbar.getComponent("icecap-message");

		var s_message = a_result.join(" ");

		if (Ext.String.startsWith(s_message.toLowerCase(), "(c)")) {
			i_messageLabel.removeCls("icecap-statusbar-error");

		}
		else {
			i_messageLabel.addCls("icecap-statusbar-error")
		}
		i_messageLabel.setText(s_message);
	},

	applyFFW: function (o_config) {

		var i_self = this;
		var s_hex = o_config.ffw;
		var b_fixed = IceCap.util.Handler.getFixed();

		var o_field = {
			xtype: "icecap-input"
		};

		var o_fieldStyle = {
		};

		if (o_config.ta) {

			Ext.apply(o_fieldStyle, {
				"text-align": o_config.ta
			});
		}

		if (s_hex) {

			var n_hex = parseInt(s_hex);

			var n_sanHex = IceCap.util.Handler.createIndicators(s_hex);

			if (n_sanHex & IceCap.util.Handler.FFW.BYPASS) {

				Ext.apply(o_field, {
					readOnly: true
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.ALPHA_ONLY) {

				Ext.apply(o_field, {
					maskRe: new RegExp("[a-z A-Z ,.-]")
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.NUMERIC_ONLY) {

				Ext.apply(o_field, {
					maskRe: new RegExp("[+\\-,. 0-9]")
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.DIGITS_ONLY) {

				Ext.apply(o_field, {
					maskRe: new RegExp("[0-9]")
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.MOD_DATA) {

				Ext.apply(o_field, {
					listeners: {
						afterrender: {
							fn: function (i_field) {

								i_field.originalValue = 0xFF;
							},
							single: true
						}
					}
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.AUTO_ENTER) {

				// THIS WE DONT NEED IN THE MODERN WORLD...

				// Ext.apply(o_field, {
				// 	listeners: {
				// 		blur: {
				// 			fn: function(i_field) {
				// 				i_self.doKeyEvent("ENTER");
				// 			}
				// 		}
				// 	}
				// });
			}

			if (n_sanHex & IceCap.util.Handler.FFW.MONOCASE) {

				// Ext.apply(o_fieldStyle, {
				// 	"text-transform": "uppercase"
				// });
			}

			if (n_sanHex & IceCap.util.Handler.FFW.MAND_ENTER) {

				Ext.apply(o_field, {
					allowBlank: false
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.RA_ZEROFILL ||
				n_sanHex & IceCap.util.Handler.FFW.RA_BLANKFILL ||
				n_sanHex & IceCap.util.Handler.FFW.RA_MANDATORY) {

				Ext.apply(o_fieldStyle, {
					"text-align": "right"
				});
			}

			if (o_config.atr == "27" && n_hex & (1 << 13)) {

				Ext.apply(o_field, {
					hidden: true,
					disabled: true
				});
			}
		}

		Ext.apply(o_field, {
			fieldStyle: o_fieldStyle
		});

		return o_field;
	},

	updateCurrentPosition: function (o_position) {

		var i_self = this;
		var i_statusbar = i_self.getStatusBar();

		if (i_statusbar) {
			var i_position = i_statusbar.getComponent("icecap-position");

			if (i_position) {

				var a_result = [
					o_position.lin,
					o_position.col
				];

				i_position.setText(a_result.join("/"));
			}

			i_self.updateTypeMode(i_self.getTypeMode())
		}
	},

	updateTypeMode: function (n_type) {

		var i_self = this;

		var i_statusbar = i_self.getStatusBar();

		if (i_statusbar) {

			var i_typeLabel = i_statusbar.getComponent("icecap-typemode");

			var a_mode = [
			];

			if (i_typeLabel) {

				switch (n_type) {
					case IceCap.util.Handler.typeMode.OVERWRITE:
						a_mode.push(" DEL");
						break;

					default:
						a_mode.push(" INS");
						break;
				}

				i_typeLabel.setText(a_mode.join(" "));
			}
		}
	},
	updateEdit: function(value) {

		var i_self = this;
		
		if (i_self.rendered) {
			var o_inputData = i_self.getInputData();

			i_self.redraw();
		}
	}
});
if (Ext.ClassManager.aliasToName["widget.webcontainer"] == null) {
	Ext.define("IceCap.view.WebContainer", {

		extend: "Ext.Component",

		xtype: "icecap-webcontainer",

		alias: [
			"widget.icecap.view.webcontainer",
			"widget.webcontainer"
		],

		config: {
			src: ""
		},

		autoEl: {
			tag: "iframe",
			style: "height: 100%; width: 100%; border: none;",
			src: ""
		},

		listeners: {
			render: {
				fn: function (i_self) {

					var i_element = i_self.getEl();

					if (i_element) {
						i_element.dom.src = i_self.getSrc();
						i_self.setLoading(true);
					}
				}
			},
			load: {
				element: "el",
				fn: function (i_element) {

					var i_self = this.component;
					i_self.setLoading(false);
				}
			}
		},

		initComponent: function () {

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

		updateSrc: function (s_url) {

			var i_self = this;
			var i_element = i_self.getEl();

			if (i_element) {
				i_element.dom.src = s_url;
				i_self.setLoading(true);
			}
		}
	});
}


Ext.define("IceCap.controller.Main", {
	extend: "Ext.app.ViewController",

	alias: "controller.icecap.view.main",

	listen: {
		global: {
			beforelogout: {
				fn: function() {

					var i_controller = this;
					i_controller.onBeforeLogout();
				}
			}
		}
	},

	onAfterRender: function(i_panel) {

		var i_self = i_panel;

		i_self.addKeyEvents();

		var i_content = i_self.getContent();
		var i_main = i_self.getMain();

		var o_inputData = i_self.getInputData() || {};

		if (o_inputData.window) {
			i_self.doCreateFromData(o_inputData);
		}

		if (i_content) {

			var a_fields = IceCap.util.Handler.getInputFields(i_content);

			var i_found = Ext.Array.findBy(a_fields, function (i_field) {
				return i_field.getTabIndex() == i_self.getNeedFocus();
			});

			if (i_found) {
				i_found.focus(false, 10);
			}
			else {
				i_self.setCurrentPosition({
					col: o_inputData.csrCol,
					lin: o_inputData.csrLin
				});

				i_main.focus(true, 10);
			}
		}
	},

	onSendData: function(o_config, o_data) {

		var i_controller = this;
		var o_saved = Ext.clone(o_config);
		var i_view = i_controller.getView();
		var s_session = i_view.getSessionValue();

		var o_options = i_view.getOptions();

		o_data = Ext.apply(o_data, {
			i18nLearning: false
		});

		Ext.apply(o_config, {
			session: s_session,
		});

		Ext.apply(o_config, o_options);

		if (!i_view.getWorking()) {
			i_view.setWorking(true);
			i_view.doTimer();
			IceCap.util.Handler.getData(o_config, o_data, function(o_inputData) {

				if (o_inputData.statusUpdate) {

					i_view.setWorking(false);
					i_view.updateMessage(o_inputData);
					if (o_inputData.status > -1) {
						i_view.doCreateFromData(o_inputData);
					}
					i_controller.onSendData(o_saved, o_data);
				}
				else {

					i_view.setLoading(false);
					i_view.cancelTimer();

					var f_callback = i_view.getResponseCallBack() || Ext.emptyFn;

					if (f_callback != Ext.emptyFn) {

						f_callback(o_inputData);
					}

					var o_plugin = o_inputData.plugin || Ext.apply({}, {
						require: []
					});

					var a_require = o_plugin.require || [];
					var s_run = o_plugin.run || "";

					i_controller.doRequire(a_require, function() {

						if (s_run) {
							eval(s_run);
						}

						if (o_inputData.close) {
							i_view.close();
						}
						else {

							i_view.setWorking(false);
							i_view.doCreateFromData(o_inputData);

							i_view.fireEvent("stateupdate", i_view);
						}
					});
				}
			});
		}
	},

	onWheel: function(i_event) {

		var i_controller = this;
		var i_view = i_controller.getView();

		var b_hasGrid = i_view.query("gridpanel").length > 0;
		var b_mappanel = i_view.query("icecap-gmappanel").length > 0;

		var n_delta = i_event.getWheelDelta();
		var s_event = "";

		if (n_delta > 0) {
			s_event = "ROLLDOWN";
		}
		else {
			s_event = "ROLLUP";
		}

		if (!b_hasGrid && !b_mappanel && !i_event.ctrlKey){
			i_controller.doKeyEvent(s_event);
		}
	},

	onDblClick: function(i_event) {

		var i_controller = this;
		var i_view = i_controller.getView();
		var o_inputData = i_view.getInputData();
		var i_cursor = i_view.getCursor();

		var b_fireEvent = i_view.getEnterOnDblClick();

		if (b_fireEvent) {

			var i_body = i_view.body;
			var a_local = i_body.getOffsetsTo(window);

			var a_metaFields = o_inputData.metaFields || [];

			var o_click = Ext.apply({
				x: i_event.pageX - a_local[0],
				y: i_event.pageY - a_local[1]
			});

			var o_position = IceCap.util.Handler.toColAndLine(o_click);

			var i_currentField = i_view.getCurrentField();

			if (i_currentField) {
				o_position = Ext.apply(o_position, {
					lin: i_currentField.lin,
					col: i_currentField.col
				});
				if (i_currentField.inputEl && i_currentField.getValue()) {
					o_position = IceCap.util.Handler.toColAndLine(o_click);
				}
			}
			else {

				i_cursor.moveCursor(o_position);
				i_cursor[a_metaFields.length === 0 ? "show" : "hide" ]();
			}

			i_view.setCurrentPosition(o_position);

			if (a_metaFields.length === 0) {
				i_controller.doKeyEvent("ENTER");
			}
		}
	},

	onClick: function(i_event) {

		var i_controller = this;
		var i_view = i_controller.getView();
		var o_inputData = i_view.getInputData();
		var i_cursor = i_view.getCursor();
		var i_content = i_view.getContent();

		var i_activeComponent = Ext.ComponentManager.getActiveComponent();

		var i_body = i_view.body;
		var a_local = i_body.getOffsetsTo(window);

		var o_click = Ext.apply({
			x: i_event.pageX - a_local[0],
			y: i_event.pageY - a_local[1]
		});

		var o_position = IceCap.util.Handler.toColAndLine(o_click);

		if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {

			var i_currentField = i_view.getCurrentField();

			var a_metaFields = o_inputData.metaFields || [];

			if (i_currentField) {
				o_position = Ext.apply(o_position, {
					lin: i_currentField.lin,
					col: i_currentField.col
				});
				if (i_currentField.inputEl && i_currentField.getValue()) {
					o_position = IceCap.util.Handler.toColAndLine(o_click);
				}
			}
			else {

				var a_inputs = IceCap.util.Handler.getInputFields(i_view);

				var o_box = Ext.apply({
					x: IceCap.util.Handler.getX(o_position.col),
					y: IceCap.util.Handler.getY(o_position.lin),
					width: IceCap.util.Handler.getColSize(),
					height: 1
				});

				var b_intersect = false;

				Ext.Array.each(a_inputs, function (i_field) {

					var i_element = i_field.getEl();

					if (i_element) {

						var o_bound = i_element.dom.getBoundingClientRect();

						var o_rect = Ext.apply({}, {
							x: IceCap.util.Handler.getX(i_field.col),
							y: IceCap.util.Handler.getY(i_field.lin),
							width: o_bound.width,
							height: o_bound.height
						});

						if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {

							b_intersect = true;
							i_field.focus(false, 10);

							var n_start = o_position.col - i_field.col;
							var i_inputEl = i_field.inputEl;
							i_inputEl.dom.selectionStart = i_inputEl.dom.selectionEnd = n_start;

							return false;
						}
					}
				});

				if (!b_intersect) {
					i_cursor.moveCursor(o_position);

					i_cursor[a_metaFields.length === 0 ? "show" : "hide"]();
				}
			}
		}

		i_view.setCurrentPosition(o_position);
	},

	doArrowKeys: function(n_direction) {

		var i_controller = this;
		var i_view = i_controller.getView();
		var a_fields = IceCap.util.Handler.getInputFields(i_view);
		var n_tabIndex = i_view.getCurrentTabIndex();
		var n_lastTabIndex = i_view.getLastTabIndex();
		var n_part = n_direction ? 1 : -1;

		var i_lastFocus;
		var i_nextFocus;

		i_lastFocus = Ext.Array.findBy(a_fields, function (i_field) {
			return i_field.getTabIndex() == n_tabIndex;
		});

		var b_found = false;

		if (i_lastFocus) {

			var n_lin = i_lastFocus.lin;
			var n_col = i_lastFocus.col;
			var n_next = n_lin + n_part;

			i_nextFocus = Ext.Array.findBy(a_fields, function(i_field) {
				return i_field.lin === n_next && i_field.col === n_col;
			});

			if (i_nextFocus) {
				b_found = true;
				n_tabIndex = i_nextFocus.getTabIndex();
				i_nextFocus.focus(false, 10);
			}
		}

		if (!b_found) {

			n_tabIndex = i_view.getCurrentTabIndex() + n_part;

			if (n_direction) {
				if (n_tabIndex > n_lastTabIndex) {
					n_tabIndex = 1;
				}
			}
			else {
				if (n_tabIndex < 1) {
					n_tabIndex = n_lastTabIndex;
				}
			}

			i_nextFocus = Ext.Array.findBy(a_fields, function (i_field) {
				return i_field.getTabIndex() == n_tabIndex;
			});

			if (i_nextFocus) {
				i_nextFocus.focus(false, 10);
			}
		}

		i_view.setCurrentTabIndex(n_tabIndex);
	},

	doTabKey: function(n_direction) {

		var i_controller = this;
		var i_view = i_controller.getView();
		var a_fields = IceCap.util.Handler.getInputFields(i_view);
		var n_tabIndex = i_view.getCurrentTabIndex();
		var n_lastTabIndex = i_view.getLastTabIndex();
		var n_part = n_direction ? 1 : -1;

		n_tabIndex = i_view.getCurrentTabIndex() + n_part;

		if (n_direction) {
			if (n_tabIndex > n_lastTabIndex) {
				n_tabIndex = 1;
			}
		}
		else {
			if (n_tabIndex < 1) {
				n_tabIndex = n_lastTabIndex;
			}
		}

		var i_found =Ext.Array.findBy(a_fields, function(i_field) {
			return i_field.getTabIndex() == n_tabIndex;
		});

		if (i_found) {
			i_found.focus(false, 10);
		}

		i_view.setCurrentTabIndex(n_tabIndex);
	},

	doKeyEvent: function(s_value) {

		var i_controller = this;
		var i_view = i_controller.getView();

		var i_currentField = i_view.getCurrentField();
		var o_position = i_view.getCurrentPosition();

		var o_data = {
			key: s_value
		};

		var i_content = i_view.getContent();
		var i_form = i_content.getForm();
		var i_collectionField = i_form.getFields();
		var o_values = {};

		Ext.Array.each(i_collectionField.items, function(i_field) {
			if (i_field.isDirty()) {
				var value = i_field.getSubmitValue ? i_field.getSubmitValue() : i_field.getValue();
				o_values[i_field.itemId || i_field.initialConfig.id || i_field.name] = value;
			}
		});

		Ext.Object.each(o_values, function(s_key, value) {
			var s_id = "ses2.win." + s_key;
			o_data[s_id] = value;
		});

		if (i_currentField) {

			o_data = Ext.apply(o_data, {
				csrLin: i_currentField.lin,
				csrCol: i_currentField.col
			});

			if (i_currentField.inputEl && i_currentField.getValue()) {
				o_data = Ext.apply(o_data, {
					csrCol: o_position.col
				});
			}
		}
		else {

			o_data = Ext.apply(o_data, {
				csrLin: o_position.lin,
				csrCol: o_position.col
			});
		}

		var f_callback = i_view.getRequestCallBack() || Ext.emptyFn;

		if (f_callback != Ext.emptyFn) {

			f_callback(o_data);
		}

		i_controller.onSendData({
			func: ""
		}, o_data);
	},

	doFKey: function(s_value) {

		var i_controller = this;

		i_controller.doKeyEvent(s_value);
	},

	doRequire: function(a_require, f_callback) {

		f_callback = f_callback || Ext.emptyFn;

		a_require = a_require || [];

		if (a_require.length > 0) {

			var a_external = Ext.Array.filter(Ext.Array.map(a_require, function(s_value) {
				if (s_value.indexOf("/") > -1) {
					return s_value;
				}
			}), function(value) {
				return value;
			});

			var a_internal = Ext.Array.filter(Ext.Array.map(a_require, function(s_value) {
				if (s_value.indexOf("/") < 0) {
					return s_value;
				}
			}), function(value) {
				return value;
			});

			if (a_external.length > 0) {
				Ext.Loader.loadScriptsSync(a_external);
			}

			if (a_internal.length > 0) {
				Ext.syncRequire(a_internal);
			}
		}

		f_callback();
	},

	onPCO: function(o_inputData) {

		var i_controller = this;
		var i_view = i_controller.getView();
		var i_keyMap = i_view.getKeyMap();

		switch (o_inputData.cmdAct) {

			case 0:
				window.open(o_inputData.cmd, o_inputData.cmdTitle, "");
				break;
			case 1:
				var i_window = Ext.widget("window", {
					title: o_inputData.cmdTitle,
					layout: "fit",
					collapsible: true,
					items: [
						{
							xtype: "icecap-webcontainer",
							src: o_inputData.cmd
						}
					],
					width: window.outerWidth * 0.9,
					height: window.outerHeight * 0.9
				});

				i_window.show();
				break;
			default:

				i_keyMap.disable();

				var i_store = Ext.create('Ext.data.Store', {
					proxy: {
						type: 'jsonp',
						timeout: "86400000",
						url: o_inputData.cmd,
						nocache: false,
						callback: function(o_result) {
							i_keyMap.enable();
						},
						listeners: {
							exception: {
								fn: function(i_proxy, i_request, i_operation) {
									i_controller.onPCOError(i_operation.error, function() {
										i_keyMap.enable();
										i_view.findFocus();
									});
								}
							}
						}
					}
				});

				i_store.load();
				break;
		}
	},

	onPCOError: function(s_error, f_callback) {

		f_callback = f_callback || Ext.emptyFn;

		var i_template = new Ext.XTemplate(
			"<div class=\"iceCap-msg\">",
				"<h3>{header}</h3>",
				"<ul>",
					"<li>{message}</li>",
				"</ul>",
			"</div>"
		);

		var i_window = Ext.widget("window", {
			title: "PCO Error",
			width: 800,
			modal: true,
			closable: false,
			html: i_template.apply({
				header: "Error",
				message: s_error
			}),
			bodyPadding: 5,
			buttons: [{
				text: "Ok",
				tabIndex: 1,
				focusable: true,
				listeners: {
					afterrender: {
						fn: function(i_button) {
							setTimeout(function() {
								i_button.focus(false, 10);
							});
						}
					}
				},
				handler: function() {
					i_window.close();
					f_callback();
				}
			}]
		});

		i_window.show();
	},

	onDestroy: function(i_panel) {

		var s_session = i_panel.getSessionValue();

		IceCap.util.Handler.removeSession(s_session);

		Ext.Ajax.request({
			method: "POST",
			url: IceCap.util.Handler.getPath({
				session: s_session,
				func: "",
				close: "on"

			})
		});
	},

	onBeforeDestroy: function() {

		var i_controller = this;
		var i_view = i_controller.getView();

		i_controller.onDestroy(i_view);

		var i_window = i_view.up("window");

		if (i_window) {
			i_window.close();
		}
	},

	onActivated: function() {

		var i_controller = this;
		var i_view = i_controller.getView();
		var i_content = i_view.getContent();
		var i_main = i_view.getMain();

		var o_currentPosition = i_view.getCurrentPosition();

		var a_inputs = IceCap.util.Handler.getInputFields(i_view);

		var o_box = Ext.apply({
			x: IceCap.util.Handler.getX(o_currentPosition.col),
			y: IceCap.util.Handler.getY(o_currentPosition.lin),
			width: IceCap.util.Handler.getWidth(),
			height: 2
		});

		var b_intersect = false;

		var o_inputData = i_view.getInputData() || {
			metaFields: []
		};

		var a_metaFields = o_inputData.metaFields || [];

		Ext.Array.each(a_inputs, function(i_field) {

			var i_element = i_field.getEl();

			if (i_element) {
				var o_bound = i_element.dom.getBoundingClientRect();

				var o_rect = Ext.apply({}, {
					x: i_field.getLocalX(),
					y: i_field.getLocalY(),
					width: o_bound.width,
					height: o_bound.height
				});

				if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
					b_intersect = true;
					i_field.focus(false, 10);
					return false;
				}
			}
		});

		if (!b_intersect) {
			var i_cursor = i_view.getCursor();

			if (i_cursor) {

				i_cursor.moveCursor(o_currentPosition);

				i_cursor[a_metaFields.length === 0 ? "show" : "hide" ]();
			}

			if (i_main) {
				setTimeout(function() {
					i_main.focus(true, 10);
				}, 10);
			}
		}
	},

	onApplicationClose: function() {

		var i_controller = this;
		var i_view = i_controller.getView();

		i_view.close();
	},

	onBeforeLogout: function() {

		var i_controller = this;
		var i_view = i_controller.getView();

		i_view.close();
	}
});
Ext.define("IceCap.view.Main", {

	xtype: "icecap-panel",

	extend: "Ext.panel.Panel",

	layout: "fit",

	ui: "",

	mixins: [
		"Ext.mixin.Mashup"
	],

	requiredScripts: [
		"/icecap/app/theme/default.css",
		"/icecap/app/icecap-overrides.js"
	],

	requires: [
		"IceCap.controller.Main",
		"IceCap.view.Window",
		"IceCap.util.Handler",
		"IceCap.util.Scale",
		"IceCap.util.Breakout",
		"IceCap.component.Marker",
		"IceCap.component.Cursor",
		"IceCap.component.Input",
		"IceCap.component.Selector",
		"IceCap.ux.form.panel.Panel4Area",
		"IceCap.ux.form.panel.TabPanel",
		"IceCap.ux.grid.editor.Main",
		"IceCap.ux.container.Column",
		"IceCap.ux.form.label.Label",
		"IceCap.ux.form.field.Field",
		"IceCap.ux.form.panel.fusionChart",
		"IceCap.ux.form.field.SimpleComboBox",
		"IceCap.ux.form.field.sqlComboBox",
		"IceCap.ux.form.field.sqlSearchBox",
		"IceCap.ux.form.field.LINKFIELD",
		"IceCap.ux.form.field.AdvancedComboBox",
		"IceCap.ux.form.field.CommandField",
		"IceCap.ux.form.field.LibraryFileDependency",
		"IceCap.ux.form.field.FileLibraryDependency",
		"IceCap.ux.form.field.RadioGroup",
		"IceCap.ux.container.CommandPanel",
		"IceCap.ux.container.GMapPanel"
	],

	config: {
		inputData: null,
		lastTabIndex: 1,
		currentTabIndex: 1,
		content: null,
		keyArea: null,
		working: false,
		needFocus: 1,
		ignoreTitle: false,
		currentPosition: {
			col: 1,
			lin: 1
		},
		activeWindow: null,
		statusBar: null,
		main: null,
		sessionValue: "",
		keyMap: null,
		cursor: null,
		timer: null,
		func: "",
		initFunc: "",
		initCmd: "",
		responseCallBack: Ext.emptyFn,
		requestCallBack: Ext.emptyFn,
		theme: "",
		scale: 14,
		enterOnDblClick: false,
		marker: null,
		markerActive: false,
		options: {},
		messageText: "",
		typeMode: 2,
		resizeMode: 1,
		edit: false
	},

	controller: "icecap.view.main",

	focusable: false,

	listeners: {
		afterrender: {
			fn: "onAfterRender",
			buffer: 100,
			single: true
		},
		activate: {
			fn: "onActivated",
			buffer: 10
		},
		dblclick: {
			fn: "onDblClick",
			element: "body"
		},
		click: {
			fn: "onClick",
			element: "body"
		},
		wheel: {
			fn: "onWheel",
			element: "body"
		},
		beforedestroy: {
			fn: "onBeforeDestroy"
		},
		applicationClose: {
			fn: "onApplicationClose"
		},
		fieldoption: {
			fn: function(a_config) {

				var i_self = this;
				var i_controller = i_self.getController();

				var o_data = {};

				Ext.apply(o_data, {
					key: "ENTER"
				});

				Ext.Array.each(a_config, function(o_config) {

					var s_field = o_config.field;

					o_data[s_field] = o_config.option;

					Ext.apply(o_data, {
						csrCol: o_config.col,
						csrLin: o_config.lin
					});
				});

				i_self.setCurrentPosition({
					col: o_data.csrCol,
					lin: o_data.csrLin
				});

				i_controller.onSendData({
					func: ""
				}, o_data);
			}
		},
		key: {
			fn: function(s_value) {

				var i_self = this;
				var i_controller = i_self.getController();

				i_controller.doKeyEvent(s_value);
			}
		},
		resize: {
			fn: function() {

				var i_self = this;
				IceCap.util.Handler.setChanged(false);
				i_self.redraw();
			}
		}
	},

	initComponent: function() {

		Ext.tip.QuickTipManager.init();

		var i_self = this;

		var o_params = Ext.Object.fromQueryString(window.location.search);

		Ext.Object.each(o_params, function(s_key, value) {
			o_params[s_key] = Ext.decode(value, true) || value;
		});

		var o_options = Ext.apply(i_self.options, o_params.options || {});

		Ext.apply(i_self, o_options);

		i_self.callParent(arguments);

		i_self.add(i_self.createLayout());

		var o_data = i_self.getInputData();
		var s_sessionValue = i_self.getSessionValue();

		if (o_data) {
			if (o_data.close) {
				i_self.close();
			}
			else {

				IceCap.util.Handler.useScale(i_self.getScale());

				if (s_sessionValue) {

					IceCap.util.Handler.isSessionAlive(s_sessionValue, function(b_alive) {
						if (!b_alive) {
							i_self.setSessionValue(null);
							i_self.setInputData(null);

							i_self.doInit(function(o_data) {
								i_self.cancelTimer();
								i_self.setLoading(false);
								if (o_data.close) {
									i_self.close();
								}
								else {
									i_self.setInputData(o_data);
									i_self.doCreateFromData(o_data);
								}
							});
						}
						else {
							i_self.doCreateFromData(o_data);
						}
					});
				}
			}
		}
		else {
			i_self.doInit(function(o_data) {
				i_self.cancelTimer();
				i_self.setLoading(false);
				if (o_data.close) {
					i_self.close();
				}
				else {
					i_self.setInputData(o_data);
					i_self.doCreateFromData(o_data);
				}
			});
		}

		if (i_self.getTheme()) {
			Ext.Loader.loadScriptsSync([
				"/icecap/app/theme/" + i_self.getTheme() + ".css"
			]);
		}

		i_self.enableBubble("onAddWebContainer");
		i_self.enableBubble("stateupdate");
	},

	doInit: function(f_callback) {

		var i_self = this;

		IceCap.util.Handler.useScale(i_self.getScale());

		if (i_self.getSessionValue()) {

			IceCap.util.Handler.addSession(i_self.getSessionValue());

			IceCap.util.Handler.getData(Ext.apply({
				session: i_self.getSessionValue(),
				func: i_self.getFunc(),
				initFunc: i_self.getInitFunc() || i_self.getInitCmd() || "",
			}, i_self.getOptions()), {}, function(o_data) {
				f_callback(o_data);
			});
		}
		else {

			IceCap.util.Handler.getNewSession(function(o_result) {

				if (o_result.success) {

					i_self.setSessionValue(o_result.session);
					i_self.doTimer();
					IceCap.util.Handler.getData(Ext.apply({
						session: o_result.session,
						func: i_self.getFunc(),
						initFunc: i_self.getInitFunc() || i_self.getInitCmd() || "",
					}, i_self.getOptions()), {}, function(o_data) {
						f_callback(o_data);
					});
				}
				else {
					Ext.Msg.show({
						title: "Error",
						msg: "No session pls! retry to connect",
						buttons: Ext.Msg.OK
					});
				}
			});
		}
	},

	createLayout: function() {

		var i_self = this;

		return i_self.createContent();
	},

	createContent: function() {

		var i_self = this;
		var o_inputData = i_self.getInputData() || {};

		var a_items = i_self.createItems();

		var i_keyArea = Ext.widget("panel", {
			layout: {
				type: "column"
			},
			border: false,
			focusable: false,
			height: 50,
			defaults: {
				margin: "0 5 5 0"
			},
			cls: ["icecap-panel", i_self.getTheme()].join("-"),
			ui: "icecap-keyarea"
		});

		a_items.push(i_keyArea);

		var i_panel = Ext.widget("panel", {
			layout: {
				type: "vbox",
				align: "stretch"
			},
			border: false,
			focusable: true,
			tabIndex: -1,
			items: a_items
		});

		i_self.setMain(i_panel);

		var i_statusbar = i_self.createStatusBar();


		i_self.addDocked(i_statusbar);

		i_self.setKeyArea(i_keyArea);

		i_self.setStatusBar(i_statusbar);

		i_self.updateMessage(o_inputData);

		return i_panel;
	},

	createStatusBar: function() {

		var i_self = this;

		var i_statusbar = Ext.widget("toolbar", {
			dock: "bottom",
			cls: "icecap-statusbar",
			hidden: false,
			ui: "statusbar",
			layout: {
				type: "hbox",
				align: "top"
			},
			height: 30,
			items: [
				{
					xtype: "label",
					itemId: "icecap-message",
					listeners: {
						afterrender: {
							fn: function(i_label) {

								var i_tpl = Ext.create("Ext.XTemplate",
									"<ul style=\"list-style: none;",
												"margin:10px;",
												"padding:0;",
									"\">",
										"<tpl for=\".\">",
											"<li>{text}</li>",
										"</tpl>",
									"</ul>"
								);

								Ext.create("Ext.tip.ToolTip", {
									target: i_label.getEl(),
									html: "",
									anchor: true,
									defealtAlign: "b50-t50",
									listeners: {
										beforeshow: {
											fn: function (i_tip) {

												var b_hasError = i_label.hasCls("icecap-statusbar-error");

												var o_inputData = i_self.getInputData();

												var a_messages = Ext.Array.from(o_inputData.message);

												if (b_hasError && a_messages.length > 0) {
													var s_value = i_tpl.apply(a_messages);
													i_tip.update(s_value);
												}
												else {
													return b_hasError;
												}
											}
										}
									}
								});
							}
						},
						click: {
							element: "el",
							fn: function (i_event, i_element) {

								var o_input = {
									col: 3,
									lin: 24
								};

								i_self.setCurrentPosition(o_input);

								var i_cursor = i_self.getCursor();
								i_cursor.moveCursor(o_input);

								i_self.doKeyEvent("F1");
							}
						},
					}
				},
				"->",
				{
					xtype: "component",
					cls: "pf-gearwheel",
					height: 24,
					hidden: true,
					autoEl: {
						tab: "span"
					},
					style: {
						"cursor": "pointer"
					},
					listeners: {
						click: {
							element: "el",
							fn: function() {

								var i_element = this;
								var b_edit = i_self.getEdit();

								b_edit = !b_edit;

								if (b_edit) {
									i_element.addCls("x-base-color");
								}
								else {
									i_element.removeCls("x-base-color");
								}

								i_self.setEdit(b_edit);
							}
						}
					}
				},
				{
					xtype: "label",
					itemId: "icecap-position"
				},
				{
					xtype: "label",
					text: " INS",
					itemId: "icecap-typemode"
				}
			],
			setText: function(s_text) {

				var i_toolbar = this;

				var i_message = i_toolbar.getComponent("icecap-message");

				if (i_message) {
					i_message.setText(s_text);
				}
			}
		});

		return i_statusbar;
	},

	createItems: function() {

		var i_self = this;

		var a_items = [];

		var i_center = Ext.widget("form", {
			border: false,
			layout: "absolute",
			autoScroll: true,
			focusable: false,
			flex: 1,
			ui: ["icecap", i_self.getTheme()].filter(Boolean).join("-")
		});

		a_items.push(i_center);

		i_self.setContent(i_center);

		return a_items;
	},

	splitFields: function() {

		var i_self = this;
		var o_inputData = i_self.getInputData();

		var a_sliced = Ext.Array.from(o_inputData.fields || []);

		var a_outputs = Ext.Array.from(o_inputData.output || []);
		var a_inputs = Ext.Array.from(o_inputData.input || []);

		Ext.Array.each(a_sliced, function(o_config) {
			if (o_config.type == "input" || o_config.type == "grid") {
				a_inputs.push(o_config);
			}
			else if (o_config.type == "output") {
				a_outputs.push(o_config);
			}
		});

		Ext.apply(o_inputData, {
			input: a_inputs,
			output: a_outputs
		});

		if (a_sliced.length > 0) {
			o_inputData.processedFields = true;
		}

		delete o_inputData.fields;

		i_self.setInputData(o_inputData);
	},

	createFields: function() {

		var i_self = this;
		var o_inputData = i_self.getInputData();

		var a_fields = [];

		var n_tabIndex = 1;
		var n_focus = o_inputData.focus;

		var n_inputWidth = o_inputData.width || 80;

		var a_sliced = Ext.Array.from(o_inputData.input || []);

		Ext.Array.each(a_sliced, function(o_config, n_index) {

			var n_width = (IceCap.util.Handler.getWidth(o_config.len) + (IceCap.util.Handler.getWidth() / 2));

			var o_meta = o_config.metaData || {};

			var o_field = {
				xtype: "icecap-input",
				ui: "icecap-field"
			};

			var s_type = o_field.xtype || "icecap-input";
			var n_x = IceCap.util.Handler.getX(o_config.col) - 3;
			var n_y = IceCap.util.Handler.getY(o_config.lin);
			var b_password = o_config.atr == "27";

			if (o_config.len > n_inputWidth) {
				var n_temp = n_inputWidth - o_config.col;
				n_width = (IceCap.util.Handler.getWidth(n_temp) + (IceCap.util.Handler.getWidth() / 2));
			}


			if (o_config.hasOwnProperty("colsize") && o_config.hasOwnProperty("rows")) {

				var s_data = o_config.dta || "";

				o_field.xtype = s_type = "textarea";
				o_field.height = IceCap.util.Handler.getHeight() * o_config.rows;
				o_field.preventScrollbars = true;

				var a_split = s_data.split("\n");

				var s_result = "";

				var n_split = a_split.length;

				Ext.Array.each(a_split, function(s_part, n_index) {

					var regex = new RegExp(".{" + o_config.colsize + "}", "g");

					var a_match = s_part.match(regex);

					if (a_match) {
						s_result += s_part;
					}
					else {
						if (n_index != n_split - 1) {
							s_result += s_part + "\n";
						}
						else {
							s_result += s_part;
						}
					}
				});

				o_config.dta = s_result;


				o_field.getSubmitValue = function() {

					var i_field = this;

					var s_value = i_field.stripReturns(i_field.getRawValue());

					var regex = new RegExp(".{1,"+ o_config.colsize +"}", "g");

					var a_split = s_value.match(regex) || [];

					return a_split.join("\n");
				};

			}

			var o_listeners = Ext.apply({}, o_meta.listeners);
			delete o_meta.listeners;

			var a_field = ["icecap-field", i_self.getTheme()];

			var a_pass = [b_password ? "iceCap-input-password" : "iceCap-input-" + (o_config.atr || 20)];

			a_pass.push(i_self.getTheme());

			var a_cls = [a_field.filter(Boolean).join("-"), a_pass.filter(Boolean).join("-")];

			var s_cls = a_cls.join(" ");

			var s_name = IceCap.util.Handler.getRandomName();

			if (isNaN(n_x)) {
				n_x = IceCap.util.Handler.getColSize();
			}

			if (isNaN(n_y)) {
				n_y = IceCap.util.Handler.getLineHeight();
			}

			var s_ui = b_password ? "icecap-password-field" : "icecap-field";

			if (!o_meta.xtype) {
				Ext.apply(o_field, i_self.applyFFW(o_config));
			}

			var i_field;

			if (o_field.readOnly) {

				o_field.xtype = s_type = "displayfield";
				s_ui = "icecap-display";
				s_cls = (["iceCap-output-" + (o_config.atr || 20), i_self.getTheme()].filter(Boolean).join("-"));

				o_field = {
					autoEl: {
						tag: "span"
					},
					name: s_name,
					html: o_config.dta || "",
					x: n_x,
					y: n_y,
					cls: ["x-form-display-field-icecap-display", s_cls].join(" "),
					style: {
						"white-space": "pre"
					},
					listeners: {
						afterrender: {
							fn: function (i_field) {
								i_field.el.dom.setAttribute("draggable", false);
							}
						}
					}
				};


				if (o_config.atr == "27") {
					o_field.hidden = true;
				}

				if (o_config.atr == "22") {

					Ext.apply(o_field.style, {
						"font-size": (IceCap.util.Handler.getFontSize() - 1) + "px",
						"font-weight": "bold;",
						"letter-spacing": (IceCap.util.Handler.getColSize() - IceCap.util.Handler.getBoldColSize()) + "px",
						"word-spacing": "0.02em;"
					});
				}

				i_field = Ext.widget("component", o_field);

			}
			else {

				Ext.Object.merge(o_field, {
					width: n_width,
					enforceMaxLength: true,
					maxLength: o_config.len,
					minWidth: IceCap.util.Handler.getDefaultWidth(),
					tabIndex: !o_field.readOnly ? n_tabIndex : -1,
					focusable: !o_field.readOnly,
					lin: o_config.lin,
					col: o_config.col,
					emuId: o_config.id,
					value: o_config.dta || "",
					itemId: o_config.id,
					name: s_name,
					inputAttrTpl: "spellcheck=false autocomplete=\"new-password\" name=\"" + s_name  + "\"",
					x: n_x,
					y: n_y,
					cls: s_cls,
					enableKeyEvents: true,
					selectOnFocus: false,
					ui: s_ui,
					listeners: {
						afterrender: {
							fn: function (i_field) {

								if (i_field.inputEl && !i_field.metaField) {

									if (i_field.xtype == "textarea") {
										i_field.inputEl.dom.setAttribute("rows", o_config.rows);
									}

									if (i_field.getTabIndex() === i_self.getNeedFocus()) {

										i_field.focus(false, 10, function () {
											var o_inputData = i_self.getInputData();

											var s_value = i_field.getValue();
											var n_col = i_field.col;
											var n_diff = 0;

											if (n_col < o_inputData.csrCol) {
												n_diff = o_inputData.csrCol - n_col;
												i_field.inputEl.el.dom.selectionEnd = i_field.inputEl.el.dom.selectionStart = i_field.inputEl.el.dom.selectionStart + n_diff;
											}

											var o_position = {
												col: o_inputData.csrCol,
												lin: o_inputData.csrLin
											};

											i_self.setCurrentPosition(o_position);

											var i_cursor = i_self.getCursor();
											i_cursor.moveCursor(o_position);
											i_cursor.hide();
										});
									}
								}
							}
						},
						change: {
							fn: function (i_field, value) {

								var s_direction = i_field.inputEl.el.dom.selectionDirection;

								var n_curpos = s_direction == "forward" ? i_field.inputEl.el.dom.selectionEnd : i_field.inputEl.el.dom.selectionStart;

								value = value || "";

								if (value.length == i_field.maxLength && n_curpos == i_field.maxLength) {
									i_self.doNavigationKey(1, true);
								}
							}
						},
						focus: {
							fn: function (i_field) {

								var n_tabIndex = i_field.getTabIndex();
								i_self.setCurrentTabIndex(n_tabIndex);

								var o_position = {
									col: i_field.col,
									lin: i_field.lin
								};
								i_self.setCurrentPosition(o_position);

								var i_cursor = i_self.getCursor();
								i_cursor.moveCursor(o_position);
								i_cursor.hide();
							}
						},
						keyup: {
							fn: function (i_field, i_event) {

								if (i_field.xtype === "icecap-input") {

									var value = i_field.getValue();

									var s_direction = i_field.inputEl.el.dom.selectionDirection;

									var n_start = s_direction == "forward" ? i_field.inputEl.el.dom.selectionEnd : i_field.inputEl.el.dom.selectionStart;
									var n_add = value.length * IceCap.util.Handler.getWidth();

									if (n_start != value.length) {
										n_add = n_start * IceCap.util.Handler.getWidth();
									}

									var o_input = Ext.apply({
										x: i_field.getLocalX() + n_add,
										y: i_field.getLocalY()
									});

									var o_position = IceCap.util.Handler.toColAndLine(o_input);
									i_self.setCurrentPosition(o_position);

									var i_cursor = i_self.getCursor();
									i_cursor.moveCursor(o_position);
								}
							}
						},
						keydown: {
							fn: function (i_field, i_event) {

								var i_regext = new RegExp("^\\w{1}$");

								var value = i_field.getValue();

								if (i_event.ctrlKey) {

									var o_input = {};
									var o_position = {};
									var o_box = {};
									var i_main = i_self.getMain();
									var i_cursor = i_self.getCursor();
									var a_inputs = IceCap.util.Handler.getInputFields(i_self);
									var b_intersect = false;
									var n_selection = 0;

									var i_inputEl = i_field.inputEl;

									if (i_event.keyCode == Ext.event.Event.DOWN ||
										i_event.keyCode == Ext.event.Event.UP) {

										n_selection = i_inputEl.dom.selectionEnd;

										i_event.stopEvent();

										o_position = {
											col: i_field.col + n_selection,
											lin: i_field.lin
										};

										if (i_event.keyCode == Ext.event.Event.DOWN) {
											o_position.lin++;
										}
										else {
											o_position.lin--;
										}

										i_self.setCurrentPosition(o_position);

										i_cursor.moveCursor(o_position);

										o_input = {
											x: IceCap.util.Handler.getX(o_position.col),
											y: IceCap.util.Handler.getY(o_position.lin)
										};

										Ext.apply(o_box, {
											width: i_cursor.getWidth(),
											height: i_cursor.getHeight()
										}, o_input);

										Ext.Array.each(a_inputs, function (i_field) {

											var o_bound = i_field.el.dom.getBoundingClientRect();

											var o_rect = Ext.apply({}, {
												x: i_field.getLocalX(),
												y: i_field.getLocalY(),
												width: o_bound.width,
												height: o_bound.height
											});

											if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
												b_intersect = true;
												i_field.focus(false, 10);
												return false;
											}
										});

										if (!b_intersect) {

											i_field.blur();
											i_cursor.show();

											i_main.focus(true, 10);
										}
									}
									if (i_event.keyCode == Ext.event.Event.LEFT ||
										i_event.keyCode == Ext.event.Event.RIGHT) {

										n_selection = i_event.keyCode == Ext.event.Event.LEFT ? i_inputEl.dom.selectionStart : i_inputEl.dom.selectionEnd;

										i_event.stopEvent();

										if (n_selection === 0 && i_event.keyCode === Ext.event.Event.LEFT) {

											o_position = {
												col: i_field.col,
												lin: i_field.lin
											};

											o_position.col--;

											o_input = {
												x: IceCap.util.Handler.getX(o_position.col),
												y: IceCap.util.Handler.getY(o_position.lin)
											};

											i_self.setCurrentPosition(o_position);

											i_cursor.moveCursor(o_position);

											Ext.apply(o_box, {
												width: i_cursor.getWidth(),
												height: i_cursor.getHeight()
											}, o_input);


											Ext.Array.each(a_inputs, function (i_field) {

												var o_bound = i_field.el.dom.getBoundingClientRect();

												var o_rect = Ext.apply({}, {
													x: IceCap.util.Handler.getX(i_field.col),
													y: IceCap.util.Handler.getY(i_field.lin),
													width: o_bound.width,
													height: o_bound.height
												});

												if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
													b_intersect = true;
													i_field.focus(false, 10);
													return false;
												}
											});

											if (!b_intersect) {

												i_field.blur();
												i_cursor.show();

												i_main.focus(true, 10);
											}
										}
										else if (n_selection == value.length && i_event.keyCode == Ext.event.Event.RIGHT) {

											o_position = {
												col: i_field.col + i_field.maxLength,
												lin: i_field.lin
											};

											if (o_position.col > o_inputData.width) {
												o_position.col = o_inputData.width;
											}

											o_position.col++;

											o_input = {
												x: IceCap.util.Handler.getX(o_position.col),
												y: IceCap.util.Handler.getY(o_position.lin)
											};


											i_self.setCurrentPosition(o_position);
											i_cursor.moveCursor(o_position);

											Ext.apply(o_box, {
												width: i_cursor.getWidth(),
												height: i_cursor.getHeight()
											}, o_input);

											Ext.Array.each(a_inputs, function (i_field) {

												var o_bound = i_field.el.dom.getBoundingClientRect();

												var o_rect = Ext.apply({}, {
													x: IceCap.util.Handler.getX(i_field.col),
													y: IceCap.util.Handler.getY(i_field.lin),
													width: o_bound.width,
													height: o_bound.height
												});

												if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
													b_intersect = true;
													i_field.focus(false, 10);
													return false;
												}
											});

											if (!b_intersect) {

												i_field.blur();
												i_cursor.show();

												i_main.focus(true, 10);
											}
										}
									}
								}
								else {

									if (i_field.xtype == "textarea") {

										if (i_event.keyCode == Ext.event.Event.UP) {

											var s_value = i_field.stripReturns(i_field.getRawValue());

											var regex = new RegExp("^.*\n$|.{1," + o_config.colsize + "}", "gm");

											var a_lines = s_value.match(regex) || [];
											var a_newLines = s_value.split("\n");

											var n_start = i_field.inputEl.dom.selectionStart;

											var n_row = 1;
											var n_char = 0;
											var b_last = i_field.inputEl.dom.selectionStart == i_field.inputEl.dom.value.length;

											Ext.Array.each(a_lines, function (s_part, n_index) {

												n_char += s_part.length;

												if (n_char <= n_start) {
													n_row++;
												}
												else {
													return false;
												}
											});

											if (n_row > 1) {

												i_event.stopEvent();

												n_char = 0;
												var n_left = 0;
												var n_current = 0;
												var n_nextLine = 0;

												n_start = n_start - (a_newLines.length - 1);

												Ext.Array.each(a_lines, function (s_part, n_index) {

													n_char += s_part.length;

													var n_count = 0;

													n_left = 0;

													while (n_count < s_part.length) {
														n_count++;
														if (n_current < n_start) {
															n_current++;
															n_left++;
														}
													}

													if (n_char < n_start) {
														n_row++;
													}
													else {
														n_nextLine = n_index - 1;
														return false;
													}
												});

												if (n_nextLine == -1) {
													n_nextLine = 0;
												}

												var n_newPos = 0;

												Ext.Array.each(a_lines, function (s_part, n_index) {

													if (n_index < n_nextLine) {
														n_newPos += s_part.length;
													}
													else {
														n_newPos += n_left;
														return false;
													}
												});

												i_event.stopEvent();
												i_field.inputEl.dom.setSelectionRange(n_newPos, n_newPos);
											}
										}

										if (i_event.keyCode == Ext.event.Event.DOWN) {

											var s_value = i_field.stripReturns(i_field.getRawValue());
											var n_length = s_value.length;

											var regex = new RegExp("^.*\n$|.{1," + o_config.colsize + "}", "g");
											var n_pos = i_field.inputEl.dom.selectionStart;

											var a_lines = s_value.match(regex) || [];
											var a_newLines = s_value.split("\n");

											if (a_lines.length < o_config.rows && a_newLines.length < o_config.rows) {

												i_event.stopEvent();

												s_value = s_value + "\n";

												i_field.setValue(s_value);

												i_field.inputEl.dom.setSelectionRange(s_value.length, s_value.length);
											}
											else {
												var n_row = 1;
												var n_char = 0;
												var n_left = 0;
												var n_current = 0;
												var n_nextLine = 0;

												Ext.Array.each(a_lines, function (s_part, n_index) {

													n_char += s_part.length;

													var n_count = 0;

													n_left = 0;

													while (n_count < s_part.length) {
														n_count++;
														if (n_current < n_pos) {
															n_current++;
															n_left++;
														}
													}

													if (n_char <= n_pos) {
														n_row++;
													}
													else {
														n_nextLine = n_index + 1;
														return false;
													}
												});

												if (n_nextLine < a_lines.length || n_nextLine < a_newLines.length) {

													var n_newPos = 0;

													Ext.Array.each(a_lines, function (s_part, n_index) {

														if (n_index < n_nextLine) {
															n_newPos += s_part.length;
														}
														else {
															n_newPos += n_left + (a_newLines.length - 1);
															return false;
														}
													});

													if (n_row < o_config.rows) {
														i_event.stopEvent();
														i_field.inputEl.dom.setSelectionRange(n_newPos, n_newPos);
													}
												}
											}

										}
									}
									else if (i_field.xtype == "icecap-input") {

										var n_typeMode = i_self.getTypeMode();

										if (n_typeMode == IceCap.util.Handler.typeMode.OVERWRITE) {

											var s_direction = i_field.inputEl.el.dom.selectionDirection;

											var n_curpos = s_direction == "forward" ? i_field.inputEl.el.dom.selectionEnd : i_field.inputEl.el.dom.selectionStart;

											var s_key = String.fromCharCode(i_event.keyCode);

											if (n_curpos < value.length && i_regext.test(s_key)) {

												var a_values = value.split("");
												a_values[n_curpos] = i_event.browserEvent.key;
												value = a_values.join("");
												i_field.setValue(value);
												i_field.inputEl.el.dom.selectionEnd = i_field.inputEl.el.dom.selectionStart = n_curpos + 1;
												i_event.stopEvent();
											}
										}
									}
								}
							}
						}
					}
				}, o_meta);

				var o_clone = Ext.clone(o_field);

				if (o_meta.xtype) {

					o_clone.metaField = true;

					o_clone.xtype = s_type = o_meta.xtype;

					delete o_clone.cls;
					delete o_clone.fieldStyle;
					delete o_clone.inputType;
					delete o_clone.ui;
				}

				if (o_config.type == "grid") {

					s_type = "iceCapGrid";

					Ext.apply(o_clone, {
						xtype: s_type,
						gridConfig: o_config.grid,
						width: IceCap.util.Handler.getWidth(n_inputWidth)
					});

					delete o_clone.cls;
					delete o_clone.fieldStyle;
					delete o_clone.inputType;
					delete o_clone.listeners;
					delete o_clone.grid;

					Ext.apply(o_clone, {
						listeners: {
							fieldoption: {
								fn: function (a_config) {
									i_self.fireEvent("fieldoption", a_config);
								}
							},
							key: {
								fn: function (s_key) {
									i_self.fireEvent("key", s_key);
								}
							}
						}
					});
				}

				i_field = Ext.widget(s_type, o_clone);

				var o_on = {};

				Ext.Object.each(o_listeners, function (s_key, value) {

					if (Ext.isFunction(value)) {
						o_on[s_key] = Ext.apply({}, {
							fn: value,
							scope: i_self
						});
					}
					else if (Ext.isObject(value)) {
						value.scope = i_self;
						o_on[s_key] = value;
					}
				});

				i_field.on(o_on);
			}

			if (!i_field.readOnly) {
				n_tabIndex++;
			}

			if (o_config.atr == 25) {

				if (o_field.readOnly) {
					i_field.addCls("icecap-invalid");
				}
				else {
					i_field.markInvalid(true);
				}
			}

			a_fields.push(i_field);
		});

		n_tabIndex = n_tabIndex - 1;
		i_self.setLastTabIndex(n_tabIndex);
		i_self.setCurrentTabIndex(o_inputData.focus);

		i_self.setNeedFocus(n_focus);

		return a_fields;
	},

	createLabels: function() {

		var i_self = this;
		var o_inputData = i_self.getInputData();

		var i_cssRule = IceCap.util.Handler.getCssRule();
		var o_style = i_cssRule.style;

		var a_fields = [];

		if (!i_self.getEdit()) {


			var a_lines = [];
			var a_temp = [];

			Ext.Array.each(o_inputData.output, function (o_config) {

				var o_line = Ext.Array.findBy(a_lines, function (o_line) {
					return o_line.lin == o_config.lin;
				});

				if (o_line) {
					o_line.items.push(o_config);
				}
				else {
					o_line = {
						items: [o_config],
						lin: o_config.lin,
						col: o_config.col
					};

					a_lines.push(o_line);
				}
			});

			Ext.Array.each(a_lines, function (o_line) {

				var a_items = [];

				Ext.Array.each(o_line.items, function (o_item) {

					var o_atr = Ext.Array.findBy(a_items, function (o_atr) {
						return (o_atr.atr || "") == (o_item.atr || "");
					});

					if (!o_atr) {
						o_atr = {
							lin: o_item.lin,
							items: [o_item],
							atr: o_item.atr || ""
						};

						a_items.push(o_atr);
					}
					else {
						o_atr.items.push(o_item);
					}
				});

				o_line.atr = a_items;
			});

			Ext.Array.each(a_lines, function (o_line) {

				Ext.Array.each(o_line.atr, function (o_atr) {

					var n_col = 0;
					var n_current = 0;
					var s_value = "";

					var o_field = {
						value: ""
					};

					Ext.Array.each(o_atr.items, function (o_config) {

						var s_data = o_config.dta || o_config.label || o_config.text || "";

						if (o_config.off) {
							s_data = Ext.String.leftPad(s_data, s_data.length + o_config.off);
						}

						if (n_col === 0) {

							n_col = o_config.col;
							n_current = n_col + s_data.length;
							s_value = s_data;
						}
						else {

							var n_diff = o_config.col - n_current;

							if (n_diff > 0) {
								s_data = Ext.String.leftPad(s_data, s_data.length + n_diff);
							}

							n_current = n_current + s_data.length;

							s_value = s_value + s_data;
						}
					});

					Ext.apply(o_field, {
						col: n_col,
						lin: o_line.lin,
						value: s_value,
						atr: o_atr.atr
					});

					a_temp.push(o_field);
				});
			});

			Ext.Array.each(a_temp, function (o_config) {

				var s_value = o_config.value;

				if (s_value) {

					var n_x = IceCap.util.Handler.getX(o_config.col);
					var n_y = IceCap.util.Handler.getY(o_config.lin);

					var s_cls = (["iceCap-output-" + (o_config.atr || 20), i_self.getTheme()].filter(Boolean).join("-"));

					var o_field = {
						autoEl: {
							tag: "span"
						},
						html: s_value,
						x: n_x,
						y: n_y,
						cls: ["x-form-display-field-icecap-display", s_cls].join(" "),
						style: {
							"white-space": "pre"
						},
						listeners: {
							afterrender: {
								fn: function (i_field) {
									i_field.el.dom.setAttribute("draggable", false);
								}
							}
						}
					};


					if (o_config.atr == "27") {
						o_field.hidden = true;
					}

					if (o_config.atr == "22") {

						Ext.apply(o_field.style, {
							"font-size": (IceCap.util.Handler.getFontSize() - 1) + "px",
							"font-weight": "bold;",
							"letter-spacing": (IceCap.util.Handler.getColSize() - IceCap.util.Handler.getBoldColSize()) + "px",
							"word-spacing": "0.02em;"
						});
					}

					var i_field = Ext.widget("component", o_field);
					a_fields.push(i_field);
				}
			});
		}
		else {

			var editor = new Ext.Editor({
				updateEl: true,
				alignment: "l-l",
				autoSize: {
					width: "boundEl"
				},
				field: {
					xtype: "textfield",
					ui: "icecap-field"
				}
			});

			Ext.Array.each(o_inputData.output, function (o_config) {

				var s_value = o_config.dta || "";

				if (s_value) {

					var n_x = IceCap.util.Handler.getX(o_config.col);
					var n_y = IceCap.util.Handler.getY(o_config.lin);

					var s_cls = (["iceCap-output-" + (o_config.atr || 20), i_self.getTheme()].filter(Boolean).join("-"));

					var o_field = {
						autoEl: {
							tag: "span"
						},
						html: s_value,
						x: n_x,
						y: n_y,
						cls: ["x-form-display-field-icecap-display", s_cls].join(" "),
						style: {
							"white-space": "pre"
						},
						listeners: {
							mouseover: {
								element: "el",
								fn: function() {

									var i_element = this;
									i_element.addCls("x-base-background-color");
								}
							},
							mouseout: {
								element: "el",
								fn: function() {

									var i_element = this;
									i_element.removeCls("x-base-background-color");
								}
							},
							afterrender: {
								fn: function (i_field) {
									i_field.el.dom.setAttribute("draggable", false);

									var i_tpl = Ext.create("Ext.XTemplate",
										"<div style=\"width: 300px; overflow:hidden; white-space:nowrap;\">",
											"<div>Lin: {lin}</div>",
											"<div>Col: {col}</div>",
											"<div>Color: {color}</div>",
											"<div style=\"overflow:hidden; white-space: nowrap; text-overflow:ellipsis;\">Font: {font}</div>",
										"</div>"
									);

									Ext.create("Ext.tip.ToolTip", {
										target: i_field.el,
										html: "",
										anchor: true,
										defealtAlign: "b0-t0",
										listeners: {
											beforeshow: {
												fn: function (i_tip) {

													var o_data = {
														lin: o_config.lin,
														col: o_config.col,
														color: o_style.color,
														font: [
															o_style.fontSize,
															o_style.fontFamily
														].join(" ")
													};

													var s_value = i_tpl.apply(o_data);
													i_tip.update(s_value);
												}
											}
										}
									});
								}
							}
						}
					};


					if (o_config.atr == "27") {
						o_field.hidden = true;
					}

					if (o_config.atr == "22") {

						Ext.apply(o_field.style, {
							"font-size": (IceCap.util.Handler.getFontSize() - 1) + "px",
							"font-weight": "bold;",
							"letter-spacing": (IceCap.util.Handler.getColSize() - IceCap.util.Handler.getBoldColSize()) + "px",
							"word-spacing": "0.02em;"
						});
					}

					var i_field = Ext.widget("component", o_field);
					a_fields.push(i_field);

					i_field.on({
						afterrender: {
							fn: function(i_field) {
								i_field.el.on({
									click: {
										fn: function() {
											editor.startEdit(i_field.getEl());
											editor.field.focus(50, false);
										}
									}
								});
							}
						}
					});
				}
			});
		}

		return a_fields;
	},

	createMetaFields: function() {

		var i_self = this;
		var o_inputData = i_self.getInputData();

		var a_fields = [];
		var n_tabIndex = i_self.getLastTabIndex() || 0;

		var a_sliced = Ext.Array.slice(o_inputData.metaFields || []);

		Ext.Array.each(a_sliced, function(o_config) {

			var n_x = o_config.x;
			var n_y = o_config.y;

			if (!o_config.x) {
				n_x = IceCap.util.Handler.getX(o_config.col);
			}

			if (!o_config.y) {
				n_y = IceCap.util.Handler.getY(o_config.lin);
			}

			if (isNaN(n_x)) {
				n_x = IceCap.util.Handler.getColSize();
			}

			if (isNaN(n_y)) {
				n_y = IceCap.util.Handler.getHeight();
			}

			var o_listeners = o_config.listeners || {};

			Ext.apply(o_config, {
				tabIndex: n_tabIndex + 1,
				keys: Ext.Array.slice(o_inputData.keys),
				theme: i_self.getTheme(),
				x: n_x,
				y: n_y,
				listeners: {
					fieldoption: {
						fn: function(a_config) {
							i_self.fireEvent("fieldoption", a_config);
						}
					},
					key: {
						fn: function(s_key) {
							i_self.fireEvent("key", s_key);
						}
					}
				}
			});

			o_config.xtype = o_config.xtype || o_config.type || "icecap-input";

			o_config.name = o_config.id;

			delete o_config.id;

			var i_field = Ext.widget(o_config.xtype, o_config);

			var o_on = {};

			if (!Ext.Object.isEmpty(o_listeners)) {

				Ext.Object.each(o_listeners, function(s_key, value) {

					if (Ext.isFunction(value)) {
						o_on[s_key] = Ext.apply({}, {
							fn: value,
							scope: i_self
						});
					}
					else if (Ext.isObject(value)) {
						value.scope = i_self;
						o_on[s_key] = value;
					}
				});
			}

			i_field.on(o_on);

			a_fields.push(i_field);

			n_tabIndex++;
		});

		i_self.setLastTabIndex(n_tabIndex);

		return a_fields;
	},

	createKeys: function() {

		var i_self = this;
		var o_inputData = i_self.getInputData();
		var a_disabledKey = o_inputData.disabledKeys || [];
		var a_buttons = [];

		var i_template = Ext.create("Ext.XTemplate",
			"{id}={text}"
		);

		Ext.Array.each(o_inputData.keys, function(o_config) {

			var s_template = i_template.apply(o_config);

			var o_found = Ext.Array.findBy(a_disabledKey, function(o_disabled) {
				return o_config.id == o_disabled.id;
			});

			o_found = o_found || {
				showKey: 1
			};

			var b_hidden = Number(o_found.showKey) < 1  || false;

			var i_button = Ext.widget("button", {
				text: s_template,
				key: o_config.id,
				focusable: false,
				hidden: b_hidden,
				handler: function(i_button) {
					i_self.doKeyEvent(i_button.key);
				}
			});

			a_buttons.push(i_button);
		});

		return a_buttons;
	},

	doCreateFromData: function(o_inputData) {

		var i_self = this;
		var i_controller = i_self.getController();

		i_self.setInputData(o_inputData);
		i_self.splitFields();

		var b_fixed = o_inputData.hasOwnProperty("fixed") ? o_inputData.fixed : true;

		IceCap.util.Handler.setFixed(b_fixed);

		var a_fields = [];
		var i_content;

		i_self.suspendLayouts();

		if (o_inputData.window && o_inputData.window.level > 0) {
			if (i_self.rendered) {
				i_self.mask(false);
				i_self.createWindow(o_inputData);
			}
		}
		else {

			if (i_self.rendered) {
				i_self.unmask();
			}

			if (o_inputData.title) {
				i_self.doTitleUpdate(o_inputData.title);
			}

			i_content = i_self.getContent();

			if (i_self.getResizeMode() == 2) {

				i_content.setSize({
					width: IceCap.util.Handler.getWidth(o_inputData.width + 7 || 87),
					height: IceCap.util.Handler.getHeight(o_inputData.height || 24)
				});
			}

			var i_keyArea = i_self.getKeyArea();

			if (i_content.rendered) {
				i_content.removeAll(true);
			}

			if (i_keyArea.rendered) {
				i_keyArea.removeAll(true);
			}

			i_self.setCursor(null);
			i_self.setMarker(null);

			var a_created = [];
			a_created = a_created.concat(i_self.createLabels());
			a_created = a_created.concat(i_self.createFields());
			a_created = a_created.concat(i_self.createMetaFields());

			a_created.push(i_self.createCursor());
			a_created.push(i_self.createMarker());

			if (o_inputData.processedFields) {

				var a_toAdd = Ext.Array.slice(a_created);

				var n_inputWidth = o_inputData.width || 80;
				var n_inputHeight = o_inputData.height || 24;

				var i_container = Ext.widget("container", {
					layout: "anchor",
					width: IceCap.util.Handler.getWidth(n_inputWidth),
					height: IceCap.util.Handler.getHeight(n_inputHeight),
					focusable: false,
					tabIndex: -1,
					defaults: {
						margin: "5 0 0 0"
					},
					items: a_toAdd
				});

				a_created = [i_container];
			}

			i_content.add(a_created);

			i_self.updateMessage(o_inputData);

			var a_keys = i_self.createKeys();
			i_keyArea.add(a_keys);

			i_keyArea[a_keys.length === 0 ? "hide" : "show"]();

			if (o_inputData.cmd) {

				i_controller.onPCO(o_inputData);
				i_controller.doKeyEvent("ENTER");
			}

			var i_marker = i_self.getMarker();
			i_marker.setInUse(i_self.getMarkerActive());
		}

		IceCap.util.Handler.setFixed(true);

		i_self.resumeLayouts(true);

		if (i_content) {
			a_fields = IceCap.util.Handler.getInputFields(i_content);

			var b_found = false;
			var b_error = false;

			if (o_inputData.msgBox && o_inputData.msgBox.text) {
				b_error = true;
			}

			if (a_fields.length > 0) {

				b_found = Ext.Array.findBy(a_fields, function (i_field) {
					return i_field.getTabIndex() === i_self.getNeedFocus();
				});
			}

			if (!b_found) {

				i_self.setCurrentPosition({
					col: o_inputData.csrCol || 1,
					lin: o_inputData.csrLin || 1
				});
			}

			if (b_error) {
				i_self.onError(o_inputData);
			}
			else {
				i_self.findFocus();
			}
		}


		var a_metafields = o_inputData.metaFields || [];

		if (
			o_inputData.input.length === 0 &&
			o_inputData.input.length === 0 &&
			a_metafields.length === 0 && o_inputData.messageText) {

				var s_message = o_inputData.messageText;

				i_self.setMessageText(s_message);

				i_self.setLoading(s_message);
				i_controller.onSendData({
					func: ""
				}, {});
		}
	},

	createWindow: function(o_inputData) {

		var i_self = this;
		var o_config = o_inputData.window;
		var i_active = i_self.getActiveWindow();

		var i_content = i_self.getContent();

		if (o_config.width < 80) {
			o_config.width = 80;
		}

		var o_size = {
			width: IceCap.util.Handler.getWidth(o_config.width),
			height: IceCap.util.Handler.getHeight(o_config.height)
		};

		if (i_active) {

			i_active.hide();

			i_active.setHeight(null);
			i_active.setWidth(null);

			i_active.setTitle(o_config.title);

			i_active.getContent().setSize(o_size);

			i_active.setInputData(o_inputData);

			i_active.show();

			i_active.recreate();
		}
		else {

			i_active = Ext.create("IceCap.view.Window", {
				title: o_config.title,
				inputData: o_inputData,
				sessionValue: i_self.getSessionValue(),
				modal: false,
				onEsc: Ext.emptyFn,
				theme: i_self.getTheme(),
				markerActive: i_self.getMarkerActive(),
				options: i_self.getOptions(),
				ui: "icecap-window",
				bodyCls: ["icecap-window", i_self.getTheme()].join("-"),
				constrainHeader: true,
				typeMode: i_self.getTypeMode(),
				listeners: {
					destroy: {
						fn: function(i_window) {
							i_self.setActiveWindow(null);
						}
					},
					toWindow: {
						fn: function(i_window, o_inputData) {
							if (!o_inputData.close) {
								i_self.doCreateFromData(o_inputData);
								if (o_inputData.window && !o_inputData.window.level) {
									i_window.close();
								}
							}
							else {
								i_window.close();
								i_self.close();
							}
						}
					}
				}
			});

			i_content.add(i_active);

			i_active.getContent().setSize(o_size);

			i_active.show();

			var b_center = false;

			if (i_active.getSize().width > window.screen.width) {
				i_active.setWidth(window.screen.width);
				b_center = true;
			}

			if (i_active.getSize().height > window.screen.height) {
				i_active.setHeight(window.screen.height);
				b_center = true;
			}

			if (b_center) {
				i_active.center();
			}
		}

		i_self.setActiveWindow(i_active);

		var i_query = Ext.get(i_self.getMaskTarget().query(".x-mask"));

		Ext.Array.each(i_query.elements, function(i_mask) {
			Ext.get(i_mask).setStyle("opacity", 0);
		});
	},

	getCurrentField: function() {

		var i_self = this;

		var a_fields = IceCap.util.Handler.getInputFields(i_self);
		var n_tabIndex = i_self.getCurrentTabIndex();

		var i_currentField;

		Ext.Array.each(a_fields, function(i_field) {
			if (i_field.getTabIndex() === n_tabIndex && i_field.hasFocus) {
				i_currentField = i_field;
				return false;
			}
		});

		return i_currentField;
	},

	doKeyEvent: function(s_value) {

		var i_self = this;

		var i_controller = i_self.getController();

		var o_inputData = i_self.getInputData() || {};

		var a_disabledKeys = Ext.Array.from(o_inputData.disabledKeys || []);

		var o_found = Ext.Array.findBy(a_disabledKeys, function(o_key) {
			return s_value == o_key.id;
		});

		if (!o_found)  {
			i_controller.doKeyEvent(s_value);
		}
		else {

			IceCap.util.Handler.messageBox({
				title: "Error",
				msg: "Funktionstasten er ikke tilladt",
				yesText: "Ok",
				yesFn: function () {
					i_self.findFocus();
				}
			});
		}
	},

	doNavigationKey: function(n_direction, b_tab) {

		var i_self = this;
		var i_controller = i_self.getController();
		i_controller[b_tab ? "doTabKey" : "doArrowKeys"](n_direction);
	},

	addKeyEvents: function() {

		var i_self = this;

		var a_bindings = [
			{
				key: Ext.event.Event.PAGE_DOWN,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;
					i_self.doKeyEvent("ROLLUP");
				}
			},
			{
				key: Ext.event.Event.PAGE_UP,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;
					i_self.doKeyEvent("ROLLDOWN");
				}
			},
			{
				key: Ext.event.Event.ENTER,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;
					i_self.doKeyEvent("ENTER");
				}
			},
			{
				key: Ext.event.Event.ESC,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;
					i_self.doKeyEvent("ATTN");
				}
			},
			{
				key: Ext.event.Event.UP,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {

						if (!i_event.target.type) {

							i_event.stopEvent();

							var i_cursor = i_self.getCursor();
							var o_position = i_self.getCurrentPosition();

							var a_inputs = IceCap.util.Handler.getInputFields(i_self);

							o_position.lin--;

							if (o_position.lin < 1) {
								o_position.lin = 1;
							}

							var o_box = Ext.apply({
								x: IceCap.util.Handler.getX(o_position.col),
								y: IceCap.util.Handler.getY(o_position.lin),
								width: IceCap.util.Handler.getColSize(),
								height: 1
							});

							var b_intersect = false;

							Ext.Array.each(a_inputs, function(i_field) {

								var o_bound = i_field.el.dom.getBoundingClientRect();

								var o_rect = Ext.apply({}, {
									x: IceCap.util.Handler.getX(i_field.col),
									y: IceCap.util.Handler.getY(i_field.lin),
									width: o_bound.width,
									height: o_bound.height
								});

								if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {

									b_intersect = true;
									i_field.focus(false, 10);

									var n_start = o_position.col - i_field.col;
									var i_inputEl = i_field.inputEl;
									i_inputEl.dom.selectionStart = i_inputEl.dom.selectionEnd = n_start;

									return false;
								}
							});

							if (!b_intersect) {
								i_cursor.moveCursor(o_position);
							}
							i_self.setCurrentPosition(o_position);
						}
						else {
							i_self.doNavigationKey(0);
						}
					}
				}
			},
			{
				key: Ext.event.Event.DOWN,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {

						if (!i_event.target.type) {

							i_event.stopEvent();

							var i_cursor = i_self.getCursor();
							var o_position = i_self.getCurrentPosition();
							var o_inputData = i_self.getInputData();

							var a_inputs = IceCap.util.Handler.getInputFields(i_self);

							o_position.lin++;

							if (o_position.lin > o_inputData.height) {
								o_position.lin = o_inputData.height;
							}

							var o_box = Ext.apply({
								x: IceCap.util.Handler.getX(o_position.col),
								y: IceCap.util.Handler.getY(o_position.lin),
								width: i_cursor.getWidth(),
								height: i_cursor.getHeight()
							});


							var b_intersect = false;

							Ext.Array.each(a_inputs, function(i_field) {

								var o_bound = i_field.el.dom.getBoundingClientRect();


								var o_rect = Ext.apply({}, {
									x: IceCap.util.Handler.getX(i_field.col),
									y: IceCap.util.Handler.getY(i_field.lin),
									width: o_bound.width,
									height: o_bound.height
								});

								if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {

									b_intersect = true;
									i_field.focus(false, 10);

									var n_start = o_position.col - i_field.col;
									var i_inputEl = i_field.inputEl;
									i_inputEl.dom.selectionStart = i_inputEl.dom.selectionEnd = n_start;

									return false;
								}
							});

							if (!b_intersect) {
								i_cursor.moveCursor(o_position);
							}
							i_self.setCurrentPosition(o_position);
						}
						else {
							i_self.doNavigationKey(1);
						}
					}
				}
			},
			{
				key: Ext.event.Event.LEFT,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {
						if (!i_event.target.type) {
							i_event.stopEvent();

							var i_cursor = i_self.getCursor();
							var o_position = i_self.getCurrentPosition();

							var a_inputs = IceCap.util.Handler.getInputFields(i_self);

							o_position.col--;

							if (o_position.col < 1) {
								o_position.col = 1;
							}

							var o_box = Ext.apply({
								x: IceCap.util.Handler.getX(o_position.col),
								y: IceCap.util.Handler.getY(o_position.lin),
								width: i_cursor.getWidth(),
								height: i_cursor.getHeight()
							});


							var b_intersect = false;

							Ext.Array.each(a_inputs, function(i_field) {

								var o_bound = i_field.el.dom.getBoundingClientRect();

								var o_rect = Ext.apply({}, {
									x: IceCap.util.Handler.getX(i_field.col),
									y: IceCap.util.Handler.getY(i_field.lin),
									width: o_bound.width,
									height: o_bound.height
								});

								if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
									b_intersect = true;
									i_field.focus(false, 10);
									return false;
								}
							});

							if (!b_intersect) {
								i_cursor.moveCursor(o_position);
							}

							i_self.setCurrentPosition(o_position);
						}
					}
				}
			},
			{
				key: Ext.event.Event.RIGHT,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {
						if (!i_event.target.type) {

							i_event.stopEvent();

							var i_cursor = i_self.getCursor();
							var o_position = i_self.getCurrentPosition();
							var o_inputData = i_self.getInputData();

							var a_inputs = IceCap.util.Handler.getInputFields(i_self);

							o_position.col++;

							if (o_position.col > o_inputData.width) {
								o_position.col = o_inputData.width;
							}

							var o_box = Ext.apply({
								x: IceCap.util.Handler.getX(o_position.col),
								y: IceCap.util.Handler.getY(o_position.lin),
								width: i_cursor.getWidth(),
								height: i_cursor.getHeight()
							});

							var b_intersect = false;

							Ext.Array.each(a_inputs, function(i_field) {

								var o_bound = i_field.el.dom.getBoundingClientRect();

								var o_rect = Ext.apply({}, {
									x: IceCap.util.Handler.getX(i_field.col),
									y: IceCap.util.Handler.getY(i_field.lin),
									width: o_bound.width,
									height: o_bound.height
								});

								if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
									b_intersect = true;
									i_field.focus(false, 10);
									return false;
								}
							});

							if (!b_intersect) {
								i_cursor.moveCursor(o_position);
							}

							i_self.setCurrentPosition(o_position);
						}
					}
				}
			},
			{
				key: Ext.event.Event.TAB,
				shift: false,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {
						i_event.stopEvent();
						i_event.stopPropagation();

						i_self.doNavigationKey(1, true);
					}


				}
			},
			{
				key: Ext.event.Event.TAB,
				shift: true,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {
						i_event.stopEvent();
						i_event.stopPropagation();

						i_self.doNavigationKey(0, true);
					}
				}
			},
			{
				key: Ext.event.Event.NUM_PLUS,
				fn: function(n_key, i_event) {

					i_event.stopEvent();

					var i_key = this;
					var i_self = i_key.target.component;

					var i_field = i_self.getCurrentField();

					if (i_field) {

						var n_start = i_field.inputEl.el.dom.selectionStart;

						var s_text = i_field.getValue();

						s_text = s_text.substr(0, n_start);

						i_field.setValue(s_text);

						i_self.doNavigationKey(1, true);
					}
				}
			},
			{
				key: Ext.event.Event.HOME,
				ctrl: true,
				alt: false,
				fn: function(n_key, i_event) {

					i_event.stopEvent();

					var i_key = this;
					var i_self = i_key.target.component;

					var b_markerActive = i_self.getMarkerActive();
					var i_marker = i_self.getMarker();

					i_self.setMarkerActive(!b_markerActive);

					i_marker.toggle();
				}
			},
			{
				key: Ext.event.Event.INSERT,
				ctrl: false,
				alt: false,
				fn: function (n_key, i_event) {

					var n_type = i_self.getTypeMode();
					switch (n_type) {
						case IceCap.util.Handler.typeMode.OVERWRITE:
							n_type = IceCap.util.Handler.typeMode.INSERT;
							break;
						default:
							n_type = IceCap.util.Handler.typeMode.OVERWRITE;
							break;
					}

					i_self.setTypeMode(n_type);
				}
			}
		];

		a_bindings = a_bindings.concat(i_self.getFKeys());

		var i_keyMap = Ext.create("Ext.util.KeyMap", {
			target: i_self.getEl(),
			binding: a_bindings
		});
	},

	getFKeys: function() {

		var i_self = this;

		var a_keys = [
			{
				key: Ext.event.Event.F1,
				shift: false,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F1");
				}
			},
			{
				key: Ext.event.Event.F2,
				shift: false,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F2");
				}
			},
			{
				key: Ext.event.Event.F3,
				shift: false,
				alt: false,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F3");
				}
			},
			{
				key: Ext.event.Event.F4,
				shift: false,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F4");
				}
			},
			{
				key: Ext.event.Event.F5,
				shift: false,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F5");
				}
			},
			{
				key: Ext.event.Event.F6,
				shift: false,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F6");
				}
			},
			{
				key: Ext.event.Event.F7,
				shift: false,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F7");
				}
			},
			{
				key: Ext.event.Event.F8,
				shift: false,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F8");
				}
			},
			{
				key: Ext.event.Event.F9,
				shift: false,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F9");
				}
			},
			{
				key: Ext.event.Event.F10,
				shift: false,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F10");
				}
			},
			{
				key: Ext.event.Event.F11,
				shift: false,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F11");
				}
			},
			{
				key: Ext.event.Event.F12,
				shift: false,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F12");
				}
			}
		];

		a_keys = a_keys.concat(i_self.getFShiftKeys());

		return a_keys;
	},

	getFShiftKeys: function() {

		var i_self = this;

		var a_keys = [
			{
				key: Ext.event.Event.F1,
				shift: true,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F13");
				}
			},
			{
				key: Ext.event.Event.F2,
				shift: true,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F14");
				}
			},
			{
				key: Ext.event.Event.F3,
				shift: true,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F15");
				}
			},
			{
				key: Ext.event.Event.F4,
				shift: true,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F16");
				}
			},
			{
				key: Ext.event.Event.F5,
				shift: true,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F17");
				}
			},
			{
				key: Ext.event.Event.F6,
				shift: true,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F18");
				}
			},
			{
				key: Ext.event.Event.F7,
				shift: true,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F19");
				}
			},
			{
				key: Ext.event.Event.F8,
				shift: true,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F20");
				}
			},
			{
				key: Ext.event.Event.F9,
				shift: true,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F21");
				}
			},
			{
				key: Ext.event.Event.F10,
				shift: true,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F22");
				}
			},
			{
				key: Ext.event.Event.F11,
				shift: true,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F23");
				}
			},
			{
				key: Ext.event.Event.F12,
				shift: true,
				fn: function(n_key, i_event) {

					i_event.stopEvent();
					i_self.doKeyEvent("F24");
				}
			}
		];

		return a_keys;
	},

	createCursor: function() {

		var i_self = this;
		var o_inputData = i_self.getInputData();

		var i_cursor = Ext.widget("icecap-cursor", {
			theme: i_self.getTheme(),
			width: IceCap.util.Handler.getWidth(),
			listeners: {
				show: {
					fn: function(i_cursor) {

						var i_marker = i_self.getMarker();
						var b_active = i_marker.getInUse();

						if (b_active) {
							i_marker.show();
						}
					}
				},
				render: {
					fn: function(i_item) {
						i_item.hide();
					}
				},
				afterrender: {
					fn: function(i_cursor) {

						var i_content = i_self.getContent();

						var a_fields = IceCap.util.Handler.getInputFields(i_content);

						if (a_fields.length === 0) {

							i_cursor.show();

							i_cursor.moveCursor({
								col: o_inputData.csrCol || 1,
								lin: o_inputData.csrLin || 1
							});
						}
					}
				}
			},
			moveCursor: function(o_position) {

				var i_cursor = this;
				var i_marker = i_self.getMarker();

				var n_x = IceCap.util.Handler.getX(o_position.col);
				var n_y = IceCap.util.Handler.getY(o_position.lin + 1);

				var a_pos = [
					n_x,
					n_y
				];

				i_cursor.move([
					n_x,
					n_y - 11
				]);
				i_marker.move([
					n_x - 7,
					n_y - 12
				]);

				i_self.updateCurrentPosition(o_position);
			}
		});

		i_self.setCursor(i_cursor);

		return i_cursor;
	},

	createMarker: function() {

		var i_self = this;

		var i_marker = Ext.widget("icecap-marker", {
			hidden: true,
			active: false,
			inUse: false,
			ui: i_self.getTheme() || "default"
		});

		i_self.setMarker(i_marker);

		return i_marker;
	},

	findFocus: function() {

		var i_self = this;
		var i_main = i_self.getMain();
		var i_content = i_self.getContent();

		var i_focus = i_main;

		var a_fields = IceCap.util.Handler.getInputFields(i_content);

		if (a_fields.length > 0) {
			i_focus = Ext.Array.findBy(a_fields, function (i_field) {
				return i_field.getTabIndex() === i_self.getNeedFocus();
			});

			if (!i_focus) {
				i_focus = a_fields[0];
			}
		}

		var f_delay = Ext.Function.createDelayed(function() {
			i_focus.focus(false, 10);
		}, 10);

		f_delay.call();

	},

	doTimer: function() {

		var i_self = this;
		var s_message = i_self.getMessageText();

		var i_timer = i_self.getTimer();
		if (!i_timer) {
			i_timer = new Ext.util.DelayedTask(function() {

				i_self.setLoading(s_message ? s_message :true);
			});

			i_self.setTimer(i_timer);

			i_timer.delay(1000);
		}
	},

	cancelTimer: function() {

		var i_self = this;

		var i_timer = i_self.getTimer();

		if (i_timer) {
			i_timer.cancel();
			i_self.setTimer(null);
		}
	},

	doTitleUpdate: function(s_value) {

		var i_self = this;
		var i_window = i_self.up("window");
		i_self.setTitle("");

		if (i_window && !i_window.isXType("ip2DomainModelEntityManager", false)) {

			if (!i_self.getIgnoreTitle()) {
				i_window.setTitle(s_value);
			}
		}
		else {
			if (!i_self.getIgnoreTitle()) {
				i_self.setTitle(s_value);
			}
		}
	},

	onError: function(o_inputData) {

		var i_self = this;

		IceCap.util.Handler.messageBox({
			title: "Server Message",
			msg: o_inputData.msgBox.text,
			yesText: "OK",
			yesFn: function(btn) {
				i_self.findFocus();
			}
		});
	},

	updateMessage: function(o_inputData) {

		var i_self = this;
		var i_statusbar = i_self.getStatusBar();

		var a_messages = Ext.Array.from(o_inputData.message);

		var a_result = [];

		if (a_messages.length > 1) {

			a_result.push(a_messages[0].text);
		}
		else {
			Ext.Array.each(a_messages, function(o_message) {
				a_result.push(o_message.text);
			});
		}

		var i_messageLabel = i_statusbar.getComponent("icecap-message");

		var s_message = a_result.join(" ");

		if (Ext.String.startsWith(s_message.toLowerCase(), "(c)")) {
			i_messageLabel.removeCls("icecap-statusbar-error");

		}
		else {
			i_messageLabel.addCls("icecap-statusbar-error")
		}
		i_messageLabel.setText(s_message);
	},

	applyFFW: function(o_config) {

		var i_self = this;
		var s_hex = o_config.ffw;
		var b_fixed = IceCap.util.Handler.getFixed();

		var o_field = {
			xtype: "icecap-input"
		};

		var o_fieldStyle = {
		};

		if (o_config.ta) {

			Ext.apply(o_fieldStyle, {
				"text-align": o_config.ta
			});
		}

		if (s_hex) {

			var n_hex = parseInt(s_hex);

			var n_sanHex = IceCap.util.Handler.createIndicators(s_hex);

			if (n_sanHex & IceCap.util.Handler.FFW.BYPASS) {

				Ext.apply(o_field, {
					readOnly: true
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.ALPHA_ONLY) {

				Ext.apply(o_field, {
					maskRe: new RegExp("[a-z A-Z ,.-]")
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.NUMERIC_ONLY) {

				Ext.apply(o_field, {
					maskRe: new RegExp("[+\\-,. 0-9]")
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.DIGITS_ONLY) {

				Ext.apply(o_field, {
					maskRe: new RegExp("[0-9]")
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.MOD_DATA) {

				Ext.apply(o_field, {
					listeners: {
						afterrender: {
							fn: function(i_field) {

								i_field.originalValue = 0xFF;
							},
							single: true
						}
					}
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.AUTO_ENTER) {

				// THIS WE DONT NEED IN THE MODERN WORLD...

				// Ext.apply(o_field, {
				// 	listeners: {
				// 		blur: {
				// 			fn: function(i_field) {
				// 				i_self.doKeyEvent("ENTER");
				// 			}
				// 		}
				// 	}
				// });
			}

			if (n_sanHex & IceCap.util.Handler.FFW.MONOCASE) {

				// Ext.apply(o_fieldStyle, {
				// 	"text-transform": "uppercase"
				// });
			}

			if (n_sanHex & IceCap.util.Handler.FFW.MAND_ENTER) {

				Ext.apply(o_field, {
					allowBlank: false
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.RA_ZEROFILL ||
				n_sanHex & IceCap.util.Handler.FFW.RA_BLANKFILL ||
				n_sanHex & IceCap.util.Handler.FFW.RA_MANDATORY) {

				Ext.apply(o_fieldStyle, {
					"text-align": "right"
				});
			}

			if (o_config.atr == "27" && n_hex & (1 << 13)) {

				Ext.apply(o_field, {
					hidden: true,
					disabled: true
				});
			}
		}

		Ext.apply(o_field, {
			fieldStyle: o_fieldStyle
		});

		return o_field;
	},
	getState: function() {

		var i_self = this;

		var o_inputData = i_self.getInputData();
		var s_sessionValue = i_self.getSessionValue();

		var o_result = {
			appConfig: {
				inputData: o_inputData,
				sessionValue: s_sessionValue,
				typeMode: i_self.getTypeMode(),
				resizeMode: i_self.getResizeMode(),
				currentPosition: i_self.getCurrentPosition()
			}
		};

		return o_result;
	},

	updateCurrentPosition: function(o_position) {

		var i_self = this;
		var i_statusbar = i_self.getStatusBar();

		if (i_statusbar) {
			var i_position = i_statusbar.getComponent("icecap-position");

			if (i_position) {

				var a_result = [
					o_position.lin,
					o_position.col
				];

				i_position.setText(a_result.join("/"));
			}
			i_self.updateTypeMode(i_self.getTypeMode())
		}
	},

	updateTypeMode: function (n_type) {

		var i_self = this;

		var i_statusbar = i_self.getStatusBar();

		if (i_statusbar) {

			var i_typeLabel = i_statusbar.getComponent("icecap-typemode");

			var a_mode = [
			];

			if (i_typeLabel) {

				switch (n_type) {
					case IceCap.util.Handler.typeMode.OVERWRITE:
						a_mode.push(" DEL");
						break;

					default:
						a_mode.push(" INS");
						break;
				}

				i_typeLabel.setText(a_mode.join(" "));
			}
		}
	},

	updateResizeMode: function(n_mode) {

		var i_self = this;
		var i_content = i_self.getContent();
		var o_inputData = i_self.getInputData()

		if (n_mode == 2 && o_inputData) {

			i_content.setSize({
				width: IceCap.util.Handler.getWidth(o_inputData.width + 7 || 87),
				height: IceCap.util.Handler.getHeight(o_inputData.height || 24)
			});
		}
	},

	updateEdit: function(value) {

		var i_self = this;
		
		if (i_self.rendered) {
			var o_inputData = i_self.getInputData();

			i_self.redraw();
		}
	},

	focus: function() {

		var i_self = this;
		i_self.findFocus();
	},

	redraw: function() {

		var i_self = this;
		var o_inputData = i_self.getInputData();

		IceCap.util.Handler.setChanged(false);

		if (o_inputData) {
			if (o_inputData.window && o_inputData.window.level > 0) {

			}
			else {

				var i_content = i_self.getContent();

				var o_values = {};
				var i_form = i_content.getForm();
				var i_fieldCollection = i_form.getFields();
				var a_fields = i_fieldCollection.getRange();

				Ext.Array.each(a_fields, function(i_field) {
					o_values[i_field.itemId] = i_field.getValue();
				});

				i_self.doCreateFromData(o_inputData);

				i_content = i_self.getContent();

				i_fieldCollection = i_form.getFields();
				a_fields = i_fieldCollection.getRange();

				Ext.Object.each(o_values, function (s_key, value) {

					var i_field = i_form.getFields().findBy(function(i_search) {
						return i_search.itemId == s_key;
					});

					if (i_field) {
						i_field.setValue(value);
					}
				});

				i_self.findFocus();
			}
		}
	}
});
Ext.define("IceCap.view.Window", {
	extend: "Ext.window.Window",

	layout: "fit",

	requires: [
		"IceCap.controller.Window"
	],

	config: {
		inputData: null,
		lastTabIndex: 1,
		currentTabIndex: 1,
		content: null,
		keyArea: null,
		working: false,
		needFocus: 1,
		currentPosition: {
			col: 1,
			lin: 1
		},
		statusBar: null,
		main: null,
		sessionValue: "",
		cursor: null,
		timer: null,
		theme: "",
		requestCallBack: Ext.emptyFn,
		responseCallBack: Ext.emptyFn,
		enterOnDblClick: false,
		marker: null,
		markerActive: false,
		options: {},
		typeMode: 1,
		edit: false
	},

	closable: false,

	modal: false,

	controller: "icecap.view.window",

	listeners: {
		afterrender: {
			fn: function(i_panel) {

				var i_self = i_panel;

				i_self.addKeyEvents();

				var i_content = i_self.getContent();

				if (i_content) {

					var o_inputData = i_self.getInputData();

					var a_fields = IceCap.util.Handler.getInputFields(i_content);
					var b_found = false;
					var b_error = false;

					Ext.Array.each(a_fields, function(i_field) {
						if (i_field.getTabIndex() === i_self.getNeedFocus()) {
							if (!b_error) {
								setTimeout(function() {
									i_field.focus(false, 10);
								}, 10);
							}
							b_found = true;

							return false;
						}
					});

					if (!b_found) {

						i_self.setCurrentPosition({
							col: 2,
							lin: 1
						});

						if (!b_error) {
							setTimeout(function() {
								i_self.focus(true, 10);
							}, 10);
						}
					}
				}
			},
			buffer: 100
		},
		dblclick: {
			fn: "onDblClick",
			element: "body"
		},
		click: {
			fn: "onClick",
			element: "body"
		},
		wheel: {
			fn: "onWheel",
			element: "body"
		},
		fieldoption: {
			fn: function(a_config) {

				var i_self = this;
				var i_controller = i_self.getController();

				var o_data = {};

				Ext.apply(o_data, {
					key: "ENTER"
				});

				Ext.Array.each(a_config, function(o_config) {

					var s_field = o_config.field;

					o_data[s_field] = o_config.option;

					Ext.apply(o_data, {
						csrCol: o_config.col,
						csrLin: o_config.lin
					});
				});

				i_self.setCurrentPosition({
					col: o_data.csrCol,
					lin: o_data.csrLin
				});

				i_controller.onSendData({
					func: ""
				}, o_data);
			}
		},
		key: {
			fn: function(s_value) {

				var i_self = this;
				var i_controller = i_self.getController();

				i_controller.doKeyEvent(s_value);
			}
		}

	},

	onKeyDown: Ext.emptyFn, // THIS IS NEEDED TO OVERRIDE Ext.util.Floating

	initComponent: function() {

		var i_self = this;

		var o_params = Ext.Object.fromQueryString(window.location.search);

		Ext.Object.each(o_params, function(s_key, value) {
			o_params[s_key] = Ext.decode(value, true) || value;
		});

		var o_options = Ext.apply(i_self.options, o_params.options || {});

		Ext.apply(i_self, {
			theme: i_self.theme || o_params.theme || ""
		});

		i_self.callParent(arguments);

		i_self.setTypeMode(IceCap.util.Handler.typeMode.INSERT);

		i_self.add(i_self.createLayout());

		i_self.enableBubble([
			"onAddWebContainer",
			"toWindow",
			"applicationClose"
		]);

		i_self.recreate();
	},

	createStatusBar: function() {

		var i_self = this;

		var i_statusbar = Ext.widget("toolbar", {
			dock: "bottom",
			cls: "icecap-statusbar",
			hidden: false,
			ui: "statusbar",
			height: 30,
			layout: {
				type: "hbox",
				align: "top"
			},
			items: [
				{
					xtype: "label",
					itemId: "icecap-message",
					listeners: {
						afterrender: {
							fn: function(i_label) {

								var i_tpl = Ext.create("Ext.XTemplate",
									"<ul style=\"list-style: none;",
												"margin:10px;",
												"padding:0;",
									"\">",
										"<tpl for=\".\">",
											"<li>{text}</li>",
										"</tpl>",
									"</ul>"
								);

								Ext.create("Ext.tip.ToolTip", {
									target: i_label.getEl(),
									html: "",
									anchor: true,
									defealtAlign: "b50-t50",
									listeners: {
										beforeshow: {
											fn: function (i_tip) {

												var b_hasError = i_label.hasCls("icecap-statusbar-error");

												var o_inputData = i_self.getInputData();

												var a_messages = Ext.Array.from(o_inputData.message);

												if (b_hasError && a_messages.length > 0) {
													var s_value = i_tpl.apply(a_messages);
													i_tip.update(s_value);
												}
												else {
													return b_hasError;
												}
											}
										}
									}
								});
							}
						},
						click: {
							element: "el",
							fn: function (i_event, i_element) {

								var o_input = {
									col: 3,
									lin: 24
								};

								i_self.setCurrentPosition(o_input);

								var i_cursor = i_self.getCursor();
								i_cursor.moveCursor(o_input);

								i_self.doKeyEvent("F1");
							}
						},
					}
				},
				"->",
				{
					xtype: "component",
					cls: "pf-gearwheel",
					height: 24,
					hidden: true,
					autoEl: {
						tab: "span"
					},
					style: {
						"cursor": "pointer"
					},
					listeners: {
						click: {
							element: "el",
							fn: function() {

								var i_element = this;
								var b_edit = i_self.getEdit();

								b_edit = !b_edit;

								if (b_edit) {
									i_element.addCls("x-base-color");
								}
								else {
									i_element.removeCls("x-base-color");
								}

								i_self.setEdit(b_edit);
							}
						}
					}
				},
				{
					xtype: "label",
					itemId: "icecap-position"
				},
				{
					xtype: "label",
					text: " INS",
					itemId: "icecap-typemode"
				}
			],
			setText: function (s_text) {

				var i_toolbar = this;

				var i_message = i_toolbar.getComponent("icecap-message");

				if (i_message) {
					i_message.setText(s_text);
				}
			}
		});

		return i_statusbar;
	},

	createLayout: function() {

		var i_self = this;
		var o_inputData = i_self.getInputData();

		return i_self.createContent();
	},

	createContent: function() {

		var i_self = this;

		var i_panel = Ext.widget("panel", {
			layout: {
				type: "vbox",
				align: "stretch"
			},
			cls: ["icecap-window", i_self.getTheme()].join("-"),
			border: false,
			focusable: true,
			tabIndex: -1,
			items: i_self.createItems()
		});

		i_self.setMain(i_panel);

		return i_panel;
	},

	createItems: function() {

		var i_self = this;

		var o_inputData = i_self.getInputData();

		var a_items = [];

		var i_keyArea = Ext.widget("panel", {
			layout: {
				type: "column"
			},
			border: false,
			focusable: false,
			minHeight: 50,
			height: null,
			defaults: {
				margin: "0 5 5 0"
			},
			cls: ["icecap-panel", i_self.getTheme()].join("-"),
			ui: "icecap-keyarea"
		});

		var i_center = Ext.widget("form", {
			border: false,
			layout: "absolute",
			flex: 1,
			ui: ["icecap", i_self.getTheme()].filter(Boolean).join("-")
		});

		a_items.push(i_center);
		a_items.push(i_keyArea);

		i_self.setContent(i_center);

		var i_statusbar = i_self.createStatusBar();

		i_self.addDocked([
			i_statusbar
		]);


		i_self.setStatusBar(i_statusbar);
		i_self.setKeyArea(i_keyArea);

		i_self.updateMessage(o_inputData);

		return a_items;
	},

	createFields: function () {

		var i_self = this;
		var o_inputData = i_self.getInputData();

		var a_fields = [];

		var n_tabIndex = 1;
		var n_focus = o_inputData.focus;

		var n_inputWidth = o_inputData.width || 80;

		var a_sliced = Ext.Array.from(o_inputData.input || []);

		Ext.Array.each(a_sliced, function (o_config, n_index) {

			var n_width = (IceCap.util.Handler.getWidth(o_config.len) + (IceCap.util.Handler.getWidth() / 2));

			var o_meta = o_config.metaData || {};

			var o_field = {
				inputType: "text",
				xtype: "icecap-input",
				ui: "icecap-field"
			};

			var s_type = o_field.xtype || "icecap-input";
			var n_x = IceCap.util.Handler.getX(o_config.col) - 3;
			var n_y = IceCap.util.Handler.getY(o_config.lin);
			var b_password = o_config.atr == "27";

			if (o_config.len > n_inputWidth) {
				var n_temp = n_inputWidth - o_config.col;
				n_width = (IceCap.util.Handler.getWidth(n_temp) + (IceCap.util.Handler.getWidth() / 2));
			}


			if (o_config.hasOwnProperty("colsize") && o_config.hasOwnProperty("rows")) {

				var s_data = o_config.dta || "";

				o_field.xtype = s_type = "textarea";
				o_field.height = IceCap.util.Handler.getHeight() * o_config.rows;
				o_field.preventScrollbars = true;

				var a_split = s_data.split("\n");

				var s_result = "";

				var n_split = a_split.length;

				Ext.Array.each(a_split, function (s_part, n_index) {

					var regex = new RegExp(".{" + o_config.colsize + "}", "g");

					var a_match = s_part.match(regex);

					if (a_match) {
						s_result += s_part;
					}
					else {
						if (n_index != n_split - 1) {
							s_result += s_part + "\n";
						}
						else {
							s_result += s_part;
						}
					}
				});

				o_config.dta = s_result;


				o_field.getSubmitValue = function () {

					var i_field = this;

					var s_value = i_field.stripReturns(i_field.getRawValue());

					var regex = new RegExp(".{1," + o_config.colsize + "}", "g");

					var a_split = s_value.match(regex) || [];

					return a_split.join("\n");
				};

			}

			var o_listeners = Ext.apply({}, o_meta.listeners);
			delete o_meta.listeners;

			var a_field = ["icecap-field", i_self.getTheme()];

			var a_pass = [b_password ? "iceCap-input-password" : "iceCap-input-" + (o_config.atr || 20)];

			a_pass.push(i_self.getTheme());

			var a_cls = [a_field.filter(Boolean).join("-"), a_pass.filter(Boolean).join("-")];

			var s_cls = a_cls.join(" ");

			if (isNaN(n_x)) {
				n_x = IceCap.util.Handler.getColSize();
			}

			if (isNaN(n_y)) {
				n_y = IceCap.util.Handler.getLineHeight();
			}

			var s_ui = b_password ? "icecap-password-field" : "icecap-field";

			if (!o_meta.xtype) {
				Ext.apply(o_field, i_self.applyFFW(o_config));
			}

			var i_field;

			var s_name = IceCap.util.Handler.getRandomName();

			if (o_field.readOnly) {

				o_field.xtype = s_type = "displayfield";
				s_ui = "icecap-display";
				s_cls = (["iceCap-output-" + (o_config.atr || 20), i_self.getTheme()].filter(Boolean).join("-"));

				o_field = {
					autoEl: {
						tag: "span"
					},
					html: o_config.dta || "",
					x: n_x,
					y: n_y,
					name: s_name,
					cls: ["x-form-display-field-icecap-display", s_cls].join(" "),
					style: {
						"white-space": "pre"
					},
					listeners: {
						afterrender: {
							fn: function (i_field) {
								i_field.el.dom.setAttribute("draggable", false);
							}
						}
					}
				};

				if (o_config.atr == "27") {
					o_field.hidden = true;
				}

				if (o_config.atr == "22") {

					Ext.apply(o_field.style, {
						"font-size": (IceCap.util.Handler.getFontSize() - 1) + "px",
						"font-weight": "bold;",
						"letter-spacing": (IceCap.util.Handler.getColSize() - IceCap.util.Handler.getBoldColSize()) + "px",
						"word-spacing": "0.02em;"
					});
				}

				i_field = Ext.widget("component", o_field);

			}
			else {

				Ext.Object.merge(o_field, {
					width: n_width,
					enforceMaxLength: true,
					maxLength: o_config.len,
					minWidth: IceCap.util.Handler.getDefaultWidth(),
					tabIndex: !o_field.readOnly ? n_tabIndex : -1,
					focusable: !o_field.readOnly,
					lin: o_config.lin,
					col: o_config.col,
					emuId: o_config.id,
					value: o_config.dta || "",
					itemId: o_config.id,
					name: s_name,
					inputAttrTpl: "spellcheck=false autocomplete=\"new-password\" name=\"" + s_name + "\"",
					x: n_x,
					y: n_y,
					cls: s_cls,
					enableKeyEvents: true,
					selectOnFocus: false,
					ui: s_ui,
					listeners: {
						afterrender: {
							fn: function (i_field) {

								if (i_field.inputEl && !i_field.metaField) {

									if (i_field.xtype == "textarea") {
										i_field.inputEl.dom.setAttribute("rows", o_config.rows);
									}

									if (i_field.getTabIndex() === i_self.getNeedFocus()) {

										i_field.focus(false, 10, function () {
											var o_inputData = i_self.getInputData();

											var s_value = i_field.getValue();
											var n_col = i_field.col;
											var n_diff = 0;

											if (n_col < o_inputData.csrCol) {
												n_diff = o_inputData.csrCol - n_col;
												i_field.inputEl.el.dom.selectionEnd = i_field.inputEl.el.dom.selectionStart = i_field.inputEl.el.dom.selectionStart + n_diff;
											}

											var o_position = {
												col: o_inputData.csrCol,
												lin: o_inputData.csrLin
											};

											i_self.setCurrentPosition(o_position);

											var i_cursor = i_self.getCursor();
											i_cursor.moveCursor(o_position);
											i_cursor.hide();
										});
									}
								}
							}
						},
						change: {
							fn: function (i_field, value) {

								var s_direction = i_field.inputEl.el.dom.selectionDirection;

								var n_curpos = s_direction == "forward" ? i_field.inputEl.el.dom.selectionEnd : i_field.inputEl.el.dom.selectionStart;

								value = value || "";

								if (value.length == i_field.maxLength && n_curpos == i_field.maxLength) {
									i_self.doNavigationKey(1, true);
								}
							}
						},
						focus: {
							fn: function (i_field) {

								var n_tabIndex = i_field.getTabIndex();
								i_self.setCurrentTabIndex(n_tabIndex);

								var o_position = {
									col: i_field.col,
									lin: i_field.lin
								};
								i_self.setCurrentPosition(o_position);

								var i_cursor = i_self.getCursor();
								i_cursor.moveCursor(o_position);
								i_cursor.hide();
							}
						},
						keyup: {
							fn: function (i_field, i_event) {

								if (i_field.xtype === "icecap-input") {

									var value = i_field.getValue();

									var s_direction = i_field.inputEl.el.dom.selectionDirection;

									var n_start = s_direction == "forward" ? i_field.inputEl.el.dom.selectionEnd : i_field.inputEl.el.dom.selectionStart;
									var n_add = value.length * IceCap.util.Handler.getWidth();

									if (n_start != value.length) {
										n_add = n_start * IceCap.util.Handler.getWidth();
									}

									var o_input = Ext.apply({
										x: i_field.getLocalX() + n_add,
										y: i_field.getLocalY()
									});

									var o_position = IceCap.util.Handler.toColAndLine(o_input);
									i_self.setCurrentPosition(o_position);

									var i_cursor = i_self.getCursor();
									i_cursor.moveCursor(o_position);
								}
							}
						},
						keydown: {
							fn: function (i_field, i_event) {

								var i_regext = new RegExp("^\\w{1}$");

								var value = i_field.getValue();

								if (i_event.ctrlKey) {

									var o_input = {};
									var o_position = {};
									var o_box = {};
									var i_main = i_self.getMain();
									var i_cursor = i_self.getCursor();
									var a_inputs = IceCap.util.Handler.getInputFields(i_self);
									var b_intersect = false;
									var n_selection = 0;

									var i_inputEl = i_field.inputEl;

									if (i_event.keyCode == Ext.event.Event.DOWN ||
										i_event.keyCode == Ext.event.Event.UP) {

										n_selection = i_inputEl.dom.selectionEnd;

										i_event.stopEvent();

										o_position = {
											col: i_field.col + n_selection,
											lin: i_field.lin
										};

										if (i_event.keyCode == Ext.event.Event.DOWN) {
											o_position.lin++;
										}
										else {
											o_position.lin--;
										}

										i_self.setCurrentPosition(o_position);

										i_cursor.moveCursor(o_position);

										o_input = {
											x: IceCap.util.Handler.getX(o_position.col),
											y: IceCap.util.Handler.getY(o_position.lin)
										};

										Ext.apply(o_box, {
											width: i_cursor.getWidth(),
											height: i_cursor.getHeight()
										}, o_input);

										Ext.Array.each(a_inputs, function (i_field) {

											var o_bound = i_field.el.dom.getBoundingClientRect();

											var o_rect = Ext.apply({}, {
												x: i_field.getLocalX(),
												y: i_field.getLocalY(),
												width: o_bound.width,
												height: o_bound.height
											});

											if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
												b_intersect = true;
												i_field.focus(false, 10);
												return false;
											}
										});

										if (!b_intersect) {

											i_field.blur();
											i_cursor.show();

											i_main.focus(true, 10);
										}
									}
									if (i_event.keyCode == Ext.event.Event.LEFT ||
										i_event.keyCode == Ext.event.Event.RIGHT) {

										n_selection = i_event.keyCode == Ext.event.Event.LEFT ? i_inputEl.dom.selectionStart : i_inputEl.dom.selectionEnd;

										i_event.stopEvent();

										if (n_selection === 0 && i_event.keyCode === Ext.event.Event.LEFT) {

											o_position = {
												col: i_field.col,
												lin: i_field.lin
											};

											o_position.col--;

											o_input = {
												x: IceCap.util.Handler.getX(o_position.col),
												y: IceCap.util.Handler.getY(o_position.lin)
											};

											i_self.setCurrentPosition(o_position);

											i_cursor.moveCursor(o_position);

											Ext.apply(o_box, {
												width: i_cursor.getWidth(),
												height: i_cursor.getHeight()
											}, o_input);


											Ext.Array.each(a_inputs, function (i_field) {

												var o_bound = i_field.el.dom.getBoundingClientRect();

												var o_rect = Ext.apply({}, {
													x: IceCap.util.Handler.getX(i_field.col),
													y: IceCap.util.Handler.getY(i_field.lin),
													width: o_bound.width,
													height: o_bound.height
												});

												if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
													b_intersect = true;
													i_field.focus(false, 10);
													return false;
												}
											});

											if (!b_intersect) {

												i_field.blur();
												i_cursor.show();

												i_main.focus(true, 10);
											}
										}
										else if (n_selection == value.length && i_event.keyCode == Ext.event.Event.RIGHT) {

											o_position = {
												col: i_field.col + i_field.maxLength,
												lin: i_field.lin
											};

											if (o_position.col > o_inputData.width) {
												o_position.col = o_inputData.width;
											}

											o_position.col++;

											o_input = {
												x: IceCap.util.Handler.getX(o_position.col),
												y: IceCap.util.Handler.getY(o_position.lin)
											};


											i_self.setCurrentPosition(o_position);
											i_cursor.moveCursor(o_position);

											Ext.apply(o_box, {
												width: i_cursor.getWidth(),
												height: i_cursor.getHeight()
											}, o_input);

											Ext.Array.each(a_inputs, function (i_field) {

												var o_bound = i_field.el.dom.getBoundingClientRect();

												var o_rect = Ext.apply({}, {
													x: IceCap.util.Handler.getX(i_field.col),
													y: IceCap.util.Handler.getY(i_field.lin),
													width: o_bound.width,
													height: o_bound.height
												});

												if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
													b_intersect = true;
													i_field.focus(false, 10);
													return false;
												}
											});

											if (!b_intersect) {

												i_field.blur();
												i_cursor.show();

												i_main.focus(true, 10);
											}
										}
									}
								}
								else {

									if (i_field.xtype == "textarea") {

										if (i_event.keyCode == Ext.event.Event.UP) {

											var s_value = i_field.stripReturns(i_field.getRawValue());

											var regex = new RegExp("^.*\n$|.{1," + o_config.colsize + "}", "gm");

											var a_lines = s_value.match(regex) || [];
											var a_newLines = s_value.split("\n");

											var n_start = i_field.inputEl.dom.selectionStart;

											var n_row = 1;
											var n_char = 0;
											var b_last = i_field.inputEl.dom.selectionStart == i_field.inputEl.dom.value.length;

											Ext.Array.each(a_lines, function (s_part, n_index) {

												n_char += s_part.length;

												if (n_char <= n_start) {
													n_row++;
												}
												else {
													return false;
												}
											});

											if (n_row > 1) {

												i_event.stopEvent();

												n_char = 0;
												var n_left = 0;
												var n_current = 0;
												var n_nextLine = 0;

												n_start = n_start - (a_newLines.length - 1);

												Ext.Array.each(a_lines, function (s_part, n_index) {

													n_char += s_part.length;

													var n_count = 0;

													n_left = 0;

													while (n_count < s_part.length) {
														n_count++;
														if (n_current < n_start) {
															n_current++;
															n_left++;
														}
													}

													if (n_char < n_start) {
														n_row++;
													}
													else {
														n_nextLine = n_index - 1;
														return false;
													}
												});

												if (n_nextLine == -1) {
													n_nextLine = 0;
												}

												var n_newPos = 0;

												Ext.Array.each(a_lines, function (s_part, n_index) {

													if (n_index < n_nextLine) {
														n_newPos += s_part.length;
													}
													else {
														n_newPos += n_left;
														return false;
													}
												});

												i_event.stopEvent();
												i_field.inputEl.dom.setSelectionRange(n_newPos, n_newPos);
											}
										}

										if (i_event.keyCode == Ext.event.Event.DOWN) {

											var s_value = i_field.stripReturns(i_field.getRawValue());
											var n_length = s_value.length;

											var regex = new RegExp("^.*\n$|.{1," + o_config.colsize + "}", "g");
											var n_pos = i_field.inputEl.dom.selectionStart;

											var a_lines = s_value.match(regex) || [];
											var a_newLines = s_value.split("\n");

											if (a_lines.length < o_config.rows && a_newLines.length < o_config.rows) {

												i_event.stopEvent();

												s_value = s_value + "\n";

												i_field.setValue(s_value);

												i_field.inputEl.dom.setSelectionRange(s_value.length, s_value.length);
											}
											else {
												var n_row = 1;
												var n_char = 0;
												var n_left = 0;
												var n_current = 0;
												var n_nextLine = 0;

												Ext.Array.each(a_lines, function (s_part, n_index) {

													n_char += s_part.length;

													var n_count = 0;

													n_left = 0;

													while (n_count < s_part.length) {
														n_count++;
														if (n_current < n_pos) {
															n_current++;
															n_left++;
														}
													}

													if (n_char <= n_pos) {
														n_row++;
													}
													else {
														n_nextLine = n_index + 1;
														return false;
													}
												});

												if (n_nextLine < a_lines.length || n_nextLine < a_newLines.length) {

													var n_newPos = 0;

													Ext.Array.each(a_lines, function (s_part, n_index) {

														if (n_index < n_nextLine) {
															n_newPos += s_part.length;
														}
														else {
															n_newPos += n_left + (a_newLines.length - 1);
															return false;
														}
													});

													if (n_row < o_config.rows) {
														i_event.stopEvent();
														i_field.inputEl.dom.setSelectionRange(n_newPos, n_newPos);
													}
												}
											}

										}
									}
									else if (i_field.xtype == "icecap-input") {

										var n_typeMode = i_self.getTypeMode();

										if (n_typeMode == IceCap.util.Handler.typeMode.OVERWRITE) {

											var s_direction = i_field.inputEl.el.dom.selectionDirection;

											var n_curpos = s_direction == "forward" ? i_field.inputEl.el.dom.selectionEnd : i_field.inputEl.el.dom.selectionStart;

											var s_key = String.fromCharCode(i_event.keyCode);

											if (n_curpos < value.length && i_regext.test(s_key)) {

												var a_values = value.split("");
												a_values[n_curpos] = i_event.browserEvent.key;
												value = a_values.join("");
												i_field.setValue(value);
												i_field.inputEl.el.dom.selectionEnd = i_field.inputEl.el.dom.selectionStart = n_curpos + 1;
												i_event.stopEvent();
											}
										}
									}
								}
							}
						}
					}
				}, o_meta);

				var o_clone = Ext.clone(o_field);

				if (o_meta.xtype) {

					o_clone.metaField = true;

					o_clone.xtype = s_type = o_meta.xtype;

					delete o_clone.cls;
					delete o_clone.fieldStyle;
					delete o_clone.inputType;
					delete o_clone.ui;
				}

				if (o_config.type == "grid") {

					s_type = "iceCapGrid";

					Ext.apply(o_clone, {
						xtype: s_type,
						gridConfig: o_config.grid,
						width: IceCap.util.Handler.getWidth(n_inputWidth)
					});

					delete o_clone.cls;
					delete o_clone.fieldStyle;
					delete o_clone.inputType;
					delete o_clone.listeners;
					delete o_clone.grid;

					Ext.apply(o_clone, {
						listeners: {
							fieldoption: {
								fn: function (a_config) {
									i_self.fireEvent("fieldoption", a_config);
								}
							},
							key: {
								fn: function (s_key) {
									i_self.fireEvent("key", s_key);
								}
							}
						}
					});
				}

				i_field = Ext.widget(s_type, o_clone);

				var o_on = {};

				Ext.Object.each(o_listeners, function (s_key, value) {

					if (Ext.isFunction(value)) {
						o_on[s_key] = Ext.apply({}, {
							fn: value,
							scope: i_self
						});
					}
					else if (Ext.isObject(value)) {
						value.scope = i_self;
						o_on[s_key] = value;
					}
				});

				i_field.on(o_on);
			}

			if (!i_field.readOnly) {
				n_tabIndex++;
			}

			if (o_config.atr == 25) {

				if (o_field.readOnly) {
					i_field.addCls("icecap-invalid");
				}
				else {
					i_field.markInvalid(true);
				}
			}

			a_fields.push(i_field);
		});

		n_tabIndex = n_tabIndex - 1;
		i_self.setLastTabIndex(n_tabIndex);
		i_self.setCurrentTabIndex(o_inputData.focus);

		i_self.setNeedFocus(n_focus);

		return a_fields;
	},

	createLabels: function() {

		var i_self = this;
		var o_inputData = i_self.getInputData();

		var i_cssRule = IceCap.util.Handler.getCssRule();
		var o_style = i_cssRule.style;

		var a_fields = [];

		if (!i_self.getEdit()) {


			var a_lines = [];
			var a_temp = [];

			Ext.Array.each(o_inputData.output, function (o_config) {

				var o_line = Ext.Array.findBy(a_lines, function (o_line) {
					return o_line.lin == o_config.lin;
				});

				if (o_line) {
					o_line.items.push(o_config);
				}
				else {
					o_line = {
						items: [o_config],
						lin: o_config.lin,
						col: o_config.col
					};

					a_lines.push(o_line);
				}
			});

			Ext.Array.each(a_lines, function (o_line) {

				var a_items = [];

				Ext.Array.each(o_line.items, function (o_item) {

					var o_atr = Ext.Array.findBy(a_items, function (o_atr) {
						return (o_atr.atr || "") == (o_item.atr || "");
					});

					if (!o_atr) {
						o_atr = {
							lin: o_item.lin,
							items: [o_item],
							atr: o_item.atr || ""
						};

						a_items.push(o_atr);
					}
					else {
						o_atr.items.push(o_item);
					}
				});

				o_line.atr = a_items;
			});

			Ext.Array.each(a_lines, function (o_line) {

				Ext.Array.each(o_line.atr, function (o_atr) {

					var n_col = 0;
					var n_current = 0;
					var s_value = "";

					var o_field = {
						value: ""
					};

					Ext.Array.each(o_atr.items, function (o_config) {

						var s_data = o_config.dta || o_config.label || o_config.text || "";

						if (o_config.off) {
							s_data = Ext.String.leftPad(s_data, s_data.length + o_config.off);
						}

						if (n_col === 0) {

							n_col = o_config.col;
							n_current = n_col + s_data.length;
							s_value = s_data;
						}
						else {

							var n_diff = o_config.col - n_current;

							if (n_diff > 0) {
								s_data = Ext.String.leftPad(s_data, s_data.length + n_diff);
							}

							n_current = n_current + s_data.length;

							s_value = s_value + s_data;
						}
					});

					Ext.apply(o_field, {
						col: n_col,
						lin: o_line.lin,
						value: s_value,
						atr: o_atr.atr
					});

					a_temp.push(o_field);
				});
			});

			Ext.Array.each(a_temp, function (o_config) {

				var s_value = o_config.value;

				if (s_value) {

					var n_x = IceCap.util.Handler.getX(o_config.col);
					var n_y = IceCap.util.Handler.getY(o_config.lin);

					var s_cls = (["iceCap-output-" + (o_config.atr || 20), i_self.getTheme()].filter(Boolean).join("-"));

					var o_field = {
						autoEl: {
							tag: "span"
						},
						html: s_value,
						x: n_x,
						y: n_y,
						cls: ["x-form-display-field-icecap-display", s_cls].join(" "),
						style: {
							"white-space": "pre"
						},
						listeners: {
							afterrender: {
								fn: function (i_field) {
									i_field.el.dom.setAttribute("draggable", false);
								}
							}
						}
					};


					if (o_config.atr == "27") {
						o_field.hidden = true;
					}

					if (o_config.atr == "22") {

						Ext.apply(o_field.style, {
							"font-size": (IceCap.util.Handler.getFontSize() - 1) + "px",
							"font-weight": "bold;",
							"letter-spacing": (IceCap.util.Handler.getColSize() - IceCap.util.Handler.getBoldColSize()) + "px",
							"word-spacing": "0.02em;"
						});
					}

					var i_field = Ext.widget("component", o_field);
					a_fields.push(i_field);
				}
			});
		}
		else {

			var editor = new Ext.Editor({
				updateEl: true,
				alignment: "l-l",
				autoSize: {
					width: "boundEl"
				},
				field: {
					xtype: "textfield",
					ui: "icecap-field"
				}
			});

			Ext.Array.each(o_inputData.output, function (o_config) {

				var s_value = o_config.dta || "";

				if (s_value) {

					var n_x = IceCap.util.Handler.getX(o_config.col);
					var n_y = IceCap.util.Handler.getY(o_config.lin);

					var s_cls = (["iceCap-output-" + (o_config.atr || 20), i_self.getTheme()].filter(Boolean).join("-"));

					var o_field = {
						autoEl: {
							tag: "span"
						},
						html: s_value,
						x: n_x,
						y: n_y,
						cls: ["x-form-display-field-icecap-display", s_cls].join(" "),
						style: {
							"white-space": "pre"
						},
						listeners: {
							mouseover: {
								element: "el",
								fn: function() {

									var i_element = this;
									i_element.addCls("x-base-background-color");
								}
							},
							mouseout: {
								element: "el",
								fn: function() {

									var i_element = this;
									i_element.removeCls("x-base-background-color");
								}
							},
							afterrender: {
								fn: function (i_field) {
									i_field.el.dom.setAttribute("draggable", false);

									var i_tpl = Ext.create("Ext.XTemplate",
										"<div style=\"width: 300px; overflow:hidden; white-space:nowrap;\">",
											"<div>Lin: {lin}</div>",
											"<div>Col: {col}</div>",
											"<div>Color: {color}</div>",
											"<div style=\"overflow:hidden; white-space: nowrap; text-overflow:ellipsis;\">Font: {font}</div>",
										"</div>"
									);

									Ext.create("Ext.tip.ToolTip", {
										target: i_field.el,
										html: "",
										anchor: true,
										defealtAlign: "b0-t0",
										listeners: {
											beforeshow: {
												fn: function (i_tip) {

													var o_data = {
														lin: o_config.lin,
														col: o_config.col,
														color: o_style.color,
														font: [
															o_style.fontSize,
															o_style.fontFamily
														].join(" ")
													};

													var s_value = i_tpl.apply(o_data);
													i_tip.update(s_value);
												}
											}
										}
									});
								}
							}
						}
					};


					if (o_config.atr == "27") {
						o_field.hidden = true;
					}

					if (o_config.atr == "22") {

						Ext.apply(o_field.style, {
							"font-size": (IceCap.util.Handler.getFontSize() - 1) + "px",
							"font-weight": "bold;",
							"letter-spacing": (IceCap.util.Handler.getColSize() - IceCap.util.Handler.getBoldColSize()) + "px",
							"word-spacing": "0.02em;"
						});
					}

					var i_field = Ext.widget("component", o_field);
					a_fields.push(i_field);

					i_field.on({
						afterrender: {
							fn: function(i_field) {
								i_field.el.on({
									click: {
										fn: function() {
											editor.startEdit(i_field.getEl());
											editor.field.focus(50, false);
										}
									}
								});
							}
						}
					});
				}
			});
		}

		return a_fields;
	},

	createKeys: function() {

		var i_self = this;
		var o_inputData = i_self.getInputData();
		var a_disabledKey = o_inputData.disabledKeys || [];
		var a_buttons = [];

		var i_template = Ext.create("Ext.XTemplate",
			"{id}={text}"
		);

		Ext.Array.each(o_inputData.keys, function(o_config) {

			var s_template = i_template.apply(o_config);

			var o_found = Ext.Array.findBy(a_disabledKey, function(o_disabled) {
				return o_config.id == o_disabled.id;
			});

			o_found = o_found || {
				showKey: 1
			};

			var b_hidden = Number(o_found.showKey) < 1  || false;

			var i_button = Ext.widget("button", {
				text: s_template,
				key: o_config.id,
				focusable: false,
				hidden: b_hidden,
				handler: function(i_button) {
					i_self.doKeyEvent(i_button.key);
				}
			});

			a_buttons.push(i_button);
		});

		return a_buttons;
	},

	createMetaFields: function() {

		var i_self = this;
		var o_inputData = i_self.getInputData();

		var a_fields = [];
		var n_tabIndex = i_self.getLastTabIndex() || 1;

		var a_sliced = Ext.Array.slice(o_inputData.metaFields || []);

		Ext.Array.each(a_sliced, function(o_config) {

			var n_x = o_config.x;
			var n_y = o_config.y;

			if (!o_config.x) {
				n_x = Math.ceil((IceCap.util.Handler.getX(o_config.col) + (IceCap.util.Handler.getColSize() / 2)));
			}

			if (!o_config.y) {
				n_y = IceCap.util.Handler.getY(o_config.lin);
			}

			if (isNaN(n_x)) {
				n_x = IceCap.util.Handler.getColSize();
			}

			if (isNaN(n_y)) {
				n_y = IceCap.util.Handler.getLineHeight();
			}

			var o_listeners = o_config.listeners || {};

			Ext.apply(o_config, {
				tabIndex: n_tabIndex,
				keys: Ext.Array.slice(o_inputData.keys),
				theme: i_self.getTheme(),
				x: n_x,
				y: n_y,
				listeners: {
					fieldoption: {
						fn: function(a_config) {
							i_self.fireEvent("fieldoption", a_config);
						}
					},
					key: {
						fn: function(o_config) {
							i_self.fireEvent("key", o_config);
						}
					}
				}
			});

			n_tabIndex++;

			o_config.xtype = o_config.xtype || o_config.type || "icecap-input";

			o_config.name = o_config.id;

			delete o_config.id;

			var i_field = Ext.widget(o_config.xtype, o_config);

			var o_on = {};

			Ext.Object.each(o_listeners, function(s_key, value) {

				if (Ext.isFunction(value)) {
					o_on[s_key] = Ext.apply({}, {
						fn: value,
						scope: i_self
					});
				}
				else if (Ext.isObject(value)) {
					value.scope = i_self;
					o_on[s_key] = value;
				}
			});

			i_field.on(o_on);

			a_fields.push(i_field);
		});

		i_self.setLastTabIndex(n_tabIndex);

		return a_fields;
	},

	doCreateFromData: function(o_inputData) {

		var i_self = this;
		i_self.fireEvent("toWindow", i_self, o_inputData);
	},

	recreate: function() {

		var i_self = this;

		var i_content = i_self.getContent();
		var i_keyArea = i_self.getKeyArea();
		var i_main = i_self.getMain();
		var o_inputData = i_self.getInputData();

		var b_fixed = o_inputData.hasOwnProperty("fixed") ? o_inputData.fixed : true;

		IceCap.util.Handler.setFixed(b_fixed);

		i_self.suspendLayouts();

		if (o_inputData.title) {
			i_self.setTitle(o_inputData.title);
		}

		var a_created = i_self.createFields();
		a_created = a_created.concat(i_self.createLabels());
		a_created = a_created.concat(i_self.createMetaFields());
		a_created.push(i_self.createCursor());
		a_created.push(i_self.createMarker());

		i_content.removeAll(true);
		i_keyArea.removeAll(true);

		i_content.add(a_created);

		var a_keys = i_self.createKeys();
		i_keyArea.add(a_keys);

		i_keyArea[a_keys.length === 0 ? "hide" : "show"]();

		var i_marker = i_self.getMarker();
		i_marker.setInUse(i_self.getMarkerActive());

		i_self.updateMessage(o_inputData);


		IceCap.util.Handler.setFixed(true);

		i_self.resumeLayouts(true);

		if (i_content) {
			a_fields = IceCap.util.Handler.getInputFields(i_content);

			var b_found = false;
			var b_error = false;

			if (o_inputData.msgBox && o_inputData.msgBox.text) {
				b_error = true;
			}

			if (a_fields.length > 0) {

				b_found = Ext.Array.findBy(a_fields, function (i_field) {
					return i_field.getTabIndex() === i_self.getNeedFocus();
				});
			}

			if (!b_found) {

				i_self.setCurrentPosition({
					col: o_inputData.csrCol || 1,
					lin: o_inputData.csrLin || 1
				});
			}

			if (b_error) {
				i_self.onError(o_inputData);
			}
			else {
				i_self.findFocus();
			}
		}
	},

	getCurrentField: function() {

		var i_self = this;

		var a_fields = IceCap.util.Handler.getInputFields(i_self);
		var n_tabIndex = i_self.getCurrentTabIndex();
		var i_currentField;

		Ext.Array.each(a_fields, function(i_field) {
			if (i_field.getTabIndex() === n_tabIndex && i_field.hasFocus) {
				i_currentField = i_field;
				return false;
			}
		});

		return i_currentField;
	},

	doKeyEvent: function(s_value, i_event) {

		if (i_event) {
			i_event.stopEvent();
		}

		var i_self = this;

		var i_controller = i_self.getController();

		var o_inputData = i_self.getInputData() || {};

		var a_disabledKeys = Ext.Array.from(o_inputData.disabledKeys || []);

		var o_found = Ext.Array.findBy(a_disabledKeys, function (o_key) {
			return s_value == o_key.id;
		});

		if (!o_found) {
			i_controller.doKeyEvent(s_value);
		}
		else {

			Ext.Msg.show({
				title: "Error",
				msg: "Funktionstasten er ikke tilladt",
				icon: Ext.MessageBox.INFO,
				buttons: Ext.MessageBox.OK,
				fn: function () {
					i_self.findFocus();
				}
			});
		}
	},

	doNavigationKey: function(n_direction, b_tab, i_event) {

		if (i_event) {
			i_event.stopPropagation();
			i_event.preventDefault();
		}

		var i_self = this;
		var i_controller = i_self.getController();
		i_controller[b_tab ? "doTabKey" : "doArrowKeys"](n_direction);
	},

	addKeyEvents: function() {

		var i_self = this;

		var a_bindings = [
			{
				key: Ext.event.Event.PAGE_DOWN,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;
					i_self.doKeyEvent("ROLLUP", i_event);
				}
			},
			{
				key: Ext.event.Event.PAGE_UP,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;
					i_self.doKeyEvent("ROLLDOWN", i_event);
				}
			},
			{
				key: Ext.event.Event.ENTER,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;
					i_self.doKeyEvent("ENTER", i_event);
				}
			},
			{
				key: Ext.event.Event.ESC,
				fn: function(n_key, i_event) {

					i_event.preventDefault();

					var i_key = this;
					var i_self = i_key.target.component;
					i_self.doKeyEvent("ATTN", i_event);
				}
			},
			{
				key: Ext.event.Event.UP,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {

						if (!i_event.target.type) {

							i_event.stopEvent();

							var i_cursor = i_self.getCursor();
							var o_position = i_self.getCurrentPosition();

							var a_inputs = IceCap.util.Handler.getInputFields(i_self);

							o_position.lin--;

							if (o_position.lin < 1) {
								o_position.lin = 1;
							}

							var o_box = Ext.apply({
								x: IceCap.util.Handler.getX(o_position.col),
								y: IceCap.util.Handler.getY(o_position.lin),
								width: i_cursor.getWidth(),
								height: i_cursor.getHeight()
							});

							var b_intersect = false;

							Ext.Array.each(a_inputs, function(i_field) {

								var o_bound = i_field.el.dom.getBoundingClientRect();

								var o_rect = Ext.apply({}, {
									x: IceCap.util.Handler.getX(i_field.col),
									y: IceCap.util.Handler.getY(i_field.lin),
									width: o_bound.width,
									height: o_bound.height
								});

								if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
									b_intersect = true;
									i_field.focus(false, 10);


									var n_start = o_position.col - i_field.col;
									var i_inputEl = i_field.inputEl;
									i_inputEl.dom.selectionStart = i_inputEl.dom.selectionEnd = n_start;

									return false;
								}
							});

							if (!b_intersect) {

								i_cursor.moveCursor(o_position);
							}
							i_self.setCurrentPosition(o_position);
						}
						else {
							i_self.doNavigationKey(0, false, i_event);
						}
					}
				}
			},
			{
				key: Ext.event.Event.DOWN,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {

						if (!i_event.target.type) {

							i_event.stopEvent();

							var i_cursor = i_self.getCursor();
							var o_position = i_self.getCurrentPosition();
							var o_inputData = i_self.getInputData();
							var o_window = o_inputData.window;

							var a_inputs = IceCap.util.Handler.getInputFields(i_self);

							o_position.lin++;

							if (o_position.lin > o_window.height) {
								o_position.lin = o_window.height;
							}

							var o_box = Ext.apply({
								x: IceCap.util.Handler.getX(o_position.col),
								y: IceCap.util.Handler.getY(o_position.lin),
								width: i_cursor.getWidth(),
								height: i_cursor.getHeight()
							});

							var b_intersect = false;

							Ext.Array.each(a_inputs, function(i_field) {

								var o_bound = i_field.el.dom.getBoundingClientRect();

								var o_rect = Ext.apply({}, {
									x: IceCap.util.Handler.getX(i_field.col),
									y: IceCap.util.Handler.getY(i_field.lin),
									width: o_bound.width,
									height: o_bound.height
								});

								if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
									b_intersect = true;
									i_field.focus(false, 10);

									var n_start = o_position.col -i_field.col;
									var i_inputEl = i_field.inputEl;
									i_inputEl.dom.selectionStart = i_inputEl.dom.selectionEnd = n_start;

									return false;
								}
							});

							if (!b_intersect) {

								i_cursor.moveCursor(o_position);
							}
							i_self.setCurrentPosition(o_position);
						}
						else {
							i_self.doNavigationKey(1, false, i_event);
						}
					}
				}
			},
			{
				key: Ext.event.Event.LEFT,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {

						if (!i_event.target.type) {
							i_event.stopEvent();

							var i_cursor = i_self.getCursor();
							var o_position = i_self.getCurrentPosition();

							var a_inputs = IceCap.util.Handler.getInputFields(i_self);

							o_position.col--;

							if (o_position.col < 1) {
								o_position.col = 1;
							}

							var o_box = Ext.apply({
								x: IceCap.util.Handler.getX(o_position.col),
								y: IceCap.util.Handler.getY(o_position.lin),
								width: i_cursor.getWidth(),
								height: i_cursor.getHeight()
							});

							var b_intersect = false;

							Ext.Array.each(a_inputs, function(i_field) {

								var o_bound = i_field.el.dom.getBoundingClientRect();

								var o_rect = Ext.apply({}, {
									x: IceCap.util.Handler.getX(i_field.col),
									y: IceCap.util.Handler.getY(i_field.lin),
									width: o_bound.width,
									height: o_bound.height
								});

								if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
									b_intersect = true;
									i_field.focus(false, 10);
									return false;
								}
							});

							if (!b_intersect) {

								i_cursor.moveCursor(o_position);
							}

							i_self.setCurrentPosition(o_position);
						}
					}
				}
			},
			{
				key: Ext.event.Event.RIGHT,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {

						if (!i_event.target.type) {

							i_event.stopEvent();

							var i_cursor = i_self.getCursor();
							var o_position = i_self.getCurrentPosition();
							var o_inputData = i_self.getInputData();

							var a_inputs = IceCap.util.Handler.getInputFields(i_self);

							o_position.col++;

							if (o_position.col > o_inputData.width) {
								o_position.col = o_inputData.width;
							}

							var o_box = Ext.apply({
								x: IceCap.util.Handler.getX(o_position.col),
								y: IceCap.util.Handler.getY(o_position.lin),
								width: i_cursor.getWidth(),
								height: i_cursor.getHeight()
							});

							var b_intersect = false;

							Ext.Array.each(a_inputs, function(i_field) {

								var o_bound = i_field.el.dom.getBoundingClientRect();

								var o_rect = Ext.apply({}, {
									x: IceCap.util.Handler.getX(i_field.col),
									y: IceCap.util.Handler.getY(i_field.lin),
									width: o_bound.width,
									height: o_bound.height
								});

								if (!Ext.draw.Draw.isBBoxIntersect(o_box, o_rect)) {
									b_intersect = true;
									i_field.focus(false, 10);
									return false;
								}
							});

							if (!b_intersect) {

								i_cursor.moveCursor(o_position);
							}

							i_self.setCurrentPosition(o_position);
						}
					}
				}
			},
			{
				key: Ext.event.Event.TAB,
				shift: false,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {

						i_self.doNavigationKey(1, true, i_event);
					}
				}
			},
			{
				key: Ext.event.Event.TAB,
				shift: true,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_activeComponent = Ext.ComponentManager.getActiveComponent();
					var i_content = i_self.getContent();

					if (i_content.contains(i_activeComponent) || i_content.ownerCt == i_activeComponent) {

						i_self.doNavigationKey(0, true, i_event);
					}
				}
			},
			{
				key: Ext.event.Event.NUM_PLUS,
				fn: function(n_key, i_event) {

					var i_key = this;
					var i_self = i_key.target.component;

					var i_field = i_self.getCurrentField();

					if (i_field) {

						var n_start = i_field.inputEl.el.dom.selectionStart;

						var s_text = i_field.getValue();

						s_text = s_text.substr(0, n_start);

						i_field.setValue(s_text);

						i_self.doNavigationKey(1, true, i_event);
					}
				}
			},
			{
				key: Ext.event.Event.HOME,
				ctrl: true,
				alt: false,
				fn: function(n_key, i_event) {

					i_event.stopEvent();

					var i_key = this;
					var i_self = i_key.target.component;

					var b_markerActive = i_self.getMarkerActive();
					var i_marker = i_self.getMarker();

					i_self.setMarkerActive(!b_markerActive);

					i_marker.toggle();
				}
			},
			{
				key: Ext.event.Event.INSERT,
				ctrl: false,
				alt: false,
				fn: function (n_key, i_event) {

					var n_type = i_self.getTypeMode();
					switch (n_type) {
						case IceCap.util.Handler.typeMode.OVERWRITE:
							n_type = IceCap.util.Handler.typeMode.INSERT;
							break;
						default:
							n_type = IceCap.util.Handler.typeMode.OVERWRITE;
							break;
					}

					i_self.setTypeMode(n_type);
				}
			}
		];

		a_bindings = a_bindings.concat(i_self.getFKeys());

		var i_keyMap = Ext.create("Ext.util.KeyMap", {
			target: i_self.getEl(),
			binding: a_bindings
		});
	},

	getFKeys: function() {

		var i_self = this;

		var a_keys = [
			{
				key: Ext.event.Event.F1,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F1", i_event);
				}
			},
			{
				key: Ext.event.Event.F2,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F2", i_event);
				}
			},
			{
				key: Ext.event.Event.F3,
				shift: false,
				alt: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F3", i_event);
				}
			},
			{
				key: Ext.event.Event.F4,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F4", i_event);
				}
			},
			{
				key: Ext.event.Event.F5,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F5", i_event);
				}
			},
			{
				key: Ext.event.Event.F6,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F6", i_event);
				}
			},
			{
				key: Ext.event.Event.F7,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F7", i_event);
				}
			},
			{
				key: Ext.event.Event.F8,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F8", i_event);
				}
			},
			{
				key: Ext.event.Event.F9,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F9", i_event);
				}
			},
			{
				key: Ext.event.Event.F10,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F10", i_event);
				}
			},
			{
				key: Ext.event.Event.F11,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F11", i_event);
				}
			},
			{
				key: Ext.event.Event.F12,
				shift: false,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F12", i_event);
				}
			}
		];

		a_keys = a_keys.concat(i_self.getFShiftKeys());

		return a_keys;
	},

	getFShiftKeys: function() {

		var i_self = this;

		var a_keys = [
			{
				key: Ext.event.Event.F1,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F13", i_event);
				}
			},
			{
				key: Ext.event.Event.F2,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F14", i_event);
				}
			},
			{
				key: Ext.event.Event.F3,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F15", i_event);
				}
			},
			{
				key: Ext.event.Event.F4,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F16", i_event);
				}
			},
			{
				key: Ext.event.Event.F5,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F17", i_event);
				}
			},
			{
				key: Ext.event.Event.F6,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F18", i_event);
				}
			},
			{
				key: Ext.event.Event.F7,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F19", i_event);
				}
			},
			{
				key: Ext.event.Event.F8,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F20", i_event);
				}
			},
			{
				key: Ext.event.Event.F9,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F21", i_event);
				}
			},
			{
				key: Ext.event.Event.F10,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F22", i_event);
				}
			},
			{
				key: Ext.event.Event.F11,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F23", i_event);
				}
			},
			{
				key: Ext.event.Event.F12,
				shift: true,
				fn: function(n_key, i_event) {

					i_self.doKeyEvent("F24", i_event);
				}
			}
		];

		return a_keys;
	},

	createCursor: function () {

		var i_self = this;
		var o_inputData = i_self.getInputData();

		var i_cursor = Ext.widget("icecap-cursor", {
			theme: i_self.getTheme(),
			width: IceCap.util.Handler.getWidth(),
			listeners: {
				show: {
					fn: function (i_cursor) {

						var i_marker = i_self.getMarker();
						var b_active = i_marker.getInUse();

						if (b_active) {
							i_marker.show();
						}
					}
				},
				render: {
					fn: function (i_item) {
						i_item.hide();
					}
				},
				afterrender: {
					fn: function (i_cursor) {

						var i_content = i_self.getContent();

						var a_fields = IceCap.util.Handler.getInputFields(i_content);

						if (a_fields.length === 0) {

							i_cursor.show();

							i_cursor.moveCursor({
								col: o_inputData.csrCol || 1,
								lin: o_inputData.csrLin || 1
							});
						}
					}
				}
			},
			moveCursor: function (o_position) {

				var i_cursor = this;
				var i_marker = i_self.getMarker();

				var n_x = IceCap.util.Handler.getX(o_position.col);
				var n_y = IceCap.util.Handler.getY(o_position.lin + 1);

				var a_pos = [
					n_x,
					n_y
				];

				i_cursor.move([
					n_x,
					n_y - 11
				]);
				i_marker.move([
					n_x - 7,
					n_y - 12
				]);

				i_self.updateCurrentPosition(o_position);
			}
		});

		i_self.setCursor(i_cursor);

		return i_cursor;
	},

	createMarker: function() {

		var i_self = this;

		var i_marker = Ext.widget("icecap-marker", {
			hidden: true,
			active: false,
			inUse: false,
			ui: i_self.getTheme() || "default"
		});

		i_self.setMarker(i_marker);

		return i_marker;
	},

	findFocus: function() {

		var i_self = this;
		var i_main = i_self.getMain();
		var i_content = i_self.getContent();

		var a_fields = IceCap.util.Handler.getInputFields(i_content);

		if (a_fields.length > 0) {

			var i_field = a_fields[0];
			i_field.focus(false, 10);
		}
		else {
			i_main.focus(false, 10);
		}
	},

	doTimer: function() {

		var i_self = this;

		var i_timer = i_self.getTimer();
		if (!i_timer) {
			i_timer = new Ext.util.DelayedTask(function() {
				i_self.setLoading(true);
			});

			i_self.setTimer(i_timer);

			i_timer.delay(1000);
		}
	},

	cancelTimer: function() {

		var i_self = this;

		var i_timer = i_self.getTimer();

		if (i_timer) {
			i_timer.cancel();
			i_self.setTimer(null);
		}
	},

	onError: function(o_inputData) {

		var i_self = this;

		Ext.Msg.show({
			title: "Server Message",
			msg: o_inputData.msgBox.text,
			icon: Ext.MessageBox.INFO,
			buttons: Ext.MessageBox.OK,
			fn: function(btn) {
				i_self.findFocus();
			}
		});
	},

	updateMessage: function (o_inputData) {

		var i_self = this;
		var i_statusbar = i_self.getStatusBar();

		var a_messages = Ext.Array.from(o_inputData.message);

		var a_result = [];

		if (a_messages.length > 1) {

			a_result.push(a_messages[0].text);
		}
		else {
			Ext.Array.each(a_messages, function(o_message) {
				a_result.push(o_message.text);
			});
		}

		var i_messageLabel = i_statusbar.getComponent("icecap-message");

		var s_message = a_result.join(" ");

		if (Ext.String.startsWith(s_message.toLowerCase(), "(c)")) {
			i_messageLabel.removeCls("icecap-statusbar-error");

		}
		else {
			i_messageLabel.addCls("icecap-statusbar-error")
		}
		i_messageLabel.setText(s_message);
	},

	applyFFW: function (o_config) {

		var i_self = this;
		var s_hex = o_config.ffw;
		var b_fixed = IceCap.util.Handler.getFixed();

		var o_field = {
			xtype: "icecap-input"
		};

		var o_fieldStyle = {
		};

		if (o_config.ta) {

			Ext.apply(o_fieldStyle, {
				"text-align": o_config.ta
			});
		}

		if (s_hex) {

			var n_hex = parseInt(s_hex);

			var n_sanHex = IceCap.util.Handler.createIndicators(s_hex);

			if (n_sanHex & IceCap.util.Handler.FFW.BYPASS) {

				Ext.apply(o_field, {
					readOnly: true
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.ALPHA_ONLY) {

				Ext.apply(o_field, {
					maskRe: new RegExp("[a-z A-Z ,.-]")
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.NUMERIC_ONLY) {

				Ext.apply(o_field, {
					maskRe: new RegExp("[+\\-,. 0-9]")
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.DIGITS_ONLY) {

				Ext.apply(o_field, {
					maskRe: new RegExp("[0-9]")
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.MOD_DATA) {

				Ext.apply(o_field, {
					listeners: {
						afterrender: {
							fn: function (i_field) {

								i_field.originalValue = 0xFF;
							},
							single: true
						}
					}
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.AUTO_ENTER) {

				// THIS WE DONT NEED IN THE MODERN WORLD...

				// Ext.apply(o_field, {
				// 	listeners: {
				// 		blur: {
				// 			fn: function(i_field) {
				// 				i_self.doKeyEvent("ENTER");
				// 			}
				// 		}
				// 	}
				// });
			}

			if (n_sanHex & IceCap.util.Handler.FFW.MONOCASE) {

				// Ext.apply(o_fieldStyle, {
				// 	"text-transform": "uppercase"
				// });
			}

			if (n_sanHex & IceCap.util.Handler.FFW.MAND_ENTER) {

				Ext.apply(o_field, {
					allowBlank: false
				});
			}

			if (n_sanHex & IceCap.util.Handler.FFW.RA_ZEROFILL ||
				n_sanHex & IceCap.util.Handler.FFW.RA_BLANKFILL ||
				n_sanHex & IceCap.util.Handler.FFW.RA_MANDATORY) {

				Ext.apply(o_fieldStyle, {
					"text-align": "right"
				});
			}

			if (o_config.atr == "27" && n_hex & (1 << 13)) {

				Ext.apply(o_field, {
					hidden: true,
					disabled: true
				});
			}
		}

		Ext.apply(o_field, {
			fieldStyle: o_fieldStyle
		});

		return o_field;
	},

	updateCurrentPosition: function (o_position) {

		var i_self = this;
		var i_statusbar = i_self.getStatusBar();

		if (i_statusbar) {
			var i_position = i_statusbar.getComponent("icecap-position");

			if (i_position) {

				var a_result = [
					o_position.lin,
					o_position.col
				];

				i_position.setText(a_result.join("/"));
			}

			i_self.updateTypeMode(i_self.getTypeMode())
		}
	},

	updateTypeMode: function (n_type) {

		var i_self = this;

		var i_statusbar = i_self.getStatusBar();

		if (i_statusbar) {

			var i_typeLabel = i_statusbar.getComponent("icecap-typemode");

			var a_mode = [
			];

			if (i_typeLabel) {

				switch (n_type) {
					case IceCap.util.Handler.typeMode.OVERWRITE:
						a_mode.push(" DEL");
						break;

					default:
						a_mode.push(" INS");
						break;
				}

				i_typeLabel.setText(a_mode.join(" "));
			}
		}
	},
	updateEdit: function(value) {

		var i_self = this;
		
		if (i_self.rendered) {
			var o_inputData = i_self.getInputData();

			i_self.redraw();
		}
	}
});
