//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.HtmlControls;

using CommunityServer.Components;
using CommunityServer.Discussions.Components;

namespace CommunityServer.Discussions.Controls
{
	/// <summary>
	/// Summary description for EmailLink.
	/// </summary>
	public class EmailLink : HtmlAnchor
	{
		protected CSContext csContext = CSContext.Current;

		protected override void CreateChildControls()
		{
			HtmlImage image = new HtmlImage();

			if (csContext.User.IsAnonymous || !csContext.SiteSettings.EnableMailGateway || csContext.SectionID <= 0)
			{
				this.Visible = false;
				return;
			}

			CommunityServer.Mail.Common.Components.MailingList ml = CommunityServer.Mail.Common.Components.MailingLists.GetMailingList(csContext.SectionID);
			if (ml == null || !ml.IsActive || !ml.IsMailingList)
			{
				this.Visible = false;
				return;
			}

			image.Src = Globals.GetSiteUrls().EmailImage;
			image.Border = 0;
			image.Alt = ResourceManager.GetString("ViewThreads_Email");
			Controls.Add(image);

			this.HRef = ForumUrls.Instance().EmailInformation(csContext.SectionID);
		}
	}
}
