
<script type="text/javascript" charset="utf-8">
	$(function() {	
		$('#reportrange').daterangepicker(
			{
				minDate: '2011-01-01',
				startDate: "<%= @starts_at %>",
        endDate: "<%= @ends_at %>",
				locale: {
		      format: 'YYYY-MM-DD',					
          applyLabel: '<%= I18n.t(:apply_date_range) %>',
          fromLabel: '<%= I18n.t(:from) %>',
          toLabel: '<%= I18n.t(:to) %>',
					clearLabel: '<%= I18n.t(:clear) %>',
          customRangeLabel: '<%= I18n.t(:custom_range) %>',
          firstDay: 1
        },
		
				ranges: {
					'<%= I18n.t(:today) %>': [moment(), moment()],
					'<%= I18n.t(:yesterday) %>': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],					
          '<%= I18n.t(:last_7_days) %>': [moment().subtract(6, 'days'), moment()],
          '<%= I18n.t(:last_14_days) %>': [moment().subtract(13, 'days'), moment()],
					'<%= I18n.t(:this_week) %>': [moment().startOf('isoweek'), moment().endOf('isoweek')],
					'<%= I18n.t(:last_week) %>': [moment().subtract(1, 'week').startOf('isoweek'), moment().subtract(1, 'week').endOf('isoweek')],
					'<%= I18n.t(:last_2_weeks) %>': [moment().subtract(2, 'week').startOf('isoweek'), moment().subtract(1, 'week').endOf('isoweek')],
					'<%= I18n.t(:this_month) %>': [moment().startOf('month'), moment().endOf('month')],
					'<%= I18n.t(:last_month) %>': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
					'<%= I18n.t(:last_quarter) %>': [moment().subtract(2, 'month').startOf('month'), moment().endOf('month')],
					'<%= I18n.t(:this_year) %>': [moment().startOf('year'), moment().endOf('year')],
					'<%= I18n.t(:last_year) %>': [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year').endOf('year')],
				}
			},
			function(start, end) {
				// console.log(start); Australia date format on selection
				var start_date_str = start.format('YYYY-MM-DD');
				var end_date_str = end.format('YYYY-MM-DD');
				
				$("#report_starts_at").val(start_date_str);
				$("#report_ends_at").val(end_date_str);
				
		    $('#reportrange span').html(start_date_str + ' - ' + end_date_str);		        
				
		    <% if defined?(url_prefix) %>    
				var new_path = "<%= url_prefix%>" + "?starts_at=" + start.format('YYYY-MM-DD') + "&ends_at="  + end.format('YYYY-MM-DD');
				window.location = new_path;
				<% end %>
				
		  }
		);
	});
</script>