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

using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommunityServer.Components;

namespace CommunityServer.Controls
{
	/// <summary>
	/// Summary description for AnonymousUserControl.
	/// </summary>
	public class AnonymousUserControl : TemplatedWebControl
	{
		public AnonymousUserControl()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		Literal message = null;

		/// <summary>
		/// No Being Span
		/// </summary>
		/// <param name="writer"></param>
		public override void RenderBeginTag(HtmlTextWriter writer)
		{
			//we don't need a span tag
		}

		/// <summary>
		/// No End Span
		/// </summary>
		/// <param name="writer"></param>
		public override void RenderEndTag(HtmlTextWriter writer)
		{
			//we don't need a span tag
		}


		protected override void AttachChildControls()
		{
			CSContext cntx = CSContext.Current;
			message = FindControl("Message")	 as Literal;
			if(message != null)
				message.Text = string.Format(ResourceManager.GetString("DisplayUserWelcome_AlternateUserWelcome"), cntx.SiteSettings.SiteName);

			switch(cntx.AuthenticationType)
			{

				case "passport":

					PlaceHolder passport = FindControl("PassportPanel") as PlaceHolder;
					if(passport != null)
						passport.Visible = true;					

					Literal lit = FindControl("PassportButton") as Literal;
					if(lit != null)
						lit.Text = (new PassportIdentity()).LogoTag() ;

					break;

				case "windows":

					PlaceHolder windows = FindControl("WindowsPanel") as PlaceHolder;
					if(windows != null)
						windows.Visible = true;					


					break;

				case "forms":
				default:

					PlaceHolder formspanel = FindControl("FormsPanel") as PlaceHolder;
					if(formspanel != null)
						formspanel.Visible = true;
					
					HyperLink login = FindControl("login") as HyperLink;

					if(login != null)
					{
						login.Text = ResourceManager.GetString("login");
						login.NavigateUrl = Globals.GetSiteUrls().Login;
					}
			
					HyperLink register = FindControl("Register") as HyperLink;
					if(register != null)
					{
						if (cntx.SiteSettings.AccountActivation != AccountActivation.InvitationOnly)
						{
							register.Text = ResourceManager.GetString("Utility_ForumAnchorType_MenuRegister");
							register.NavigateUrl = Globals.GetSiteUrls().UserRegister;
						}
						else
						{
							register.Visible = false;

							Control registerArea = FindControl("RegisterArea");
							if (registerArea != null)
								registerArea.Visible = false;
						}
					}

					break;


			}

		}
	}
}
