/*
   JavaScript Functions

   Author: Prof Sandy Feder
   Date:   October 1, 2006

   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
  
   stringReverse
      Used to reverse the order of characters in a text string
 
  randomInteger(size)
      Used to return a number between zero and size

*/

function showDate(dateObj)
{
  var thisDate = dateObj.getDate();
  var thisMonth = dateObj.getMonth() + 1;  // months run from 0 to 11
  var thisYear = dateObj.getFullYear();
  var nicedate = thisMonth + "/" + thisDate + "/" + thisYear;
  alert( nicedate );
  return nicedate;
}
function showTime(dateObj)
{ 
   thisSecond = dateObj.getSeconds();
   thisSecond = (thisSecond < 10) ? "0" + thisSecond : thisSecond;
   thisMinute = dateObj.getMinutes();
   thisMinute = (thisMinute < 10) ? "0" + thisMinute : thisMinute;

   var thisHour = dateObj.getHours();
   var ampm = (thisHour < 12) ? "am" : "pm";
   thisHour = (thisHour > 12) ? thisHour -12 : thisHour;
   thisHour = (thisHour == 0) ? 12 : thisHour;
   var nicetime = thisHour + ":" + thisMinute + ":" + thisSecond + " " + ampm;
   return nicetime;
}
function calcDays(currentDate)
{
  //  create a date of Jan 1 next year
  var newYear = new Date("January 1, 2007");  // temporary year
  var nextYear = currentDate.getFullYear() + 1;

  newYear.setFullYear(nextYear);

  // calculate the number of days between today and Jan 1 next year
  var days = (newYear - currentDate) / (1000 * 60* 20 * 24);  // Convert milliseconds to days
  return days;

}
function randomInteger(size) 
{     // size is the maximum integer returned and zero the minimum
   return Math.floor((size+1)*Math.random());
}

function stringReverse(textString) 
{
   if (!textString) return '';
   var revString='';
   for (i = textString.length-1; i>=0; i--)
       revString+=textString.charAt(i)
   return revString;
}