<%@ Page Language="C#" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Page</title>

    <script type="text/javascript">
        function RadCalendar1_DateClick(sender, args) {
            var shouldResetMultiSelect = false;
            if (!sender.get_enableMultiSelect()) {
                sender.set_enableMultiSelect(true);
                shouldResetMultiSelect = true;
            }
            
            var selectedDates = sender.get_selectedDates();
            if (selectedDates.length == 1) {
                var datesToSelect = new Array();
                var startDate = selectedDates[0];
                var endDate = args.get_renderDay().get_date();

                if (startDate[0] == endDate[0] && startDate[1] == endDate[1]) {

                    if (startDate[2] < endDate[2]) {
                        for (var i = 0; i < endDate[2] - startDate[2]; i++) {
                            var newDate = new Array(startDate[0], startDate[1], startDate[2] + i);
                            Array.add(datesToSelect, newDate);
                        }

                        sender.selectDates(datesToSelect);
                    }
                    else {
                        var i = startDate[2];
                        var j = 1;
                        while (i != endDate[2] + 1) {
                            var newDate = new Array(startDate[0], startDate[1], startDate[2] - j);
                            Array.add(datesToSelect, newDate);
                            i--;
                            j++;
                        }

                        sender.selectDates(datesToSelect);
                    }
                }
            }
            else {
                sender.unselectDates(selectedDates);
            }

            if (shouldResetMultiSelect) {
                sender.set_enableMultiSelect(false);
            }
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <telerik:RadCalendar ID="RadCalendar1" EnableMultiSelect="true" runat="server">
            <ClientEvents OnDateClick="RadCalendar1_DateClick" />
        </telerik:RadCalendar>
    </div>
    </form>
</body>
</html>
