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

using System;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Components;
using CommunityServer.Components;
using CommunityServer.Controls;

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

        private TextBox SearchBox = null;
        private IButton SearchButton = null;

        protected override void AttachChildControls()
        {
            SearchBox = FindControl("SearchBox") as TextBox;
            SearchButton = FindButton("SearchButton");

            if(SearchButton != null)
            {
                SearchButton.Click +=new EventHandler(SearchButton_Click);
                SearchButton.CausesValidation = false;
            }
            string q = Context.Request.QueryString["q"];
            if(!Globals.IsNullorEmpty(q))
                SearchBox.Text = q;
        }

        private void SearchButton_Click(object sender, EventArgs e)
        {
            string searchText = SearchBox.Text;
            if(!Globals.IsNullorEmpty(searchText))
            {
                //SearchQuery query = SearchQuery.SectionSearch(searchText,CurrentWeblog.SectionID);
                Context.Response.Redirect(BlogUrls.Instance().IndividualSearch(CurrentWeblog,searchText,1));
                Context.Response.End();
            }
        }
    }
}
