function Countdown(when) {
  return difference(when, new Date()).formatDate();
}

function Countup(when) {
  return difference(new Date(), when).formatDate();
}

function formatObjectDate() {
  if (this.weeks < 0) return 'Your due date is here!!';
  return ((this.weeks < 10) ? '0' + this.weeks : this.weeks) +
         ((this.weeks == 1) ? ' Week ' : ' Weeks ') +
         ((this.days < 10) ? '0' + this.days : this.days) +
         ((this.days == 1) ? ' Day ' : ' Days ') +
         ((this.hours < 10) ? '0' + this.hours : this.hours)  + ':' +
         ((this.minutes < 10) ? '0' + this.minutes : this.minutes) + ':' +
         ((this.seconds < 10) ? '0' + this.seconds : this.seconds) + ' Hours';
}

function difference(older,newer) {
    var myObject = new Object();

    var dif = older.getTime() - newer.getTime();

    myObject.days = Math.floor(dif/1000/60/60/24);

    myObject.weeks = Math.floor(myObject.days/7);

    dif = dif - myObject.days*1000*60*60*24

    myObject.hours = Math.floor(dif/1000/60/60);

    dif = dif - myObject.hours*1000*60*60

    myObject.minutes = Math.floor(dif/1000/60);

    dif = dif - myObject.minutes*1000*60

    myObject.seconds = Math.floor(dif/1000);

    myObject.days = myObject.days % 7;

    myObject.formatDate = formatObjectDate;

    return myObject;
}