﻿var natDays = [];

(function($) {

    $(document).ready(function() {

        String.prototype.endsWith = function(str) {
            return (this.match(str + '$') == str)
        }

        jQuery.expr[":"].asp = function(a, i, m) {
            return (id = jQuery(a).attr('id')) && id.endsWith(m[3]);
        };

        function disableAllDays(date) {

            for (i = 0; i < natDays.length; i++) {
                if (date.getMonth() == natDays[i][0] - 1 && date.getDate() == natDays[i][1]) {
                    $('.withevent').bind('click', function() { alert($(this).html()) });
                    return [true, natDays[i][2] + '_day' + ' withevent', natDays[i][2]];
                }
            }
            return [false, ''];
        }

        /* INIT CALENDAR */
        $('#calendar').datepicker({ beforeShowDay: disableAllDays, onSelect: function(dateText, inst) {
            $(":asp('eventsFromDate')").val(dateText);
            $(":asp('eventsToDate')").val(dateText);            
            __doPostBack($(":asp('eventsUP')").attr("id"), "");            
        }
        });

        $('#calendar').datepicker('option', 'monthNames', ['Ianuarie', 'Februarie', 'Martie', 'Aprilie', 'Mai', 'Iunie', 'Iulie', 'August', 'Septembrie', 'Octombrie', 'Noiembrie', 'Decembrie']);
        $('#calendar').datepicker('option', 'dayNamesMin', ['D', 'L', 'M', 'M', 'J', 'V', 'S']);
        $('#calendar').datepicker('option', 'minDate', new Date(2009, 1 - 1, 1));
        $('#calendar').datepicker('option', 'maxDate', '+1m');
        $('#calendar').datepicker('option', 'hideIfNoPrevNext', true);
        $('#calendar').datepicker('option', 'prevText', '');
        $('#calendar').datepicker('option', 'nextText', '');
        $('#calendar').datepicker('option', 'firstDay', 1);
        $('#calendar').datepicker('option', 'dateFormat', 'yy.mm.dd');     

    });
})(jQuery);