/*
   New Perspectives on JavaScript
   Tutorial 2
   Review Assignment

   Author: Rich Howard, Ryan Cook
   Date: 2-4-08
 
   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 = holiday < today ? year + 1 : year;
    holiday.setFullYear(year);
    return holiday;
    
}

function countdown(start,stop) {
    time = (stop - start);
    Days = time/(1000*60*60*24);
    Hours = (Days - Math.floor(Days))*24;
    Minutes = (Hours - Math.floor(Hours))*60;
    Seconds = (Minutes - Math.floor(Minutes))*60;

    return Math.floor(Days) + " days, " + Math.floor(Hours) + " hrs, " + Math.floor(Minutes) + " mins, " + Math.floor(Seconds) + " secs";
}




