
jQuery.toggleMinDate = function (from, to, delta) {
  var fromDate = from.datepicker("getDate");
  var toDate = to.datepicker("getDate");
  var d = (delta == null ? 1 : delta);

  if (toDate == null || fromDate > toDate){
    suggestDate = new Date(fromDate.getFullYear(), fromDate.getMonth(), fromDate.getDate() + d);
    to.datepicker("setDate" , suggestDate);
  }

  var minToDate = new Date(fromDate.getFullYear(), fromDate.getMonth(), fromDate.getDate() + 1);
  to.datepicker("option", "minDate", minToDate);

};


jQuery.initRange = function(from, to, delta) {

  // init toggler
  from.change(function() {
    jQuery.toggleMinDate(from, to, delta);
  });

  // other option
  from.datepicker("option", "showOtherMonths", true);
  to.datepicker("option", "showOtherMonths", true);

  from.datepicker("option", "selectOtherMonths", true);
  to.datepicker("option", "selectOtherMonths", true);

  from.datepicker("option", "yearRange", "c:c+1");
  to.datepicker("option", "yearRange", "c:c+1");

  from.datepicker("option", "changeYear", true);
  to.datepicker("option", "changeYear", true);

  from.datepicker("option", "changeMonth", true);
  to.datepicker("option", "changeMonth", true);

  from.datepicker("option", "minDate", "today");
  to.datepicker("option", "minDate", "+1");
  

}
