function initDatepicker() {
	var lang = getLang(); 
	loadScript('assets/plugins/datepicker/bootstrap-datepicker.' + lang + '.min.js', function() {
		$(".datepicker").datepicker({
			language: lang
		});
	});
}

function initDaterangePicker() {
	var lang = getLang();
	loadScript('assets/plugins/daterangepicker/' + lang + '.js');
}

function initMomentLang() {
	var lang = getLang();
	loadScript('assets/plugins/moment/' + lang + '.js');
}

function getFormatDate() {
	var lang = getLang();
	switch (lang) {
		case 'en':
			return 'YYYY-MM-DD';
			break;
		case 'fr':
			return 'DD/MM/YYYY';
			break;
		default:
			return 'YYYY-MM-DD';
			break;
	}
}

function getFormatDatetime() {
	var lang = getLang();
	switch (lang) {
		case 'en':
			return 'YYYY-MM-DD HH:mm:ss';
			break;
		case 'fr':
			return 'DD/MM/YYYY HH:mm:ss';
			break;
		default:
			return 'YYYY-MM-DD HH:mm:ss';
			break;
	}	
}

function convertToDateRange(str)
{
	return str.replace('-','/');
}

function getDaterangePicker(selector, startDate, parentEl, endDate) {
	// console.log('getDaterangePicker');
	// console.log("StartDate : ", startDate);
	if (typeof(parentEL) == 'undefined') {
		parentEl = 'file_effect_date_selection';
	} else {
		$(selector).parent().parent().parent().parent().parent().parent().parent().parent().parent().addClass(parentEl);
	}
	if (typeof(startDate) == 'undefined') {
		// startDate = moment().format(dateRangePickerLanguage.format);
		startDate = moment();
	} else {
		// console.log("ici");
		startDate = moment(startDate, getFormatDate());
	}
	// console.log("selector : ", selector);
	// console.log("StartDate : ", startDate);
	// console.log("format", dateRangePickerLanguage.format);
	var options = {
		alwaysShowCalendars: true,
		autoUpdateInput: false,
		format: dateRangePickerLanguage.format,
		opens: 'left',
		showDropdowns: true,
		showWeekNumbers: true,
		startDate: startDate,
		separator: dateRangePickerLanguage.separator,
		locale: dateRangePickerLanguage.locale,
		buttonClasses: 'btn light uppercase weight-900',
		parentEl: '.' +parentEl
	};

	if (typeof(endDate) != 'undefined') {
		options.cancelClass = "btn-danger";
		options.endDate = endDate;
		options.ranges = dateRangePickerLanguage.ranges;
		options.template =
            '<div class="daterangepicker">' +
                '<div class="ranges"></div>' +
                '<div class="drp-calendar left">' +
                    '<div class="calendar-table"></div>' +
                    '<div class="calendar-time"></div>' +
                '</div>' +
                '<div class="drp-calendar right">' +
                    '<div class="calendar-table"></div>' +
                    '<div class="calendar-time"></div>' +
                '</div>' +
                '<div class="drp-buttons">' +
                    '<span class="drp-selected"></span>' +
                    '<button class="cancelBtn" type="button"></button>' +
                    '<button class="applyBtn" disabled="disabled" type="button"></button> ' +
                '</div>' +
            '</div>';
	} else {
		options.autoApply = true;
		options.singleDatePicker = true;
	};

	$('#files_selection').parent().parent().parent().parent().parent().parent().parent().parent().parent().removeClass(parentEl).addClass(parentEl);
	var picker = $(selector).daterangepicker(options, function(start, end, label) {
		//console.log("New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')");
	});
	
	$(selector + ' .daterangepicker').removeClass('light').addClass('light');

	$(selector).next('span.add-on').off('click').on('click', function() {
		$(selector).trigger('click');
	});

	$(selector).on('apply.daterangepicker', function(ev, picker) {
		$(this).val(picker.startDate.format(dateRangePickerLanguage.format));
		$(selector).trigger('change');
	});

	return picker;
}