/// ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
/// ' Microsoft Content Management Server - Sample Code 
/// '
/// ' This sample code is provided "AS IS" with no warranties, and confers no rights. 
/// ' You assume all risk for your use.  2001 Microsoft Corporation. All rights reserved.
/// '
/// ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

namespace WoodgroveNet
{
	using System;
	using System.Web;
	//Add reference for localization
	using System.EnterpriseServices;
	using System.Globalization;
	using System.Resources;
	using System.Threading;
	//Add reference to the CMS API
	using Microsoft.ContentManagement.Publishing;
	using Microsoft.ContentManagement.Web.Caching;
	using Microsoft.ContentManagement.Web.Security;
	//Add reference to the Mcms control library
	using McmsWebControlLibrary;

	/// <summary>
	///		Summary description for Header.
	///	</summary>
	public abstract class Header : System.Web.UI.UserControl
	{
		protected McmsWebControlLibrary.McmsGlobalNavigationControl McmsGlobalNavigationControl1;
		protected McmsWebControlLibrary.McmsDhtmlGlobalNavigationControl McmsDhtmlGlobalNavigationControl1;
		protected System.Web.UI.WebControls.Literal LTHeaderLoginLogOff;
		protected System.Web.UI.WebControls.LinkButton HeaderLoginLogoff;
				
		//Resource Manager for localization
		protected ResourceManager LocalizationResourceManager;
						
		private void Page_Load(object sender, System.EventArgs e)
		{
			//CHANGES MADE FOR POSTBACK
			CmsHttpContext PostBackCmsContext = CmsHttpContext.Current;
			HeaderLoginLogoff.Visible = true;				
			if(PostBackCmsContext.IsLoggedInAsGuest)
			{
				HeaderLoginLogoff.Text = LocalizationResourceManager.GetString("HeaderLogin");				
			}		
			else
			{
				HeaderLoginLogoff.Text = LocalizationResourceManager.GetString("HeaderLogout");				
			}	
		}

		//Function called on Link Button Click
		private void HeaderLoginLogoff_Click(object sender, System.EventArgs e)
		{
			CmsHttpContext PostBackCmsContext = CmsHttpContext.Current;

			//If the User is not logged in as guest
			if(!PostBackCmsContext.IsLoggedInAsGuest)
			{
				//Sign Out the User and redirect to the same page
				CmsFormsAuthentication.SignOut();
				Response.Redirect(Request.Url.AbsoluteUri);
			}
			else
			{
				//Redirect to the Manual Login Page picking
				//the Url from We.config file
				Response.StatusCode=401;
				Response.End();
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
			LocalizationResourceManager = (ResourceManager) Application["WoodgroveNetResourceManager"];
		}
		
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.HeaderLoginLogoff.Click += new System.EventHandler(this.HeaderLoginLogoff_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}
