$(function() {
	$("#datepickfrom").datepicker({
		minDate: min_date,
		maxDate: max_date,
		changeMonth: true,
		changeYear: true,
		altField: '#unixdatefrom',
		altFormat: '@'
	});
	
	$("#datepickto").datepicker({
		minDate: min_date,
		maxDate: max_date,
		changeMonth: true,
		changeYear: true,
		//Cannot use the altField and altFormat here, because we want to return the end of the day, not the beginning.
		//So create a workaround
		onClose: function(date) {
			valt = $("#datepickto").datepicker('getDate');
			if (valt) {
				timestamp = valt.getTime() + 3600 * 24 * 1000;
				$("#unixdateto").val(timestamp);
			}
		}
	});
});

function hidefields() {
	if (!$("#datepickfrom").val()) {
		$("#unixdatefrom").attr("disabled", "disabled");
	}
	if (!$("#datepickto").val()) {
		$("#unixdateto").attr("disabled", "disabled");
	}
	if (!$("#vidname").val()) {
		$("#vidname").attr("disabled", "disabled");
	}
	$("#datepickfrom").attr("disabled", "disabled");
	$("#datepickto").attr("disabled", "disabled");
	$("#filter").attr("disabled", "disabled");
}

function resetfilters() {
	$(".filtervar").val('');
	$("#classes").val('[]');
}