//---------------------------------------------------------------------------
//
// File:    date.js
// Purpose: Give the date of the next nth day of the week, i.e. the third Sat.
// Modified to only return even months and include December
// Usage:   For the 4th Saturday:
//            day = new NthDay();
//			  day.showDate(4, 5);
// Author:  Torville
// Date:    07/03/2009
//
//---------------------------------------------------------------------------

function SinglesNthDay() {

  // Properties
  this.single_month_names = new Array( "", "February", "", "April",
                                "", "June", "", "August",
                                "", "October", "", "December" );
  this.now = new Date();
  this.showDate = SinglesNthDay_showDate;
}

function SkipAMonth(someDate) {
    someDate.setDate(1);
	tmp_month = someDate.getMonth() + 1;
	if (tmp_month == 12) {
		tmp_year = someDate.getFullYear();
		someDate.setFullYear(tmp_year + 1, 0, 1);
	}		
	else
		someDate.setMonth(tmp_month);	
	return someDate;
}


function SinglesNthDay_showDate(nth, dow) {

	today_date = new Date();
	today_month = today_date.getMonth();
	today_day = today_date.getDate();
  
	// Figure correct day for munch
	munch_date = new Date();
	
	// Skip months that do not have a munch
	while (this.single_month_names[munch_date.getMonth()] == "") {
		munch_date = SkipAMonth(munch_date);
	}	
			
    munch_date.setDate(1 + (dow - munch_date.getDay()) + ((nth - 1) * 7));	
	munch_month = munch_date.getMonth();
	munch_day =  munch_date.getDay();
				
	// If it's this month and past the day of the munch, you have to wait until next time
	if ( (munch_month == today_month) && (munch_day < today_day)) {
		munch_date = SkipAMonth(munch_date);
	    munch_date.setDate(1 + (dow - munch_date.getDay()) + ((nth - 1) * 7));	
		munch_month = munch_date.getMonth();
		munch_day =  munch_date.getDay();
	}
		    
    document.write(this.single_month_names[munch_month] + " " + munch_day);
    return;
  }


