//---------------------------------------------------------------------------
//
// File:    date.js
// Purpose: Give the date of the next nth day of the week, i.e. the third Sat.
// Usage:   For the 4th Saturday:
//            day = new NthDay();
//			  day.showDate(4, 5);
// Author:  Torville
// Date:    05/04/1999
//
//---------------------------------------------------------------------------

function NthDay() {

  // Properties
  this.month_names = new Array( "January", "February", "March", "April",
                                "May", "June", "July", "August",
                                "September", "October", "November", "December" );
  this.now = new Date();
  this.showDate = NthDay_showDate;
}


function NthDay_showDate(nth, dow) {
  tmp_day = new Date();

  // Figure what correct day would be for this month
  tmp_day.setDate(1);
  tmp_day.setDate(1 + (dow - tmp_day.getDay()) + ((nth - 1) * 7));
  
  // If target date is in December, no munch
  if (tmp_day.getMonth() == 11) {
	  document.write("January");
	  return;
  }
  
  // Is that today?
  if (tmp_day.getDate() == this.now.getDate()) {
//    document.write("Today, ");
    document.write(this.month_names[this.now.getMonth()] + " " + this.now.getDate());
    return;
  }

  // Is it later this month?
  if (tmp_day.getMonth() == this.now.getMonth() && tmp_day.getDate() > this.now.getDate()) {
//    document.write("Later this month, on ");
	
    document.write(this.month_names[tmp_day.getMonth()] + " " + tmp_day.getDate());
    return;
  }

  // Aw, it's next month
  tmp_day = new Date();
  tmp_day.setDate(1);
  tmp_day.setMonth(tmp_day.getMonth() + 1);
  
    // If target date is in December, no munch
  if (tmp_day.getMonth() == 11) {
	  document.write("January");
	  return;
  }
  
  tmp_day.setDate(1 + (dow - tmp_day.getDay()) + ((nth - 1) * 7));
//  document.write("Next month, on ");
  document.write(this.month_names[tmp_day.getMonth()] + " " + tmp_day.getDate());

}

