function MenuItemCollection(p_parent)
{
	MenuItemCollection.baseConstructor.call(this);
	this.Parent = p_parent;
	this.ItemAddedOrRemoved = null;
	return;
}
Extend(MenuItemCollection, Collection);
MenuItemCollection.prototype.GetType = function() { return 'MenuItemCollection'; }
MenuItemCollection.prototype.Add = function(p_menuItemOrText, p_icon, p_clickHandler, p_identifier)
{//alert(this.Parent.GetType());
	var v_parent_menu = TypeOf(this.Parent) == 'MenuItem' ? this.Parent.ParentMenu : this.Parent;
	var v_menu_item = TypeOf(p_menuItemOrText) == 'MenuItem' ? p_menuItemOrText : new MenuItem(p_menuItemOrText, p_icon);
	if(p_clickHandler) { v_menu_item.Click = p_clickHandler; }
	var v_index = MenuItemCollection.superClass.Add.call(this, v_menu_item);
	v_menu_item.Parent     = this.Parent;
	v_menu_item.TopLevel   = TypeOf(this.Parent) != 'MenuItem';
	v_menu_item.ParentMenu = v_menu_item.TopLevel ? this.Parent : this.Parent.ParentMenu;
	v_menu_item.ElementId  = this.Parent.ElementId + '_menuitem' + v_index.toString();
	v_menu_item.Name       = this.Parent.Name + '.Items.Item(' + v_index.toString() + ')';
	v_menu_item.Identifier = p_identifier;
	v_menu_item.Cursor     = v_parent_menu.DefaultItemCursor;
	v_menu_item.ForeColor  = v_parent_menu.DefaultItemForeColor;
	v_menu_item.TextAlign  = v_parent_menu.DefaultItemTextAlign;
	v_parent_menu.DefaultItemBorder.CopyTo(v_menu_item.Border);
	v_parent_menu.DefaultItemFont.CopyTo(v_menu_item.Font);
	v_parent_menu.DefaultItemBackground.CopyTo(v_menu_item.Background);
	v_parent_menu.DefaultItemPadding.CopyTo(v_menu_item.Padding);
	this.OnItemAddedOrRemoved();
	return v_index;
}
MenuItemCollection.prototype.RemoveAt = function(p_index) { if(MenuItemCollection.superClass.RemoveAt.call(this, p_index)) { this.OnItemAddedOrRemoved(); return true; } return false; }
MenuItemCollection.prototype.Clear = function() { MenuItemCollection.superClass.Clear.call(this); this.OnItemAddedOrRemoved(); return; }
MenuItemCollection.prototype.OnItemAddedOrRemoved = function() { if(this.ItemAddedOrRemoved) { this.ItemAddedOrRemoved(this); } return; }
/******************************************************************************/
function MenuItemIcon(p_src, p_alt, p_toolTipText)
{
	this.ElementId    = '';
	this.Name         = '';
	this.Src          = TypeOf(p_src) == 'String' ? p_src : '';
	this.Alt          = TypeOf(p_alt) == 'String' ? p_alt : '';
	this.ToolTipText  = TypeOf(p_toolTipText) == 'String' ? p_toolTipText : '';
	this.CssClassName = '';
	this.Padding      = new Padding(0);
	this.Size         = new Size(0, 0);
	return;
}
MenuItemIcon.prototype.GetType = function() { return 'MenuItemIcon'; }
MenuItemIcon.prototype.ToString = function() { return this.Alt; }
MenuItemIcon.prototype.toString = function() { return this.ToString(); }
MenuItemIcon.prototype.Refresh = function(p_altDivText)
{
	if(this.ElementId.length > 0)
	{
		var v_image = document.getElementById(this.ElementId + '_image');
		var v_div   = document.getElementById(this.ElementId + '_div');
		if(v_image != null)
		{
			v_image.src       = this.Src;
			v_image.alt       = this.Alt;
			v_image.title     = this.ToolTipText;
			v_image.className = this.CssClassName;
			v_image.width     = this.Size.Width > 0 ? this.Size.Width.toString() : '';
			v_image.height    = this.Size.Height > 0 ? this.Size.Height.toString() : '';
			v_image.style.padding  = this.Padding.ToCssString();
			v_image.style.display  = this.Src.length > 0 ? 'inline' : 'none';
			v_image.style.position = this.Src.length > 0 ? 'static' : 'absolute';
		}
		if(v_div != null)
		{
			var v_alt_text = TypeOf(p_altDivText) == 'String' ? p_altDivText : '';
			v_alt_text     = v_alt_text.length > 0 ? v_alt_text : (this.Alt.length <= 0 ? '&nbsp;' : this.Alt);
			v_div.innerHTML = v_alt_text;
			v_div.title     = this.ToolTipText;
			v_div.className = this.CssClassName;
			v_div.style.width    = this.Size.Width > 0 ? this.Size.Width.ToCssString() : '';
			v_div.style.height   = this.Size.Height > 0 ? this.Size.Height.ToCssString() : '';
			v_div.style.padding  = this.Padding.ToCssString();
			v_div.style.display  = this.Src.length > 0 ? 'none' : 'inline';
			v_div.style.position = this.Src.length > 0 ? 'absolute' : 'static';
		}
	}
	return;
}
MenuItemIcon.prototype.Render = function(p_stringBuilder, p_altDivText)
{
	var v_alt_text = TypeOf(p_altDivText) == 'String' ? p_altDivText : '';
	v_alt_text     = v_alt_text.length > 0 ? v_alt_text : (this.Alt.length <= 0 ? '&nbsp;' : this.Alt);
	p_stringBuilder.Append('<img border="0" src="').Append(this.Src).Append('" alt="').Append(this.Alt).Append('"')
		.Append(Utils.CreateAttributeString('id', this.ElementId.length > 0 ? this.ElementId + '_image' : ''))
		.Append(Utils.CreateAttributeString('title', this.ToolTipText))
		.Append(Utils.CreateAttributeString('class', this.CssClassName))
		.Append(this.Size.ToAttributeString())
		.Append(' style="')
			.Append(this.Padding.ToCssString())
			.Append(Utils.CreateCssPropertyString('position', this.Src.length > 0 ? 'static' : 'absolute'))
			.Append(Utils.CreateCssPropertyString('display', this.Src.length > 0 ? 'inline' : 'none'))
		.Append('" />')
	.Append('<div')
		.Append(Utils.CreateAttributeString('id', this.ElementId.length > 0 ? this.ElementId + '_div' : ''))
		.Append(Utils.CreateAttributeString('title', this.ToolTipText))
		.Append(Utils.CreateAttributeString('class', this.CssClassName))
		.Append(' style="')
			.Append(this.Size.ToCssString())
			.Append(this.Padding.ToCssString())
			.Append(Utils.CreateCssPropertyString('position', this.Src.length > 0 ? 'absolute' : 'static'))
			.Append(Utils.CreateCssPropertyString('display', this.Src.length > 0 ? 'none' : 'inline'))
		.Append('">').Append(v_alt_text).Append('</div>');
	return;
}
/******************************************************************************/
function MenuItem(p_text, p_icon)
{
	MenuItem.baseConstructor.call(this, 'menu_item', 'menu_item');
	this.ParentMenu = null;
	this.Items      = new MenuItemCollection(this);
	this.Text       = TypeOf(p_text) == 'String' ? p_text : '';
	this.Icon       = TypeOf(p_icon) == 'MenuItemIcon' ? p_icon : new MenuItemIcon(p_icon, '', '');
	this.Enabled    = true;
	this.TopLevel   = false;
	this.DisabledForeColor = '#666666';
	this._SubMenuVisible = false;
	this.Items.ItemAddedOrRemoved = function(p_sender) { p_sender.Parent.ParentMenu.Refresh(); return; }
	return;
}
Extend(MenuItem, SimpleControl);
MenuItem.prototype.GetType = function() { return 'MenuItem'; }
MenuItem.prototype.ToString = function() { return this.Text; }
MenuItem.prototype.DefaultSize = function() { return new Size(0, 0); }
MenuItem.prototype.DefaultPadding = function() { return new Padding(2, 2, 2, 2); }
MenuItem.prototype.DefaultBorder = function() { return new RectangleBorder(0, BorderStyle.None, '#D4D0C8'); }
MenuItem.prototype.DefaultBackground = function() { return new Background('#D4D0C8'); }
MenuItem.prototype.DefaultTextAlign = function() { return ContentAlignment.MiddleLeft; }
MenuItem.prototype.Refresh = function()
{
	if(this.IsRendered)
	{
		var v_row = Utils.GetElement(this.ElementId);
		v_row.style.background = this.Background.ToCssString();
		v_row.style.height     = this.Size.Height > 0 ? this.Size.Height.ToCssString() : '';
		v_row.style.font       = this.Font.ToCssString();
		v_row.style.color      = this.Enabled ? this.ForeColor : this.DisabledForeColor;
		v_row.style.cursor     = this.Cursor;
		if(this.Text == '-')
		{
			Utils.GetElement(this.ElementId + '_spacer_td').style.padding = this.Padding.ToCssString();
			var v_height = Utils.IsIE ? this.ParentMenu.SpacerStyle.Width.ToCssString() : '1px';
			var v_spacer = Utils.GetElement(this.ElementId + '_spacer');
			v_spacer.style.height    = v_height;
			v_spacer.style.borderTop = this.ParentMenu.SpacerStyle.ToCssString();
		}
		else
		{
			var v_icon_td = Utils.GetElement(this.ElementId + '_icon_td');
			v_icon_td.style.borderTop     = this.Border.Top.ToCssString();
			v_icon_td.style.borderBottom  = this.Border.Bottom.ToCssString();
			v_icon_td.style.borderLeft    = this.Border.Left.ToCssString();
			v_icon_td.style.paddingTop    = this.Padding.Top.ToCssString();
			v_icon_td.style.paddingBottom = this.Padding.Bottom.ToCssString();
			v_icon_td.style.paddingLeft   = this.Padding.Left.ToCssString();
			var v_text_td = Utils.GetElement(this.ElementId + '_text_td');
			ContentAlignment.SetCssDomProperties(v_text_td, this.TextAlign);
			v_text_td.style.borderTop     = this.Border.Top.ToCssString();
			v_text_td.style.borderBottom  = this.Border.Bottom.ToCssString();
			v_text_td.style.paddingTop    = this.Padding.Top.ToCssString();
			v_text_td.style.paddingBottom = this.Padding.Bottom.ToCssString();
			var v_arrow_td   = Utils.GetElement(this.ElementId + '_arrow_td');
			v_arrow_td.style.borderTop     = this.Border.Top.ToCssString();
			v_arrow_td.style.borderBottom  = this.Border.Bottom.ToCssString();
			v_arrow_td.style.paddingTop    = this.Padding.Top.ToCssString();
			v_arrow_td.style.paddingBottom = this.Padding.Bottom.ToCssString();
			var v_submenu_td = Utils.GetElement(this.ElementId + '_submenu_td');
			v_submenu_td.style.borderTop     = this.Border.Top.ToCssString();
			v_submenu_td.style.borderBottom  = this.Border.Bottom.ToCssString();
			v_submenu_td.style.borderRight   = this.Border.Right.ToCssString();
			v_submenu_td.style.paddingTop    = this.Padding.Top.ToCssString();
			v_submenu_td.style.paddingBottom = this.Padding.Bottom.ToCssString();
			v_submenu_td.style.paddingRight  = this.Padding.Right.ToCssString();
		}
		this.ParentMenu.RefreshArrowIcon(this.ElementId + '_arrow_icon', this.Items.Count > 0 ? '' : '&nbsp;');
		this.Icon.Refresh();
		if(this.Items.Count > 0)
		{
			this.ParentMenu.RefreshMenuTable(this.ElementId + '_submenu');
			for(var i = 0; i < this.Items.Count; i++) { this.Items.Item(i).Refresh(); }
		}
	}
	return;
}
MenuItem.prototype.Render = function(p_stringBuilder)
{
	this.ParentMenu.ArrowIcon.ElementId = this.ElementId + '_arrow_icon';
	this.Icon.ElementId = this.ElementId + '_icon';
	this.Icon.Name      = this.Name + '.Icon';
	p_stringBuilder.Append('<tr id="').Append(this.ElementId).Append('" style="')
		.Append(Utils.CreateCssPropertyString('background', this.Background.ToCssString()))
		.Append(Utils.CreateCssPropertyString('height', this.Size.Height > 0 ? this.Size.Height.ToCssString() : ''))
		.Append(Utils.CreateCssPropertyString('font', this.Font.ToCssString()))
		.Append(Utils.CreateCssPropertyString('color', this.Enabled ? this.ForeColor : this.DisabledForeColor))
		.Append(Utils.CreateCssPropertyString('cursor', this.Cursor))
		.Append('"');
	this.GetEventAttributeString(p_stringBuilder);
	p_stringBuilder.Append('>');
	if(this.Text == '-')
	{
		var v_height = Utils.IsIE ? this.ParentMenu.SpacerStyle.Width.ToCssString() : '1px';
		p_stringBuilder.Append('<td colspan="4" id="').Append(this.ElementId).Append('_spacer_td" style="vertical-align: middle;')
				.Append(Utils.CreateCssPropertyString('padding', this.Padding.ToCssString()))
				.Append(this.Border.ToCssString())
			.Append('"><div id="').Append(this.ElementId).Append('_spacer" style="height: ').Append(v_height)
			.Append('; overflow: hidden; border-top: ').Append(this.ParentMenu.SpacerStyle.ToCssString()).Append(';">&nbsp;</div></td>');
	}
	else
	{
		p_stringBuilder.Append('<td id="').Append(this.ElementId).Append('_icon_td" style="padding-right: 3px;')
				.Append(Utils.CreateCssPropertyString('border-top', this.Border.Top.ToCssString()))
				.Append(Utils.CreateCssPropertyString('border-bottom', this.Border.Bottom.ToCssString()))
				.Append(Utils.CreateCssPropertyString('border-left', this.Border.Left.ToCssString()))
				.Append(Utils.CreateCssPropertyString('padding-top', this.Padding.Top.ToCssString()))
				.Append(Utils.CreateCssPropertyString('padding-bottom', this.Padding.Bottom.ToCssString()))
				.Append(Utils.CreateCssPropertyString('padding-left', this.Padding.Left.ToCssString()))
			.Append('">');
		this.Icon.Render(p_stringBuilder);
		p_stringBuilder.Append('</td>')
			.Append('<td id="').Append(this.ElementId).Append('_text_td"')
			.Append(Utils.CreateAttributeString('onclick', this.Name + '.OnClick(event,this);'))
			.Append(' style="white-space: nowrap;')
				.Append(ContentAlignment.CreateCssString(this.TextAlign))
				.Append(Utils.CreateCssPropertyString('border-top', this.Border.Top.ToCssString()))
				.Append(Utils.CreateCssPropertyString('border-bottom', this.Border.Bottom.ToCssString()))
				.Append(Utils.CreateCssPropertyString('padding-top', this.Padding.Top.ToCssString()))
				.Append(Utils.CreateCssPropertyString('padding-bottom', this.Padding.Bottom.ToCssString()))
			.Append('">').Append(this.Text).Append('</td>')
			.Append('<td id="').Append(this.ElementId).Append('_arrow_td" style="padding-left: 3px;')
				.Append(Utils.CreateCssPropertyString('border-top', this.Border.Top.ToCssString()))
				.Append(Utils.CreateCssPropertyString('border-bottom', this.Border.Bottom.ToCssString()))
				.Append(Utils.CreateCssPropertyString('padding-top', this.Padding.Top.ToCssString()))
				.Append(Utils.CreateCssPropertyString('padding-bottom', this.Padding.Bottom.ToCssString()))
			.Append('">');
		this.ParentMenu.ArrowIcon.Render(p_stringBuilder, this.Items.Count > 0 ? '' : '&nbsp;');
		p_stringBuilder.Append('</td>')
			.Append('<td id="').Append(this.ElementId).Append('_submenu_td" style="width: 5px; vertical-align: top;')
				.Append(Utils.CreateCssPropertyString('border-top', this.Border.Top.ToCssString()))
				.Append(Utils.CreateCssPropertyString('border-bottom', this.Border.Bottom.ToCssString()))
				.Append(Utils.CreateCssPropertyString('border-right', this.Border.Right.ToCssString()))
				.Append(Utils.CreateCssPropertyString('padding-top', this.Padding.Top.ToCssString()))
				.Append(Utils.CreateCssPropertyString('padding-bottom', this.Padding.Bottom.ToCssString()))
				.Append(Utils.CreateCssPropertyString('padding-right', this.Padding.Right.ToCssString()))
			.Append('"><div style="width: 1px; height: 1px; overflow: hidden; position: absolute;">&nbsp;</div>');
		if(this.Items.Count > 0)
		{
			this.ParentMenu.RenderMenuTableBeginning(p_stringBuilder, this.ElementId + '_submenu', false, true, 0, false);
			for(var i = 0; i < this.Items.Count; i++) { this.Items.Item(i).Render(p_stringBuilder); }
			this.ParentMenu.RenderMenuTableEnd(p_stringBuilder);
		}
		p_stringBuilder.Append('</td>');
	}
	p_stringBuilder.Append('</tr>');
	this.IsRendered = true;
	return;
}
MenuItem.prototype.RenderHorizontal = function(p_stringBuilder, p_isBottomStyleMenu, p_usePercentWidths)
{
	this.ParentMenu.ArrowIcon.ElementId = this.ElementId + '_arrow_icon';
	this.Icon.ElementId = this.ElementId + '_icon';
	this.Icon.Name      = this.Name + '.Icon';
	p_stringBuilder.Append('<td id="').Append(this.ElementId).Append('" style="')
		.Append(ContentAlignment.CreateCssString(this.TextAlign))
		.Append(Utils.CreateCssPropertyString('background', this.Background.ToCssString()))
		.Append(Utils.CreateCssPropertyString('height', this.Size.Height > 0 ? this.Size.Height.ToCssString() : ''))
		.Append(Utils.CreateCssPropertyString('width', this.Size.Width > 0 ? (p_usePercentWidths ? this.Size.Width.toString() + '%' : this.Size.Width.ToCssString()) : ''))
		.Append(Utils.CreateCssPropertyString('font', this.Font.ToCssString()))
		.Append(Utils.CreateCssPropertyString('color', this.Enabled ? this.ForeColor : this.DisabledForeColor))
		.Append(Utils.CreateCssPropertyString('cursor', this.Cursor))
		.Append(Utils.CreateCssPropertyString('padding', this.Padding.ToCssString()))
		.Append(this.Border.ToCssString())
		.Append('"');
	this.GetEventAttributeString(p_stringBuilder);
	p_stringBuilder.Append('>');
	if(this.Text == '-') { p_stringBuilder.Append('&nbsp;'); }
	else
	{
		p_stringBuilder.Append('<div id="').Append(this.ElementId).Append('_icon_td" style="display: inline;">')
		this.Icon.Render(p_stringBuilder);
		p_stringBuilder.Append('</div><div id="').Append(this.ElementId).Append('_text_td" style="display: inline;">')
			.Append(this.Text).Append('</div><div id="').Append(this.ElementId).Append('_submenu_td" style="height: 1px; overflow: hidden; text-align: left;">');
		if(this.Items.Count > 0)
		{
			this.ParentMenu.RenderMenuTableBeginning(p_stringBuilder, this.ElementId + '_submenu', false, true, 0, false);
			for(var i = 0; i < this.Items.Count; i++) { this.Items.Item(i).Render(p_stringBuilder); }
			this.ParentMenu.RenderMenuTableEnd(p_stringBuilder);
		}
		else { p_stringBuilder.Append('&nbsp;'); }
		p_stringBuilder.Append('</div>');
	}
	p_stringBuilder.Append('</td>');
	this.IsRendered = true;
	return;
}
MenuItem.prototype.ShowSubMenu = function() { if(this.Enabled && !this._SubMenuVisible && this.Items.Count > 0) { var v_item = Utils.GetElement(this.ElementId + '_submenu'); v_item.style.display = 'block'; v_item.zIndex = 9999; this._SubMenuVisible = true; } return; }
MenuItem.prototype.HideSubMenu = function() { if(this._SubMenuVisible && this.Items.Count > 0) { Utils.GetElement(this.ElementId + '_submenu').style.display = 'none'; this._SubMenuVisible = false; } return; }
MenuItem.prototype.HideAll = function()
{
	for(var i = 0; i < this.Items.Count; i++) { this.Items.Item(i).HideAll(); }
	this.HideSubMenu();
	return;
}
MenuItem.prototype.OnClick = function(e, p_element)
{
	if(this.Enabled && this.Text != '-' && this.Items.Count <= 0) { MenuItem.superClass.OnClick.call(this, e, p_element); this.ParentMenu.Hide(); }
	return;
}
MenuItem.prototype.OnMouseOver = function(e, p_element)
{
	if(this.Text != '-')
	{
		var v_element = Utils.GetElement(this.ElementId);
		v_element.style.background = this.ParentMenu.MenuItemMouseOverBackground.ToCssString();
		if(this.Enabled) { v_element.style.color = this.ParentMenu.MenuItemMouseOverForeColor; }
		this.ShowSubMenu();
	}
	MenuItem.superClass.OnMouseOver.call(this, e, p_element);
	return;
}
MenuItem.prototype.OnMouseOut = function(e, p_element)
{
	if(this.Text != '-')
	{
		var v_element = Utils.GetElement(this.ElementId);
		v_element.style.background = this.Background.ToCssString();
		if(this.Enabled) { v_element.style.color = this.ForeColor; }
		this.HideSubMenu();
	}
	MenuItem.superClass.OnMouseOut.call(this, e, p_element);
	return;
}
/******************************************************************************/
function MenuBase(p_elementId, p_instanceName)
{
	MenuBase.baseConstructor.call(this, p_elementId, p_instanceName);
	this.Items         = new MenuItemCollection(this);
	this.SpacerStyle   = new Border(2, BorderStyle.Groove, '#FFFFFF');
	this.ArrowIcon     = new MenuItemIcon('', '&#187;', '');
	this.SubMenuBorder = this.DefaultSubMenuBorder();
	this.MenuItemMouseOverBackground = new Background('#0A246A');
	this.MenuItemMouseOverForeColor  = '#FFFFFF';

	// Default menu item styling.
	this.DefaultItemCursor     = this.DefaultCursor();
	this.DefaultItemForeColor  = this.DefaultForeColor();
	this.DefaultItemTextAlign  = this.DefaultTextAlign();
	this.DefaultItemBorder     = this.DefaultBorder();
	this.DefaultItemFont       = this.DefaultFont();
	this.DefaultItemBackground = this.DefaultBackground();
	this.DefaultItemPadding    = new Padding(0, 0, 0, 0);

	this.Items.ItemAddedOrRemoved = function(p_sender) { p_sender.Parent.Refresh(); return; }
	return;
}
Extend(MenuBase, Control);
MenuBase.prototype.GetType = function() { return 'MenuBase'; }
MenuBase.prototype.DefaultSize = function() { return new Size(0, 0); }
MenuBase.prototype.DefaultBackground = function() { return new Background('#D4D0C8'); }
MenuBase.prototype.DefaultSubMenuBorder = function() { return new RectangleBorder(2, BorderStyle.Outset, '#D4D0C8'); }
MenuBase.prototype.Show = function() { return; }
MenuBase.prototype.Hide = function() { return; }
MenuBase.prototype.Refresh = function() { return; }
MenuBase.prototype.Render = function() { return; }
MenuBase.prototype.RenderMenuTableBeginning = function(p_stringBuilder, p_elementId, p_visible, p_isStandAloneMenu, p_width, p_usePercentWidth)
{
	p_stringBuilder.Append('<table cellpadding="0" cellspacing="0" border="0"')
		.Append(Utils.CreateAttributeString('id', p_elementId))
		.Append(Utils.CreateAttributeString('class', this.CssClassName))
		.Append(' style="z-index: 9999;');
	if(p_isStandAloneMenu) { p_stringBuilder.Append('position: absolute;'); }
	if(p_width > 0) { p_stringBuilder.Append('width:').Append(p_usePercentWidth ? p_width.toString() + '%' : p_width.ToCssString()).Append(';'); }
		p_stringBuilder.Append(Utils.CreateCssPropertyString('display', p_visible ? (p_isStandAloneMenu ? 'block' : '') : 'none'))
			.Append(Utils.CreateCssPropertyString('background', this.Background.ToCssString()))
			.Append(Utils.CreateCssPropertyString('padding', this.Padding.ToCssString()))
			.Append(Utils.CreateCssPropertyString('font', this.Font.ToCssString()))
			.Append(Utils.CreateCssPropertyString('color', this.ForeColor))
			.Append(Utils.CreateCssPropertyString('cursor', this.Cursor));
	if(p_isStandAloneMenu) { p_stringBuilder.Append(this.SubMenuBorder.ToCssString()) }
	else { p_stringBuilder.Append(this.Border.ToCssString()); }
	p_stringBuilder.Append('">');
	return;
}
MenuBase.prototype.RenderMenuTableEnd = function(p_stringBuilder) { p_stringBuilder.Append('</table>'); return; }
MenuBase.prototype.RefreshMenuTable = function(p_elementId) { this.RefreshMenuTableCore(Utils.GetElement(p_elementId)); return; }
MenuBase.prototype.RefreshMenuTableCore = function(p_element)
{
	p_element.className = this.CssClassName;
	p_element.style.background = this.Background.ToCssString();
	p_element.style.padding    = this.Padding.ToCssString();
	p_element.style.font       = this.Font.ToCssString();
	p_element.style.color      = this.ForeColor;
	p_element.style.cursor     = this.Cursor;
	p_element.zIndex           = 9999;
	this.Border.SetCssDomProperties(p_element);
	return;
}
MenuBase.prototype.RefreshArrowIcon = function(p_elementId, p_altDivText) { this.ArrowIcon.ElementId = p_elementId; this.ArrowIcon.Refresh(p_altDivText); return; }
/******************************************************************************/
function ContextMenu(p_instanceName)
{
	ContextMenu.baseConstructor.call(this, 'contextmenu_' + p_instanceName, p_instanceName);
	this.Visible = false;
	return;
}
ContextMenu._ActiveMenu = null;
ContextMenu.ShowMenu = function(p_menu, p_pointOrX, p_y)
{
	if(ContextMenu._ActiveMenu != null) { ContextMenu._ActiveMenu.Hide(); }
	var v_point = TypeOf(p_pointOrX) == 'Point' ? p_pointOrX : new Point(p_pointOrX, p_y);
	var v_element = Utils.GetElement(p_menu.ElementId);
	v_element.style.top      = v_point.Y.ToCssString();
	v_element.style.left     = v_point.X.ToCssString();
	v_element.style.position = 'absolute';
	v_element.style.display  = 'block';
	v_element.zIndex         = 9999;
	p_menu.SetVisibleCore(true);
	ContextMenu._ActiveMenu = p_menu;
	return;
}
ContextMenu.HideMenu = function(p_menu)
{
	if(p_menu.Visible)
	{
		var v_element = Utils.GetElement(p_menu.ElementId);
		v_element.style.top      = '0px';
		v_element.style.left     = '0px';
		v_element.style.position = 'absolute';
		v_element.style.display  = 'none';
		p_menu.SetVisibleCore(false);
	}
	ContextMenu._ActiveMenu = null;
	return;
}
Extend(ContextMenu, MenuBase);
ContextMenu.prototype.GetType = function() { return 'ContextMenu'; }
ContextMenu.prototype.DefaultBorder = function() { return new RectangleBorder(2, BorderStyle.Outset, '#D4D0C8'); }
ContextMenu.prototype.Show = function() { ContextMenu.ShowMenu(this, this.Location); return; }
ContextMenu.prototype.ShowAt = function(p_pointOrX, p_y) { ContextMenu.ShowMenu(this, p_pointOrX, p_y); return; }
ContextMenu.prototype.Hide = function() { ContextMenu.HideMenu(this); return; }
ContextMenu.prototype.Refresh = function()
{
	return;
}
ContextMenu.prototype.Render = function()
{
	var v_table = document.getElementById(this.ElementId);
	if(v_table == null)
	{
		var v_sb = new StringBuilder();
		for(var i = 0; i < this.Items.Count; i++) { this.Items.Item(i).Render(v_sb); }
		var v_tbody = document.createElement('tbody');
		v_table = document.createElement('table');
		v_table.setAttribute('id', this.ElementId);
		v_table.setAttribute('cellpadding', '0');
		v_table.setAttribute('cellspacing', '0');
		v_table.setAttribute('border', '0');
		v_table.appendChild(v_tbody);
		document.body.appendChild(v_table);
		v_table.style.top      = '0px';
		v_table.style.left     = '0px';
		v_table.style.position = 'absolute';
		v_table.style.display  = 'none';
		this.RefreshMenuTableCore(v_table);
		v_tbody.innerHTML = v_sb.ToString(); // TODO: figure out how to do this in IE, since IE doesn't seem to like setting the innerHTML property of a tbody element.
	}
	else { throw Exception('Could not render the ContextMenu because there is an existing ContextMenu with the same instance name.'); }
	this.IsRendered = true;
	return;
}
/******************************************************************************/
MainMenuDirection = {};
MainMenuDirection.HorizontalTop    = 0;
MainMenuDirection.HorizontalBottom = 1; // Not currently supported.
MainMenuDirection.VerticalLeft     = 2;
MainMenuDirection.VerticalRight    = 3; // Not currently supported.
function MainMenu(p_elementId, p_instanceName)
{
	MainMenu.baseConstructor.call(this, p_elementId, p_instanceName);
	this.UsePercentWidths = true;
	this.Direction = MainMenuDirection.HorizontalTop;
	return;
}
Extend(MainMenu, MenuBase);
MainMenu.prototype.GetType = function() { return 'MainMenu'; }
MainMenu.prototype.DefaultSize = function() { return new Size(100, 0); }
MainMenu.prototype.DefaultBorder = function() { return new RectangleBorder(0, BorderStyle.None, '#D4D0C8'); }
MainMenu.prototype.Show = function() { return; }
MainMenu.prototype.ShowAt = function(p_pointOrX, p_y) { return; }
MainMenu.prototype.Hide = function() { for(var i = 0; i < this.Items.Count; i++) { this.Items.Item(i).HideAll(); } return; }
MainMenu.prototype.Render = function()
{
	var v_sb = new StringBuilder();
	this.RenderMenuTableBeginning(v_sb, this.ElementId + '_mainmenu_table', true, false, this.Size.Width, this.UsePercentWidths);
	switch(this.Direction)
	{
		case MainMenuDirection.HorizontalTop:
			for(var i = 0; i < this.Items.Count; i++) { this.Items.Item(i).RenderHorizontal(v_sb, false, this.UsePercentWidths); }
			break;
		case MainMenuDirection.HorizontalBottom:
			throw Exception('MainMenuDirection.HorizontalBottom not currently implemented/supported.');
			break;
		case MainMenuDirection.VerticalLeft:
			for(var i = 0; i < this.Items.Count; i++) { this.Items.Item(i).Render(v_sb); }
			break;
		case MainMenuDirection.VerticalRight:
			throw Exception('MainMenuDirection.VerticalRight not currently implemented/supported.');
			break;
		default: throw Exception('Invalid MainMenuDirection value specified.'); break;
	}
	this.RenderMenuTableEnd(v_sb);
	Utils.GetElement(this.ElementId).innerHTML = v_sb.ToString();
	this.IsRendered = true;
	return;
}