$.datepicker.setDefaults(
  $.datepicker.regional['nl'],
  {dateFormat: 'yy-mm-dd'}
);

$(document).ready(function(){
  $("#commentForm").validate();

  $(".dateInput").datepicker({
    showOn: "button",
    buttonImage: "media/images/icons/calendar.gif",
    buttonImageOnly: true,
    minDate: new Date(),
    maxDate: "+1y",
    showAnim:'fadeIn',
    dateFormat: 'yy-mm-dd',
    altField: "#displayDate",
    altFormat: "d MM yy"
  });

  $("#dateDisplay")
    .datepicker({
      minDate: new Date(),
      maxDate: "+1y",
      inline: true
    })
    .bind('dateSelected', function(e, selectedDate, td) {
      window.alert('You selected ' + selectedDate);
      document.getElementById('selectedDate').value = selectedDate;
    });

  // Get all textareas that have a "maxlength" property.
  $('textarea[maxlength]').live('keyup blur', function() {
      // Store the maxlength and value of the field.
      var maxlength = $(this).attr('maxlength');
      var val = $(this).val();

      // Trim the field if it has content over the maxlength.
      if (val.length > maxlength) {
          $(this).val(val.slice(0, maxlength));
      }
  });
});

function submitForm(v, m, f) {
  if (v) {
    if($('#commentForm').validate().form()) {
      document.forms["commentForm"].submit();
    }
    else {
      return false;
    }
  }
}

