function McxElementContent(parentElement)
{
	this.ParentElement = parentElement;
	this.LabelTd = this.ParentElement.children[0];
	if (this.LabelTd)
	{
		if (this.LabelTd.tagName === "td")
		{
			this.LabelElement = this.LabelTd.children[0];
		}
		else
		{
			this.LabelElement = this.LabelTd;
		}
	}
	
	this.InstanceID = this.ParentElement.getAttribute("data-instance-id");
	this.ECID = this.ParentElement.getAttribute("data-ecid");

	if (this.LabelElement)
	{
		this.LabelElement.NativeObject = this;
		this.LabelElement.addEventListener("contextmenu", function(e)
		{
			var cm = new ContextMenu();
			var ecid = this.NativeObject.ECID;
			var iid = this.NativeObject.InstanceID;
			cm.Items = [

				{
					"JJJJ": this.NativeObject,
					"ClassName": "MenuItemCommand",
					"Title": "Show Field Properties",
					"Visible": true,
					"Execute": function()
					{
						var popup = Popup.create(this.JJJJ.LabelTd);

						var listview = ListView.create(popup.ParentElement, {
							"columns": [
								{
									"id": "ecid",
									"title": "ECID"
								},
								{
									"id": "iid",
									"title": "Instance ID"
								}
							],
							"items": [
								{
									"columns": [
										{
											"id": "ecid",
											"value": ecid
										},
										{
											"id": "iid",
											"value": iid
										}
									]
								}
							]
						});
						popup.ParentElement.appendChild(listview.ParentElement);
						
						popup.Show();
					}
				},
				{
					"ClassName": "MenuItemCommand",
					"Title": "Show Field EC",
					"Visible": true,
					"Execute": function()
					{
						window.open(System.ExpandRelativePath("~/" + System.TenantName + "/d/inst/1$56/" + ecid + ".htmld"));
					}
				}

			];
			cm.Show(e.clientX, e.clientY, this);
			

			e.preventDefault();
			e.stopPropagation();
			return false;
		});
	}
}

window.addEventListener("load", function()
{
	var items = document.getElementsByClassName("mcx-elementcontent");
	for (var i = 0; i < items.length; i++)
	{
		console.log("found mcx-elementcontent");
		console.log(items[i]);
		items[i].McxNativeObject = new McxElementContent(items[i]);
	}
	/*
	var items = document.getElementsByClassName("mcx-element");
	for (var i = 0; i < items.length; i++)
	{
		items[i].McxNativeObject = new McxElementContent(items[i]);
	}
	*/
});