function bcCustomRange(input) 
{ 
} 



$(document).ready(function () {

    $('.bc-recurtype').change(function (){
    
        var block = $(this).parent().parent();
    
        var type = $(this).val();
        
        $('.bc-recurblock', block).hide();
        $('.bc-element-range', block).hide();
        
        switch(type)
        {
            case 'ONCE':
                $('.bc-block-single', block).show();
            break;
            case 'WEEK':
                $('.bc-block-weekly', block).show();
                $('.bc-element-range', block).show();
                $('.bc-repeat-type', block).html(' week(s)');
            break;
            case 'MONTH':
                $('.bc-block-monthly', block).show();
                $('.bc-element-range', block).show();
                $('.bc-repeat-type', block).html(' month(s)');
            break;
            case 'YEAR':
                $('.bc-block-yearly', block).show();
                $('.bc-element-range', block).show();
                $('.bc-repeat-type', block).html(' year(s)');
                
            break;
        
        }
    
    });
    
    $('.bc-rangeendtype-date').click(function (){
    
        var block = $(this).parents('.bc-event-block')[0];
        
        $('.bc-rangeend-date',block).attr('disabled','');
    });

    $('.bc-rangeendtype-null').click(function (){
    
        var block = $(this).parents('.bc-event-block')[0];
        
        $('.bc-rangeend-date',block).attr('disabled','disabled');
    });

    $('.bc-rangeend-date').click(function (){
        var block = $(this).parents('.bc-event-block')[0];
        
        var selector = $('.bc-rangeendtype-date', block)[0];
        
        if(selector.checked)
        {
            $('.bc-rangeend-date',block).attr('disabled','');    
        }
    
    });

    $('.bc-quickview-prev').click(function () {
        var month = $('#bc_quickview_month').attr('title');
        var year = $('#bc_quickview_year').attr('title');
        
        month--; 
        
        if(month < 1)
        {
            month = 12;
            year--;
        }
        
        $('#bc_quickview_month').attr('title', month);
        $('#bc_quickview_year').attr('title', year);
        
		if($('.bc-calendar-quickview').attr('title'))
		{
			blendcalendar_update_quickview();
		}
        return false;
        
    });

    $('.bc-quickview-next').click(function () {
        var month = $('#bc_quickview_month').attr('title');
        var year = $('#bc_quickview_year').attr('title');
        
        month++; 
        
        if(month > 12)
        {
            month = 1;
            year++;
        }
        
        $('#bc_quickview_month').attr('title', month);
        $('#bc_quickview_year').attr('title', year);
        
		if($('.bc-calendar-quickview').attr('title'))
		{
			blendcalendar_update_quickview();
		}
        return false;
        
    });


    $('.bc-date').datepicker();
    
    if($('.bc-calendar-quickview').attr('title'))
    {
        blendcalendar_update_quickview();
    }
    
});

function blendcalendar_update_quickview()
{

    $('.bc-calendar-quickview').html('<p style="text-align: center;padding-top:80px;"><img src="/extension/blendcalendar/design/standard/images/calendar-load.gif" /></p>');
    
    var month = $('#bc_quickview_month').attr('title');
    var year = $('#bc_quickview_year').attr('title');
    
    var infoString = $('.bc-calendar-quickview').attr('title');
    
    var infoTokens = infoString.split('|');
    
    var contentClassAttributeId = infoTokens[0];
    
    var nodeId = infoTokens[1];

    var url='/blendcalendar/30boxes/' + contentClassAttributeId + '/' + year + '/' + month + '/(subtree)/' + nodeId;
    
    $.get(url, {}, function (response) {
        $('.bc-calendar-quickview').html(response);
        

        $('.bc-quickview-link').click(function () {
            var day = $(this).html();
            $('.bc-quickview-day').hide();
            $('#bc_quickview_day_' + day).show();
            
            $('.bc-quickview-link').removeClass('selected');
            $(this).addClass('selected');
            
            return false;
        });        
    });
}
