/*
   New Perspectives on JavaScript, 2nd Edition
   Tutorial 2
   Tutorial Case

   Author: Rebecca Van Nostrand
   Date:   January 30, 2010

   Function List:
   showDate(dateObj)
      Returns the current date in the format mm/dd/yyyy

   showTime(dateObj)
      Returns the current time in the format hh:mm:ss am/pm

   calcDays(currentDate)
      Returns the number of days between the current date and January 1st
      of the next year

*/

function showDate(dateObj) {
	thisDate = dateObj.getDate();
	thisMonth = dateObj.getMonth() + 1;
	thisYear = dateObj.getFullYear();
	return thisMonth +"/" + thisDate +"/" + thisYear; 
}

function showTime(dateObj) {
	thisSecond = dateObj.getSeconds();
	thisMinute = dateObj.getMinutes();
	thisHour = dateObj.getHours(); 
	//change thisHour from 24-hour time to 12-hour time by:
	//1) if thisHour < 12 then set ampm to"a.m" otherwise set it to "p.m"
	var ampm =(thisHour < 12) ? " a.m." : " p.m.";
	
	// 2) subtract 12 from the thisHour variable
	thisHour = (thisHour > 12) ? thisHour - 12: thisHour;
	
	// 3) if thisHour equals 0, change it to 12
	thisHour = (thisHour ==0) ? 12: thisHour;
	
	// add leading zeroes to minutes and seconds less that 10
	thisMinute = thisMinute < 10 ? "0"+thisMinute : thisMinute;
	thisSecond = thisSecond < 10 ? "0"+thisSecond : thisSecond;
	
	return thisHour +":" + thisMinute +":" + thisSecond + ampm;  

}	



//create a date object for National Check in Date
function calcDays(currentDate){
	
	//add hour for daylight savings
	natDate = new Date ("July 18, 2010 10:00:00");
	
//calculate the difference between current date and National Date	
//multipy the difference since Javascript measures dates in milliseconds not days. 
//1000 milliseconds in a one day; 60 seconds in one minute; 60 minutes in hour; 24 hours in day
	days =(natDate - currentDate)/(1000*60*60*24);
	return days
}	