Date.prototype.firstDayOfMonth = function() {
  var d = new Date(
      this.getFullYear(),
      this.getMonth(),
      this.getDate()
      );
  d.setDate(1);
  return d.getDay();
};

Date.prototype.lastDateOfLastMonth = function() {
  var d = new Date(
      this.getFullYear(),
      this.getMonth(),
      this.getDate()
      );
  d.setDate(1);
  d.setTime(d.getTime() - 1);
  return d.getDate();
}

Date.prototype.lastDateOfMonth = function() {
  var d = new Date(
      this.getFullYear(),
      this.getMonth(),
      this.getDate()
      );
  d.setMonth(d.getMonth() + 1);
  d.setDate(1);
  d.setTime(d.getTime() - 1);
  return d.getDate();
}

