/**
 * Compare the specified date to the current date
 *
 * Returns FALSE if it is less
 *
 */
function compareToCurrDate(year,month,day) {

    var eDate = new Date();
    eDate.setFullYear(year,month,day);

    var cDate = new Date();

    if (eDate.getTime() < cDate.getTime()) {
        return confirm("Are you sure you want to add date in the past?");
    } else {
        return TRUE;
    }
}

/**
 *
 */
function donothing(event) {
  event.preventDefault();
}

/**
 * Don't allow users to post content more than once
 * Disable form fields after submit has been clicked
 * Note: we don't want to disable checkboxes, just make them look disabled
 *       but we do want to disable select drop downs
 */
$(document).ready(function() {
  $('form').not(':has(input.autocomplete)').each( function () {
    var form = $(this);
    form.find('input:submit').click(function() {
      // If any elements don't want us to submit, then don't
      var toSubmit = true;
      form.find('input').each(function() {
        var ret = $(this).triggerHandler('toSubmit');
        if (ret == false) {
          toSubmit = false;
        }
      });
      if (toSubmit == false) {
        return false;
      }

      // hide cancel links and other buttons
      form.find('a.uofc-cancel-link').hide();
      form.find('input:submit').not(this).hide();
      // replace the submit button with a regular button
      var mytype  = 'type="button"';
      var myid    = 'id="'+$(this).attr('id')+'"';
      var myclass = 'class="'+$(this).attr('class')+' loading"';
      var mystyle = 'style="'+$(this).attr('style')+'"';
      var myvalue = 'value="Please wait ..."';
      var button  = '<input '+mytype+' '+myid+' '+myclass+' '+mystyle+' '+myvalue+' />';
      $(button).insertAfter(this);
      // disable form fields while we wait
      form.find(':input:not(:submit)').disable();
      form.find('.form-item a').disable();
      // hide the submit button
      $(this).removeAttr('id');
      $(this).hide();
    });
  });
})

jQuery.fn.extend({
  disable: function () {
    $(this).fadeTo(1, 0.50).bind('click', donothing).bind('keydown', donothing);
  },
  enable: function () {
    $(this).fadeTo(1, 1.00).unbind('click', donothing).unbind('keydown', donothing);
  }
});

/**
 * todo: use jQuery
 */
function togglePublication(a) {
  var e=document.getElementById(a);
  if (!e)return TRUE;
  if (e.style.display=="none") {
    e.style.display="block"
  } else {
    e.style.display="none"
  }
  return TRUE;
}

