/**
 * Misc. date functions.
 */

function dateToTimeString( dt_date ){
// Formats time as hh:mm:ss TT
  var str_hr    = dt_date.getHours();
  var str_min   = dt_date.getMinutes();
  var str_sec   = dt_date.getSeconds();

  return ( str_hr % 12 == 0 ? "12" : str_hr % 12 ) + ":" +
         ( str_min > 9 ? str_min : "0" + str_min ) + ":" +
         ( str_sec > 9 ? str_sec : "0" + str_sec ) + " " +
         ( str_hr < 12 ? "AM" : "PM" );

}

function dateToDateString( dt_date ){
// Returns the clients date time in the following format:
// Mmm-d-yyyy or, for example, Apr-23-1999
  var str_month = jsMonthToString( dt_date.getMonth() );
  var str_date  = dt_date.getDate();
  var str_year  = dt_date.getYear();

// NS returns 0 for 1900, 100 for 2000 ...
  if( str_year < 1900 ) str_year = str_year + 1900;

  return str_month.substr( 0, 3 ) + "-" + str_date + "-" + str_year;
}

function jsMonthToString( int_month ){
// Turns JavaScript month (Jan == 0...) into string

  switch( int_month ){
    case( 0 ):
      return "January";

    case( 1 ):
      return "February";

    case( 2 ):
      return "March";

    case( 3 ):
      return "April";

    case( 4 ):
      return "May";

    case( 5 ):
      return "June";

    case( 6 ):
      return "July";

    case( 7 ):
      return "August";

    case( 8 ):
      return "September";

    case( 9 ):
      return "October";

    case( 10 ):
      return "November";

    case( 11 ):
      return "December";

    default:
      return "err";
    }
}