Ext.define("Portfolio.Router", {
	extend: "Ext.app.Controller",

	alternateClassName: [
		"Ext.ux.Router"
	],

	listen: {
		controller: {
			"*": {
				unmatchedroute: "onUnmatchedroute"
			}
		}
	},

	statics: {
		proxy: "/ip2-services/ip2dmdProxy.aspx",
		runDmdView: "/portfolio/ip2-run-dmd.js?entity={0}&dmd={1}&view={2}",
		runDmd: "/portfolio/ip2-run-dmd.js?entity={0}&dmd={1}",
		defaultDmd: "dmd/webshop.dmd",
		seourl: "/ip2-services/wshProxy.aspx",
		widget: "/wsh-widgets/",
		dynapp: "/portfolio/ip2-run-dynapp.js?lib={0}&file={1}"
	},

	routes: {

		"entity/:entity/:dmd": {
			action: "onEntityGrid",
			before: "onBeforeRoute",
			conditions: {
				":entity": "([\\w+]{1,})",
				":dmd": "([A-Za-z\\/._0-9]+)"
			}
		},

		"dynapp/:lib/:file": {
			before: "onBeforeRoute",
			action: "onDynApp"
		},

		"widget/:src": {
			action: "onWidget",
			before: "onBeforeRoute",
			conditions: {
				":src": "(.+)"
			}
		},

		"dynapp-:lib-:file": {
			before: "onBeforeRoute",
			action: "onDynApp"
		},

		"widget-:src": {
			action: "onWidget",
			before: "onBeforeRoute",
			conditions: {
				":src": "(.+)"
			}
		},

		"widget-:entity-:token-:xpd-:dmd": {
			action: "onWidgetForm",
			before: "onBeforeRoute",
			conditions: {
				":entity": "([\\w+]{1,})",
				":token": "([0-9]+)",
				":xpd": "(.{1,30})",
				":dmd": "([A-Za-z\\/._0-9]+)"
			}
		},

		"entity-:entity": {
			action: "onEntityGrid",
			before: "onBeforeRoute",
			conditions: {
				":entity": "([\\w+]{1,})"
			}
		},

		"entity-:entity-:dmd": {
			action: "onEntityGrid",
			before: "onBeforeRoute",
			conditions: {
				":entity": "([\\w+]{1,})",
				":dmd": "([A-Za-z\\/._0-9]+)"
			}
		},

		"entity-:entity-:token": {
			action: "onEntityForm",
			before: "onBeforeRoute",
			conditions: {
				":entity": "([\\w+]{1,})",
				":token": "([0-9]+)"
			}
		},

		"entity-:entity-:token-:dmd": {
			action: "onEntityForm",
			before: "onBeforeRoute",
			conditions: {
				":entity": "([\\w+]{1,})",
				":token": "([0-9]+)",
				":dmd": "([A-Za-z\\/._0-9]+)"
			}
		},

		"entity-:entity-:token-:tabindex-:dmd": {
			action: "onEntityFormTabIndex",
			before: "onBeforeRouteTabIndex",
			conditions: {
				":entity": "([\\w+]{1,})",
				":token": "([0-9]+)",
				":tabindex": "([0-9]+)",
				":dmd": "([A-Za-z\\/._0-9]+)"
			}
		},

		"entity-:entity-:view-:dmd": {
			action: "onEntityGridView",
			before: "onBeforeRoute",
			conditions: {
				":entity": "([\\w+]{1,})",
				":view": "([A-Za-z]+)",
				":dmd": "([\\w \\/.]+)"
			}
		},

		"entity-:entity-:view-:token-:dmd": {
			action: "onEntityViewForm",
			before: "onBeforeRoute",
			conditions: {
				":entity": "([\\w+]{1,})",
				":view": "([A-Za-z]+)",
				":token": "([0-9]+)",
				":dmd": "([\\w \\/.]+)"
			}
		},

		"entity-:entity-:view-:token-:tabindex-:dmd": {
			action: "onEntityViewFormTab",
			before: "onBeforeRoute",
			conditions: {
				":entity": "([\\w+]{1,})",
				":view": "([A-Za-z]+)",
				":token": "([0-9]+)",
				":tabindex": "([0-9]+)",
				":dmd": "([\\w \\/.]+)"
			}
		},

		":mode-widget-:src": {
			action: "onWidgetWindow",
			before: "onBeforeWindowRoute",
			conditions: {
				":mode": "([0-9]{1})",
				":src": "(.+)"
			}
		},

		":mode-entity-:entity": {
			action: "onEntityGridWindow",
			before: "onBeforeWindowRoute",
			conditions: {
				":mode": "([0-9]{1})",
				":entity": "([\\w+]{1,10})"
			}
		},

		":mode-entity-:entity-:dmd": {
			action: "onEntityGridWindow",
			before: "onBeforeWindowRoute",
			conditions: {
				":mode": "([0-9]{1})",
				":entity": "([\\w+]{1,})",
				":dmd": "([A-Za-z\\/._0-9]+)"
			}
		},

		":mode-entity-:entity-:view-:dmd": {
			action: "onEntityGridViewWindow",
			before: "onBeforeWindowRoute",
			conditions: {
				":mode": "([0-9]{1})",
				":entity": "([\\w+]{1,})",
				":view": "([A-Za-z]+)",
				":dmd": "([A-Za-z\\/._0-9]+)"
			}
		},

		":mode-entity-:entity-:token-:dmd": {
			action: "onEntityFormWindow",
			before: "onBeforeWindowRoute",
			conditions: {
				":mode": "([0-9]{1})",
				":entity": "([\\w+]{1,})",
				":token": "([0-9]+)",
				":dmd": "([A-Za-z\\/._0-9]+)"
			}
		},

		":mode-entity-:entity-:token-:tabindex-:dmd": {
			action: "onEntityFormTabIndexWindow",
			before: "onBeforeWindowRoute",
			conditions: {
				":mode": "([0-9]{1})",
				":entity": "([\\w+]{1,})",
				":token": "([0-9]+)",
				":tabindex": "([0-9]+)",
				":dmd": "([A-Za-z\\/._0-9]+)"
			}
		},

		":app-:paths-:config": {
			action: "onApplication",
			before: "onBeforeAppication",
			conditions: {
				":app": "(\\w+(?:\\.\\w+)*)",
				":paths": "([\\w%=.&]+)",
				":config": "([\\w%=.&]+)"
			}
		},

		":mode-:app-:paths-:config": {
			action: "onApplicationWindow",
			before: "onBeforeAppication",
			conditions: {
				":mode": "([0-9]{1})",
				":app": "(\\w+(?:\\.\\w+)*)",
				":paths": "([\\w%=.&]+)",
				":config": "([\\w%=.&]+)"
			}
		}
	},

	onBeforeAppication: function(n_mode, s_main, s_path, s_config, i_action) {

		if (s_config.resume) {
			i_action = s_config;
		}

		if (Portfolio.login.util.Handler.isLogedOn()) {
			i_action.resume();
		}
		else {

			i_action.stop(true);
		}

	},

	onApplication: function(s_main, s_path, s_config) {

		var o_paths = Ext.urlDecode(s_path);
		var o_appconfig = Ext.urlDecode(s_config);

		var o_config = Ext.apply({}, {
			enabled: true,
			disableCaching: true,
			paths: o_paths
		});

		Ext.Loader.setConfig(o_config);

		Portfolio.app.fireEvent("applicationAdd", s_main, o_appconfig, null);

		this.redirectTo("");
	},

	onApplicationWindow: function(n_mode, s_main, s_path, s_config) {

		var o_paths = Ext.urlDecode(s_path);
		var o_appconfig = Ext.urlDecode(s_config);

		var o_config = Ext.apply({}, {
			enabled: true,
			disableCaching: true,
			paths: o_paths
		});

		Ext.Loader.setConfig(o_config);

		var s_title = ip2.i18n(o_appconfig.title);
		delete o_appconfig.title;
		o_appconfig.closable = false;

		var i_application = Ext.create(s_main, o_appconfig);

		var o_size = ip2.getWindowSize();

		var i_window = Ext.widget("window", {
			title: s_title,
			layout: "fit",
			width: o_size.width * 0.9,
			height: o_size.height * 0.9,
			items: [
				i_application
			]
		});

		i_window.show();
	},

	onDynApp: function(s_lib, s_file) {

		var i_self = this;
		var o_statics = i_self.statics();

		var s_src = o_statics.dynapp.replace("{0}", s_lib).replace("{1}", s_file);

		var o_config = {
			text: s_src,
			title: s_src,
			url: s_src
		};

		o_config.url = s_src;

		Portfolio.app.fireEvent("startapplication", o_config);
	},

	onEntityGrid: function(s_entity, s_dmd) {

		var i_self = this;
		var o_statics = i_self.statics();

		s_dmd = s_dmd || o_statics.defaultDmd;

		if (s_dmd != o_statics.defaultDmd) {
			s_dmd = s_dmd.replace(/\\/g, "/");
		}

		var o_dmd = ip2.resource.get(s_dmd);
		var o_entity;

		if (o_dmd && o_dmd.model) {
			s_entity = s_entity;

			o_entity = Ext.Array.findBy(o_dmd.model.entities, function(o_value) {
				return o_value.name.toUpperCase() == s_entity.toUpperCase();
			});

			if (o_entity) {

				var s_url = o_statics.runDmd.replace("{0}", s_entity).replace("{1}", s_dmd);

				var o_config = {
					text: ip2.i18n(o_entity.title),
					title: ip2.i18n(o_entity.title),
					url: s_url
				};

				Portfolio.app.fireEvent("startapplication", o_config);
			}
		}
	},

	onEntityGridView: function(s_entity, s_view, s_dmd) {

		var i_self = this;
		var o_statics = i_self.statics();

		s_view = s_view || "portfolio";
		s_dmd = s_dmd || o_statics.defaultDmd;

		if (s_dmd != o_statics.defaultDmd) {
			s_dmd = s_dmd.replace(/\\/g, "/");
		}

		var o_dmd = ip2.resource.get(s_dmd);
		var o_entity;

		if (o_dmd && o_dmd.model) {
			s_entity = s_entity;

			o_entity = Ext.Array.findBy(o_dmd.model.entities, function(o_value) {
				return o_value.name.toUpperCase() == s_entity.toUpperCase();
			});

			if (o_entity) {

				var s_url = o_statics.runDmdView.replace("{0}", s_entity).replace("{1}", s_dmd).replace("{2}", s_view);

				var o_config = {
					text: ip2.i18n(o_entity.title),
					title: ip2.i18n(o_entity.title),
					url: s_url
				};

				Portfolio.app.fireEvent("startapplication", o_config);
			}
		}
	},

	onEntityForm: function(s_entity, s_token, s_dmd) {

		var i_self = this;
		var o_statics = i_self.statics();

		s_dmd = s_dmd || o_statics.defaultDmd;
		s_entity = s_entity;

		var o_config = {
			dmd: s_dmd,
			entityName: s_entity,
			context: "form",
			uiName: "portfolio",
			activeTabIndex: 0,
			linkable: false,
			deletable: false
		};

		var i_model = ip2.model(o_config);
		var i_record = i_model.create();

		i_record.set(i_record.idProperty, s_token);

		var o_keys = {};
		o_keys[i_record.idProperty] = i_record.get(i_record.idProperty);

		o_config.keys = o_keys;

		Portfolio.app.fireEvent("entityedit", o_config, "update");
	},

	onEntityFormTabIndex: function(s_entity, s_token, s_tabindex, s_dmd) {

		var i_self = this;
		var o_statics = i_self.statics();

		s_dmd = s_dmd || o_statics.defaultDmd;
		s_entity = s_entity;

		var o_config = {
			dmd: s_dmd,
			entityName: s_entity,
			context: "form",
			uiName: "portfolio",
			activeTabIndex: parseFloat(s_tabindex)
		};

		var i_model = ip2.model(o_config);
		var i_record = i_model.create();

		i_record.set(i_record.idProperty, s_token);

		var o_keys = {};
		o_keys[i_record.idProperty] = i_record.get(i_record.idProperty);

		o_config.keys = o_keys;

		Portfolio.app.fireEvent("entityedit", o_config, "update");
	},

	onEntityViewForm: function(s_entity, s_view, s_token, s_dmd) {

		var i_self = this;
		var o_statics = i_self.statics();

		var o_config = {
			dmd: s_dmd,
			entityName: s_entity,
			context: "form",
			uiName: s_view || "portfolio",
			activeTabIndex: 0
		};

		var i_model = ip2.model(o_config);
		var i_record = i_model.create();

		i_record.set(i_record.idProperty, s_token);

		var o_keys = {};
		o_keys[i_record.idProperty] = i_record.get(i_record.idProperty);

		o_config.keys = o_keys;

		Portfolio.app.fireEvent("entityedit", o_config, "update");
	},

	onEntityViewFormTab: function(s_entity, s_view, s_token, s_tabindex, s_dmd) {

		var i_self = this;
		var o_statics = i_self.statics();

		var o_config = {
			dmd: s_dmd,
			entityName: s_entity,
			context: "form",
			uiName: s_view || "portfolio",
			activeTabIndex: parseFloat(s_tabindex) || 0
		};

		var i_model = ip2.model(o_config);
		var i_record = i_model.create();

		i_record.set(i_record.idProperty, s_token);

		var o_keys = {};
		o_keys[i_record.idProperty] = i_record.get(i_record.idProperty);

		o_config.keys = o_keys;

		Portfolio.app.fireEvent("entityedit", o_config, "update");
	},

	onWidget: function(s_src) {

		var i_self = this;
		var o_statics = i_self.statics();

		var s_text = s_src.toLowerCase();

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

		var o_config = {
			text: s_text,
			title: s_text,
			url: s_src,
			urlParams: o_params
		};

		if (s_src.indexOf("/") == -1) {
			s_src = o_statics.widget + s_src;
		}

		var a_split = s_src.split(".");

		var s_pop = a_split.pop();

		if (s_pop != "widget") {
			s_src = s_src + ".widget";
		}

		o_config.url = s_src;

		Portfolio.app.fireEvent("startapplication", o_config);
	},

	onWidgetForm: function(s_entity, s_token, s_xpd, s_dmd) {

		var i_self = this;
		var s_prop;
		var s_ID;
		var s_PARENTID;

		switch (s_entity) {
			case "WSHMNUET00":
				s_prop = "MNUPROP";
				s_PARENTID = "MNUPNTTKN";
				s_ID = "MNUMNUTKN";
				break;
			case "WSHFLDET00":
				s_prop = "FLDPROP";
				s_PARENTID = "FLDPNTTKN";
				s_ID = "FLDFLDTKN";
				break;
			case "WSHNAMET00":
				s_prop = "NAMPROP";
				s_PARENTID = "NAMPNTTKN";
				s_ID = "NAMNAMTKN";
				break;
			case "NAVMNUET00":
				s_prop = "MNUPROP";
				s_PARENTID = "MNUPNTTKN";
				s_ID = "MNUMNUTKN";
				break;
			case "NAVMNUET00":
				s_prop = "QSTPROP";
				s_PARENTID = "QSTPNTTKN";
				s_ID = "QSTQSTTKN";
				break;
		}

		var o_statics = i_self.statics();
		var o_xpd;

		var o_propertyNameMapping = {
			ID: s_ID,
			PARENTID: s_PARENTID,
			PROPERTIES: s_prop
		};

		s_dmd = s_dmd || o_statics.defaultDmd;
		s_entity = s_entity;

		if (s_xpd.indexOf(".") == -1) {
			s_xpd = s_xpd + ".xpd";
		}

		var o_config = {
			dmd: s_dmd,
			entityName: s_entity,
			context: "grid",
			uiName: "portfolio"
		};

		var i_model = ip2.model(o_config);
		var i_record = i_model.create();

		var o_key = {};
		o_key[i_record.idProperty] = s_token;

		var o_params = {
			action: "getRow",
			dmd: s_dmd || "dmd/webshop.dmd",
			model: s_entity,
			uiName: "",
			context: "",
			key: Ext.encode(o_key)
		};

		var s_params = ip2.param(o_params);

		Ext.Ajax.request({
			url: "/ip2-Services/ip2dmdproxy.aspx?" + s_params,
			success: function (o_response) {

				var o_result = Ext.decode(o_response.responseText, true) || {};
				var a_records = o_result.rows || [];

				if (a_records.length > 0) {
					i_record.set(a_records[0]);
					if (s_xpd) {
						o_xpd = ip2.resource.get(s_xpd);

						var o_flatten = ip2.xpd.flatten(o_xpd);

						o_xpd.flatten = o_flatten;

						var o_properties = Ext.decode(i_record.get(s_prop), true) || {};
						var o_collection = {};

						if (o_flatten.collections[o_properties[o_xpd.idProperty]]) {
							o_collection = o_flatten.collections[o_properties[o_xpd.idProperty]];
						}

						var i_window = Ext.widget("xpd.editor.window", {
							title: ip2.i18n({
								da: "Redigér",
								en: "Edit"
							}) + " - " +
								ip2.i18n(o_properties.TITLE) || ip2.i18n(o_properties.text) + " - " +
								i_record.get(i_record.idProperty),
							xpd: o_xpd,
							modal: true,
							propertyNameMapping: o_propertyNameMapping,
							record: i_record,
							action: "update",
							entity: s_entity,
							languageService: "",
							dmdFile: s_dmd || "dmd/webshop.dmd",
							preSave: function(a_modifed, f_callback) {
								f_callback();
							},
							doSave: function(i_record, i_node, s_value, f_callback) {

								var i_editor = this;

								i_self.onWidgetSave(o_params, i_record, i_editor, s_value, function() {
									f_callback(i_record);
								});
							}
						});

						i_window.show();
					}
				}
			}
		});
	},

	onWidgetSave: function(o_params, i_record, i_editor, s_value, f_callback) {

		var o_key = {};
		o_key[i_record.idProperty] = i_record.get(i_record.idProperty);

		var o_json = {};

		o_json[i_record.idProperty] = i_record.get(i_record.idProperty);
		o_json[i_editor.propertyNameMapping.PROPERTIES] = s_value;

		i_record.set(i_editor.propertyNameMapping.PROPERTIES, s_value);

		var s_params = ip2.param({
			action: "updateRow",
			dmd: o_params.dmd || "dmd/webshop.dmd",
			model: o_params.model,
			uiName: o_params.uiName,
			context: o_params.context
		});

		Ext.Ajax.request({
			url: "/ip2-services/ip2dmdProxy.aspx?" + s_params + "&key= " + Ext.encode(o_key),
			jsonData: o_json,
			success: function () {
				f_callback();
			}
		});
	},

	onBeforeRoute: function(s_entity, s_token, s_xpd, s_dmd, n_window, action) {

		// TEST TO SEE WHAT IS THE ACTION OBJECT
		var i_action;
		if (s_token.resume) {
			i_action = s_token;
		}
		else if (s_xpd.resume) {
			i_action = s_xpd;
		}
		else if (s_dmd.resume) {
			i_action = s_dmd;
		}
		else if (n_window.resume) {
			i_action = n_window;
		}
		else {
			i_action = action;
		}
		if (Portfolio.login.util.Handler.isLogedOn()) {
			i_action.resume();
			this.redirectTo("");
		}
		else {
			i_action.stop(true);
		}

	},

	onBeforeRouteTabIndex: function(s_entity, s_token, s_tabindex, s_dmd, action) {

		// TEST TO SEE WHAT IS THE ACTION OBJECT
		var i_action;
		if (s_token.resume) {
			i_action = s_token;
		}
		else if (s_tabindex.resume) {
			i_action = s_tabindex;
		}
		else if (s_dmd.resume) {
			i_action = s_dmd;
		}
		else {
			i_action = action;
		}

		if (Portfolio.login.util.Handler.isLogedOn()) {
			i_action.resume();
			this.redirectTo("");
		}
		else {
			i_action.stop(true);
		}
	},

	onBeforeWindowRoute: function(n_window, s_entity, s_token, s_xpd, s_dmd, action) {

		// TEST TO SEE WHAT IS THE ACTION OBJECT
		var i_action;
		if (s_entity.resume) {
			i_action = s_entity;
		}
		if (s_token.resume) {
			i_action = s_token;
		}
		else if (s_xpd.resume) {
			i_action = s_xpd;
		}
		else if (s_dmd.resume) {
			i_action = s_dmd;
		}
		else if (n_window.resume) {
			i_action = n_window;
		}
		else {
			i_action = action;
		}

		if (Portfolio.login.util.Handler.isLogedOn()) {
			i_action.resume();
			this.redirectTo("");
		}
		else {
			i_action.stop(true);
		}
	},

	onWidgetWindow: function(n_mode, s_src) {

		s_src = s_src.toLowerCase();

		var i_self = this;
		var o_statics = i_self.statics();

		var o_config = {
			text: s_src,
			title: s_src,
			url: s_src,
			urlParams: Ext.Object.fromQueryString(ip2.qrystr())
		};

		if (s_src.indexOf("/") == -1) {
			s_src = o_statics.widget + s_src;
		}

		var a_split = s_src.split(".");

		var s_pop = a_split.pop();

		if (s_pop != "widget") {
			s_src = s_src + ".widget";
		}

		o_config.url = s_src;

		var o_size = ip2.getWindowSize();

		var i_widget = ip2.callWidget(o_config);

		var i_window = Ext.widget("window", {
			title: ip2.i18n(o_config.title),
			layout: "fit",
			width: o_size.width * 0.9,
			height: o_size.height * 0.9,
			listeners: {
				afterrender: {
					fn: function(i_window) {
						i_window.add(i_widget);
						i_widget.show();
					}
				}
			}
		});

		i_window.show();
	},

	onEntityGridWindow: function(n_window, s_entity, s_dmd) {

		var i_self = this;
		var o_statics = i_self.statics();

		s_dmd = s_dmd || o_statics.defaultDmd;

		if (s_dmd != o_statics.defaultDmd) {
			s_dmd = s_dmd.replace(/\\/g, "/");
		}

		var o_dmd = ip2.resource.get(s_dmd);
		var o_entity;

		if (o_dmd && o_dmd.model) {
			s_entity = s_entity;

			o_entity = Ext.Array.findBy(o_dmd.model.entities, function(o_value) {
				return o_value.name.toUpperCase() == s_entity.toUpperCase();
			});

			if (o_entity) {

				var o_size = ip2.getWindowSize();

				var i_grid = Ext.widget("ip2pagingGrid", {
					text: ip2.i18n(o_entity.title),
					title: ip2.i18n(o_entity.title),
					dmd: {
						path: s_dmd,
						entityName: s_entity
					},
					uiName: "portfolio",
					transactiontype: s_entity
				});

				var i_window = Ext.widget("window", {
					title: ip2.i18n(o_entity.title),
					layout: "fit",
					items: [
						i_grid
					],
					width: o_size.width * 0.9,
					height: o_size.height * 0.9
				});

				i_window.show();
			}
		}
	},

	onEntityGridViewWindow: function(n_window, s_entity, s_view, s_dmd) {

		var i_self = this;
		var o_statics = i_self.statics();

		s_dmd = s_dmd || o_statics.defaultDmd;

		if (s_dmd != o_statics.defaultDmd) {
			s_dmd = s_dmd.replace(/\\/g, "/");
		}

		var o_dmd = ip2.resource.get(s_dmd);
		var o_entity;

		if (o_dmd && o_dmd.model) {
			s_entity = s_entity;

			o_entity = Ext.Array.findBy(o_dmd.model.entities, function(o_value) {
				return o_value.name.toUpperCase() == s_entity.toUpperCase();
			});

			if (o_entity) {

				var o_size = ip2.getWindowSize();

				var i_grid = Ext.widget("ip2pagingGrid", {
					text: ip2.i18n(o_entity.title),
					title: ip2.i18n(o_entity.title),
					dmd: {
						path: s_dmd,
						entityName: s_entity
					},
					uiName: s_view,
					transactiontype: s_entity
				});

				var i_window = Ext.widget("window", {
					title: ip2.i18n(o_entity.title),
					layout: "fit",
					items: [
						i_grid
					],
					width: o_size.width * 0.9,
					height: o_size.height * 0.9
				});

				i_window.show();
			}
		}
	},

	onEntityFormWindow: function(n_window, s_entity, s_token, s_dmd) {

		var i_self = this;
		var o_statics = i_self.statics();

		s_dmd = s_dmd || o_statics.defaultDmd;
		s_entity = s_entity;

		var o_config = {
			dmd: s_dmd,
			entityName: s_entity,
			context: "form",
			uiName: "portfolio",
			activeTabIndex: 0
		};

		var i_model = ip2.model(o_config);
		var i_record = i_model.create();

		i_record.set(i_record.idProperty, s_token);

		i_record.set(i_record.idProperty, s_token);

		var o_keys = {};
		o_keys[i_record.idProperty] = i_record.get(i_record.idProperty);

		o_config.keys = o_keys;

		Portfolio.app.fireEvent("entityWindow", o_config, "update");
	},

	onEntityFormTabIndexWindow: function(n_window, s_entity, s_token, s_tabindex, s_dmd) {

		var i_self = this;
		var o_statics = i_self.statics();

		s_dmd = s_dmd || o_statics.defaultDmd;
		s_entity = s_entity;

		var o_config = {
			dmd: s_dmd,
			entityName: s_entity,
			context: "form",
			uiName: "portfolio",
			activeTabIndex: parseFloat(s_tabindex)
		};

		var i_model = ip2.model(o_config);
		var i_record = i_model.create();

		i_record.set(i_record.idProperty, s_token);

		var o_keys = {};
		o_keys[i_record.idProperty] = i_record.get(i_record.idProperty);

		o_config.keys = o_keys;

		Portfolio.app.fireEvent("entityWindow", o_config, "update");
	},

	onUnmatchedroute: function(s_hash) {
		this.redirectTo("");
	}

}, function() {
	Portfolio.Router.instance = new Portfolio.Router();
});
