{
	xtype: "menu",
	onInitialize: function(i_owner, i_object, s_type) {

		var i_self = this;
		var a_records = a_objectRecord = Ext.Array.from(i_object.records);
		var i_entityForm = s_type == "form" ? Ext.getCmp(i_object.formId) : {};
		var i_parentGrid = Ext.getCmp(i_object.parentId);
		var i_store = i_parentGrid ? i_parentGrid.getStore() : null;	

		var a_items = i_self.createItems(s_type, i_store, i_entityForm, a_records);

		return a_items;
	},

	createItems: function(s_type, i_store, i_entityForm, a_records) {

		var i_self = this;

		var s_xtype = s_type == "grid" ? "themedmenuitem" : "themedbutton";

		var a_items = [];

		var i_resend = Ext.widget(s_xtype, {
			text: ip2.i18n({
				en: "Resend",
				da: "Send igen"
			}),
			itemId: "itmResend",
			iconCls: "icon-resend",
			handler: function() {

				var s_message = "";

				var i_template = Ext.create("Ext.XTemplate",
					"<tpl>",
						"<div>{start}</div>",
						"<div>{subjet}</div>",
						"<div>" + ip2.i18n({
							en: "To: ",
							da: "Til: "
						}) + "<strong>{reciever}</strong></div>",
						"<br></br>",
					"</tpl>"
				);

				i_template.compile();

				var s_timestamp = ip2.createIsoTimeStamp();

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

					i_record.set({
						NTFSTS: 0,
						NTFUPDTS: s_timestamp,
						NTFSBJ: "RS: " + i_record.get("NTFSBJ")
					});

					if (s_type == "form") {

						var i_form = i_entityForm.getForm();

						i_form.setValues({
							NTFUPDTS: s_timestamp,
							NTFSTS: 0
						});
					}

					var o_values = {
						start: ip2.i18n({
							en: "Following has been resendt",
							da: "Følgende er gensendt"
						}),
						token: i_record.get("NTFNTFTKN"),
						subject: i_record.get("NTFSBJ"),
						receiver: i_record.get("NTFRCP")
					};

					s_message += i_template.apply(o_values);
				});

				i_self.upsertRows(a_records, function() {

					ip2.messageBox({
						title: "Info",
						icon: Ext.Msg.QUESTION,
						message: s_message,
						yesText: "Ok",
						yesFn: function() {
							if (i_store) {
								i_store.loadPage(1);
							}
						}
					});
				});
			}
		});

		var i_forward = i_self.createForwardItem(s_type, i_store, a_records);

		a_items.push(i_resend);
		a_items.push(i_forward);

		return a_items;
	},

	createForwardItem: function(s_type, i_store, a_records) {

		var i_self = this;

		var s_xtype = s_type == "grid" ? "themedmenuitem" : "themedbutton";
		
		var i_forward = Ext.widget(s_xtype, {
			text: ip2.i18n({
				en: "Forward",
				da: "Videresend"
			}),
			itemId: "itmForward",
			iconCls: "icon-forward",
			handler: function() {

				var i_formpanel = Ext.widget("form", {
					bodyPadding: 5,
					layout: {
						type: "hbox",
						align: "middle"
					},
					items: [
						{
							xtype: "textfield",
							fieldLabel: ip2.i18n({
								en: "E-mail",
								da: "E-mail"
							}),
							flex: 1,
							allowBlank: false,
							itemId: "txtEmail",
							msgTaget: "side",
							vtype: "email",
							name: "email"
						}
					],
					listeners: {
						validityChange: {
							fn: function(i_form, b_valid) {

								var i_panel = this;

								var i_buttonOk = i_panel.down("#button-ok");

								if (i_buttonOk) {
									i_buttonOk[b_valid ? "enable" : "disable"]();
								}
							}
						}
					}
				});

				i_formpanel.isValid();

				var i_window = Ext.widget("window", {
					width: 600,
					height: 130,
					title: ip2.i18n({
						en: "Enter e-mail",
						da: "Indtast e-mail"
					}),
					layout: "fit",
					modal: true,
					closable: false,
					listeners: {
						destroy: {
							fn: function() {

								Ext.Ajax.request({
									url: "/wsh-services/popnotifications.aspx",
									method: "GET",
									success: function() {
										if (i_store) {
											i_store.loadPage(1);
										}
									}
								});
							}
						}
					},
					items: [
						i_formpanel
					]
				});

				var i_buttonOk = Ext.widget("themedbutton", {
					text: ip2.i18n({
						en: "OK",
						da: "OK"
					}),
					itemId: "button-ok",
					iconCls: "icon-save",
					handler: function() {

						var a_upsert = [];

						var s_message = "";

						var i_template = Ext.create("Ext.XTemplate",
							"<tpl>",
								"<div>{subject}</div>",
								"<div>" + ip2.i18n({
									en: "Has been forwarded to ",
									da: "Sendt til følgende "
								}) + "</div>",
								"<div><strong>{reciever}</strong></div>",
								"<br></br>",
							"</tpl>"
						);

						i_template.compile();

						var s_timestamp = ip2.createIsoTimeStamp();

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

							var i_create = i_record.copy();

							var o_values = i_formpanel.getValues();

							i_create.set({
								NTFNTFTKN: null,
								NTFSBJ: "FW: " + i_record.get("NTFSBJ"),
								NTFCRTTS: s_timestamp,
								NTFUPDTS: s_timestamp,
								NTFRCP: o_values.email,
								NTFSTS: 0
							});

							a_upsert.push(i_create);

							var o_templateValues = {
								subject: i_record.get("NTFSBJ"),
								reciever: o_values.email
							};

							s_message += i_template.apply(o_templateValues);
						});

						i_self.upsertRows(a_upsert, function() {

							ip2.messageBox({
								title: "Info",
								icon: Ext.Msg.QUESTION,
								message: s_message,
								yesText: "Ok",
								yesFn: function() {
									i_window.close();
								}
							});
						});
					}
				});

				var i_buttonClose = Ext.widget("themedbutton", {
					text: ip2.i18n({
						en: "Close",
						da: "Luk"
					}),
					iconCls: "icon-close",
					handler: function() {
						i_window.close();
					}
				});

				var i_toolbar = Ext.widget("toolbar", {
					ui: "footer",
					dock: "bottom",
					defaults: {
						minWidth: 70
					},
					items: [
						"->",
						i_buttonOk,
						i_buttonClose
					]
				});

				i_formpanel.addDocked(i_toolbar);

				i_window.show();
			}
		});

		return i_forward;
	},

	upsertRows: function(a_records, f_callback) {

		var a_batch = [];

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

			var o_keys = ip2.getKeysFromRecord(i_record);

			a_batch.push({
				type: "upsert",
				dmd: "dmd/webshop.dmd",
				entity: "WSHNTFTR00",
				key: o_keys,
				row: i_record.getData()
			});
		});

		Ext.Ajax.request({
			url: "/ip2-Services/ip2dmdproxy.aspx",
			jsonData: {
				batch: a_batch
			},
			success: function (o_response) {

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

				Ext.Array.each(o_result.batch, function(o_batch) {
					Ext.Array.each(o_batch.row, function(o_values, n_index) {

						var i_record = a_records[n_index];
						i_record.set(o_values);
					});
				});

				f_callback(a_records);
			}
		});
	}
}
