/*
   New Perspectives on JavaScript
   Tutorial 2
   Review Assignment

   Author: Mike Shepard
   Date:  10/09/2009
 
   Function List:
   showDateTime(time)
      Returns the date in a text string formatted as:
      mm/dd/yyyy at hh:mm:ss am

   changeYear(today, holiday)
      Changes the year value of the holiday object to point to the
      next year if it has already occurred in the present year

   countdown(stop, start)
      Displays the time between the stop and start date objects in the
      text format:
      dd days, hh hrs, mm mins, ss secs
*/

function showDateTime(time) {
   date = time.getDate();
   month = time.getMonth()+1;
   year = time.getFullYear();

   second = time.getSeconds();
   minute = time.getMinutes();
   hour = time.getHours();

   ampm = (hour < 12) ? " am" : " pm";
   hour = (hour > 12) ? hour - 12 : hour;
   hour = (hour == 0) ? 12 : hour;

   minute = minute < 10 ? "0"+minute : minute;
   second = second < 10 ? "0"+second : second;

   return month+"/"+date +"/"+year+" at "+hour+":"+minute+":"+second+ampm;
}

function changeYear(today, holiday) {
   year = today.getFullYear();
   holiday.setFullYear(year);
   year = (today > holiday) ? year + 1 : year
   year = holiday.setFullYear(year)
}

function countdown (start, stop) {
  time = stop - start;
  time = Math.floor (time / 1000);
  secs = time % 60;
  time = Math.floor (time / 60);
  mins = time % 60;
  time = Math.floor (time / 60);
  hrs = time % 24;
  time = Math.floor (time / 24);
  days = time;
  return [days + "days", hrs + "hrs", mins + "mins", secs + "secs"].join (", ");
}


