﻿(function ($) {

    function OnFocusClear() {
        $(".OnFocusClear").focus(function () {
            if ($(this).attr("title") == $(this).val()) {
                OnFocusValue = $(this).val();
                $(this).val('');
            }
        }).blur(function () {
            if ($(this).val() == '') {
                $(this).val(OnFocusValue);
            }
            OnFocusValue = '';
        });
    }

    var OnFocusValue = '';
    var MonthActivities;
    var CurrentMonth = 0;

    $(document).ready(function () {
        OnFocusClear();
        var today = new Date();
        var mm = today.getMonth() + 1;
        CurrentMonth = mm - 1;

        $.ajax({
            type: "POST",
            cache: true,
            url: "/modules/Evenement/Calendar/Client/GetEvents.aspx",
            data: ({ Year: 0, Month: mm }),
            dataType: "json",
            async: false,
            success: function (data) { MonthActivities = data; }
        });

        $("#datepicker").datepicker({
            firstDay: 0,
            dateFormat: "yy-mm-dd",
            onSelect: function (dateText, inst) {
                document.location.href = "/calendrier/" + dateText;
                //  alert(dateText);
                return false;
            },
            onChangeMonthYear: function (year, month, inst) {
                MonthActivities = "";
                CurrentMonth = month - 1;
                $.ajax({
                    type: "POST",
                    cache: true,
                    url: "/modules/Evenement/Calendar/Client/GetEvents.aspx",
                    data: ({ Year: year, Month: month }),
                    dataType: "json",
                    async: false,
                    success: function (data) { MonthActivities = data; }
                });
            },
            beforeShowDay: function (date) {
                if (CurrentMonth == date.getMonth() && MonthActivities != undefined && MonthActivities.items != undefined) {
                    return new Array((MonthActivities.items[date.getDate() - 1].IsSelectable == "True"), MonthActivities.items[date.getDate() - 1].CssClass, MonthActivities.items[date.getDate() - 1].Activites);
                } else {
                    return new Array(false, "", "");
                }
            }
        });

        $("table.ui-datepicker-calendar tbody *[title]").monnaTip();


        $(".boxNew").bind("click", function () {

            var Id = $(this).attr("Id");

            $(".boxNew").each(function () {
                $(this).removeClass("selected");
            });

            $(this).addClass("selected");

            $("#ResumeNew div").each(function () {
                $(this).hide();
            });

            $("#Resume" + Id).show();

        });


    });


})(jQuery);


