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
	},

	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();

		return n_value;
	},

	getBoldColSize: function() {

		var i_self = this;
		var n_value = 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",
				fontSize: "14px",
				fontWeight: "400",
				minHeight: "24px"
			}
		};

		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();
});
