function checkDateInAdvancedSearch() {
  var yearStart = trim($('#datestartinput').val());
  var yearEnd = trim($('#dateendinput').val());
  // Year start and yearend must be numbers
  if (yearStart != '' && isNaN(yearStart)) {
    alert('Year start is not a number');
    return false;
  } else if (yearEnd != '' && isNaN(yearEnd)) {
    alert('Year end is not a number');
    return false;
  } else if (yearStart != '' && yearEnd != '' && parseInt(yearStart) > parseInt(yearEnd)) {
    alert('Year start must be before Year end');
    return false;
  }
  return true;
}

function trim(s) {
  return s.replace(/^\s+/, '').replace(/\s+$/, '');
}

function publishFiles(server) {
  checkAndSubmitFiles('publish', server);
}

function revertFiles(server) {
  checkAndSubmitFiles('revert', server);
}

function checkAndSubmitFiles(mode, server) {
  // Set mode to publish
  $('#mode').val(mode);

  // Check that at least 1 file has been selected
  var cnt = 0;
  $('.' + mode).each(function() {
    if ($(this).val() != '') {
      ++cnt;
    }
  });
  if (cnt > 0) {
    if (confirm('Do you really want to ' + mode + ' ' + cnt + ' file' + ((cnt > 1) ? 's' : '') + ' to the ' + server + ' server?')) {
      var url = $('#publishForm').attr('action');
      url = url + '?function=publishStaticFiles&mode=' + mode;
      $('#publishForm').attr('action', url);
      $('#publishForm').submit();
    }
  } else {
    alert('Please select at least 1 file to ' + mode + '.');
  }
}
