using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Text;
using Telerik.WebControls;
using Telerik.WebControls.RadCalendarHeaders;


namespace CalendarEvents
{
    public partial class _Default : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RadCalendar1.DefaultCellPadding = 5;
                RadCalendar1.DefaultCellSpacing = 5;
                RadCalendar1.AutoPostBack = true;
            }
        }

        private string[] _oldNorseDays = new string[7] { 
    "Sunnudagr", 
    "Mánadagr", 
    "Tısdagr", 
    "Óğinsdagr", 
    "Şórsdagr", 
    "Frjádagr", 
    "Laugardagr" 
};

        private int _columnIndex = 0;

        protected void RadCalendar1_HeaderCellRender(object sender,
            Telerik.WebControls.Base.Calendar.Events.HeaderCellRenderEventArgs e)
        {
            if (e.HeaderType == HeaderType.Column)
            {
                e.Cell.Text = _oldNorseDays[_columnIndex];
                e.Cell.BackColor = System.Drawing.Color.WhiteSmoke;
                e.Cell.ForeColor = System.Drawing.Color.Blue;

                _columnIndex += 1;
            }
        }

        protected void RadCalendar1_DayRender(object sender,
            Telerik.WebControls.Base.Calendar.Events.DayRenderEventArgs e)
        {
            bool isInMonth = e.Day.Date.Month == RadCalendar1.FocusedDate.Month;

            if (e.Day.IsSelected & isInMonth)
            {
                Image checkImage = new Image();
                checkImage.ImageUrl = "~/Check.gif";
                e.Cell.Text = "stuff";
                e.Cell.Controls.Add(checkImage);
                e.Cell.Controls.Add(new LiteralControl(e.Day.Date.Day.ToString()));
            }
            else
            {
                e.Cell.Text = e.Day.Date.Day.ToString();
            }
        }

        protected void RadCalendar1_SelectionChanged(object sender,
            Telerik.WebControls.Base.Calendar.Events.SelectedDatesEventArgs e)
        {
            e.SelectedDates.SelectRange(DateTime.Now, DateTime.Now.AddDays(5));

            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("SelectedDate is: " +
                (sender as RadCalendar).SelectedDate + "\n");

            stringBuilder.Append("SelectedDates are: \n");
            foreach (RadDate selectedDate in e.SelectedDates)
            {
                stringBuilder.Append(selectedDate.Date.ToString() + "\n");
            }

            TextBox1.Text += stringBuilder.ToString();
        }

        protected void RadCalendar1_DefaultViewChanged(object sender,
            Telerik.WebControls.Base.Calendar.Events.DefaultViewChangedEventArgs e)
        {
            const string message = "Start: {0}  End: {1}\n";
            TextBox1.Text += string.Format(message, e.NewView.ViewStartDate,
                e.NewView.ViewEndDate);
        }

    }
}
