//	Calendar Javascript - Copyright (C) 2007-2010 Charles A Upsdell, All Rights Reserved; www.upsdell.com
//
//  For pages that check schedules
//
aModule.uses( 'cCalendar_cs', 'cCalendar', 'cal_config' );


cCalendar.prototype.toCheckHTML = function ( id )
{
var $name = 'toCheckHTML';
id = id || 'ins_check_schedule';
var o = getElement( id );
if ( o )
	o.innerHTML = this.toHTML( 'check', kal.period );
return false;
}

cType.prototype.eventType = function ()
{
var rv = '';
switch ( this.t1 )
  {
  case	'E':
		rv = 'event';
		break;
  case	'G':
		rv = 'game';
		break;
  case	'P':
		rv = 'practice';
		break;
  default:
		rv = this.t0 + ' event';
		break;
  }
return rv;
}

function calCheckSchedulesInit ( sd )
{
sd.nDaysToCome = 0;
sd.nLines = 0;
sd.nNotes = 0;
sd.nAlerts = 0;
sd.nErrors = 0;
sd.nWarnings = 0;
sd.nGameTime = (typeof(kal.eventConflictGameTime) == 'undefined') ? 120 : kal.eventConflictGameTime;
sd.nWayEarlyGameTime = 480;
sd.nEarlyGameTime = (typeof(calEventConflictGameEarly) == 'undefined') ? 1080 : calEventConflictGameEarly;
sd.nWayEarlyPracticeTime = 480;
sd.nEarlyPracticeTime = (typeof(calEventConflictPracticeEarly) == 'undefined') ? 1050 : calEventConflictPracticeEarly;
sd.nOldNewsDays = (typeof(calEventConflictOldNewsDays) == 'undefined') ? 30 : calEventConflictOldNewsDays;
sd.is12HourClock = (typeof(calEventConflict12HourClock) == 'undefined') ? true : calEventConflict12HourClock;
sd.isLocalSite = (String(window.location).indexOf('file:') == 0);
sd.nDaysSince2000 = calDays( sd.this_year, sd.this_month, sd.this_day );
return '';
}

function calGetCheckHTML ( sDateStamp, aHTML )
{
var $name = 'calGetCheckHTML';
var rv = '';
if ( arguments.length < 2 )
	{ $name.alert( '', '< 2 arguments' ); return rv; }
if ( aHTML[0] === undefined )
	aHTML.shift();
if ( aHTML.length == 1 )
	rv = '<tr><td class="date_stamp">' + sDateStamp + '</td>' + aHTML[0];
else if ( aHTML.length > 1 )
  {
	rv = '<tr><td class="date_stamp" rowspan="' + aHTML.length + '">' + sDateStamp + '</td>' + aHTML[0];
	for ( var i = 1; i < aHTML.length; ++i )
		rv += '<tr>' + aHTML[i];
  }
return rv;
}

function calCheckLocation ( sLocation, sPrefix )
{
if ( sPrefix === undefined )
	sPrefix = 'at';
if ( sLocation == '' )
	return '';
else
	return ' ' + sPrefix + ' ' + sLocation;
}

function calCheckSchedulesSimilar ( s1, s2 )
{
s1 = s1.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
s2 = s2.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
if ( s1 == s2 )
	return true;
var ix1 = s1.lastIndexOf( ' ' );
var ix2 = s2.lastIndexOf( ' ' );
if ( (ix1 == -1) || (ix2 == -1) )
	return false;
if ( (s1.substring(0,ix1)) != (s2.substring(0,ix2)) )
	return false;
return true;
}

function calCheckSchedulesTerm ( sd, sHTML )
{
if ( sd.isLocalSite || (sd.nNotes + sd.nAlerts + sd.nWarnings + sd.nErrors) )
  {
	var today = new Date();
	var sTable = (typeof(kal.eventConflictTableHTML) == 'undefined') ? '<table class="grid" cellspacing="0" cellpadding="0"><tbody>\n' : kal.eventConflictTableHTML;
	var sHTML2 = ( typeof(kal.eventConflictNoSummary) != 'undefined' ) ? '' : '<p>There are ' + (sd.nNotes + sd.nAlerts + sd.nWarnings + sd.nErrors) + ' issues on ' + kal.aMonthName[today.getMonth()] + ' ' + today.getDate() + ', ' + today.getFullYear() + ':</p>\n';
	sHTML = sHTML2 + sTable + sHTML + '</tbody></table>\n';
  }
return sHTML;
}

function calNth ( n )
{
var th = 'th';
if ( (n < 10) || (n > 19) )
  {
	switch ( n%10 )
	  {
	  case	1:
			th = 'st';
			break;
	  case	2:
			th = 'nd';
			break;
	  case	3:
			th = 'rd';
			break;
	  }
  }
return String(n) + '<sup>' + th + '</sup>';
}


function calPlural ( n, sSingular, sPlural, sZero )
{
var rv = '';
var argc = arguments.length;
if ( (argc < 2) || (sSingular === undefined) )
	sSingular = '';
if ( (argc < 3) || (sPlural === undefined) )
	sPlural = 's';
if ( (argc < 4) || (sZero === undefined) )
	sZero = 's';
if ( argc == 0 )
	return rv;
if ( n instanceof String )
	n = Number(n);
if ( n < 0 )
	n = -n;
if ( n == 0 )
	rv = sZero;
else if ( n == 1 )
	rv = sSingular;
else
	rv = sPlural;
return rv;	
}

cType.prototype.description = function ()
{
var rv = '';
switch ( this.t1 )
  {
  case	'G':
		if ( this.t3 == 'H' )
			rv = 'home';
		else if ( this.t3 == 'A' )
			rv = 'away';
		if ( this.t2 == 'R' )
			rv = 'regular ' + rv;
		else if ( this.t2 == 'T' )
			rv = 'tournament ' + rv;
		else if ( this.t2 == 'X' )
			rv = 'exhibition ' + rv;
		break;
  case	'G':
		rv = 'practice';
		break;
  default:
		break;
  }
return rv;
}


// Method to return HTML with a list of conflicts
cEventYear.prototype.toCheckHTML = function ( y, m, s )
{
var $name = 'toCheckHTML';
s.month = -1;

var sHTML = '';
var nDayMonthStarts = this.aYearDays[m];
var nDaysInMonth = this.aMonthDays[m];
var sYearAndMonth = y.toString() + '&nbsp;' + kal.aMonthNameSmall[m] + '&nbsp;';
var nCalendarDaysSince2000 = calDays( y, m, 0 );
var isTournamentOngoing = false;
var sDateStamp = '';
var aHTML = new Array(1);
for ( var d = 0; d < nDaysInMonth; ++d )
  {
	if ( aHTML.length > 0 )
	  {
		sHTML += calGetCheckHTML( sDateStamp, aHTML );
		aHTML = new Array(1);
	  }
	if ( d > 0 )
		nCalendarDaysSince2000 += 1;
	var yd = d + nDayMonthStarts;
	sDateStamp = calNth(1+d);
	if ( (y < s.this_year) || (((y == s.this_year) && (m < s.this_month))) || ((y == s.this_year) && (m == s.this_month) && (d < s.this_day)) )
	  {
		for ( var e = 0; e < this.aDay[yd].aEvent.length; ++e )
		  {
			if ( this.aDay[yd].aEvent[e].isGame && (this.aDay[yd].aEvent[e].sScore1==='') )
			  {
				if ( this.aDay[yd].aEvent[e].isCancelled )
				  {
					if ( this.aDay[yd].aEvent[e].isRegularGame )
					  {
						aHTML[aHTML.length] = '<td class="warning">warning</td><td>%0 game vs %1 was &ldquo;%2&rdquo;: reschedule or delist it.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock,'TBA'), this.aDay[yd].aEvent[e].sTeam2, this.aDay[yd].aEvent[e].sWhyCancelled.toLowerCase() );
						s.nWarnings++;
						s.nLines++;
					  }
				  }
				else if ( !this.aDay[yd].aEvent[e].isExhibitionGame || ((typeof(kal.news.isNoXScore)=='undefined')?true:!kal.news.isNoXScore) )
				  {
					aHTML[aHTML.length] = '<td class="warning">warning</td><td>%0 %1 game with %2 has no result: tell the webmaster the result.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock), this.aDay[yd].aEvent[e].oType.description(), this.aDay[yd].aEvent[e].sTeam2 );
					s.nWarnings++;
					s.nLines++;
				  }
				else if ( this.aDay[yd].aEvent[e].isExhibitionGame && s.isLocalSite && ((typeof(kal.eventConflictNoSummary)=='undefined') || ((typeof(kal.news.isNoXScore) != 'undefined') && kal.news.isNoXScore)) )
				  {
					// Only report if last 10 days
					if ( (s.nDaysSince2000 - nCalendarDaysSince2000) <= 10 )
					  {
						aHTML[aHTML.length] = '<td class="note">note</td><td>%0 %1 game with %2 has no result: the coach wants the result withheld.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock), this.aDay[yd].aEvent[e].oType.description(), this.aDay[yd].aEvent[e].sTeam2 );
						s.nNotes++;
						s.nLines++;
					  }
				  }
			  }
			if ( s.isLocalSite )
			  {
				var aNote = [ 'calendar_addendum', 'game_comment', 'games_comment', 'game_descriptor', 'isForSeasonRecord', 'news_addendum', 'opponent_descriptor', 'tournament_addendum', 'tournament_report', 'upcoming_addendum' ];
				for ( var i = 0; i < aNote.length; ++i )
				  {
					if ( (typeof(this.aDay[yd].aEvent[e].oType[aNote[i]]) != 'undefined') && (this.aDay[yd].aEvent[e].oType[aNote[i]].charAt(0) != ' ') )
					  {
						aHTML[aHTML.length] = '<td class="note">note</td><td>event with %0 &ldquo;%1&rdquo;: if expired, remove it.</td></tr>\n'.blend( aNote[i], this.aDay[yd].aEvent[e].oType[aNote[i]] );
						s.nNotes++;
						s.nLines++;
					  }
				  }
			  }
			if ( s.isLocalSite )
			  {
				if ( this.aDay[yd].aEvent[e].isCancelled )
				  {
					if ( !this.aDay[yd].aEvent[e].isGame )
					  {
						aHTML[aHTML.length] = '<td class="note">none</td><td>%0 %1 event was &ldquo;%2&rdquo;: reschedule or delist it.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock,'TBA'), this.aDay[yd].aEvent[e].oType.t0, this.aDay[yd].aEvent[e].sWhyCancelled );
						s.nNotes++;
						s.nNotes++;
					  }
				  }
			  }
			if ( s.isLocalSite && (this.aDay[yd].aEvent[e].oType.t1 != 'N') && (this.aDay[yd].aEvent[e].oType.t0 != 'S') )
			  {
				if ( this.aDay[yd].aEvent[e].sEvent.indexOf('<a') != -1 )
				  {
					aHTML[aHTML.length] = '<td class="note">note</td><td>expired event with a link to &ldquo;%0&ldquo;: consider removing the link.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].sEvent );
					s.nNotes++;
					s.nLines++;
				  }
			  }
			if ( s.isLocalSite && (this.aDay[yd].aEvent[e].oType.t1 == 'G') )
			  {
				if ( ( this.aDay[yd].aEvent[e].sEvent != '' ) && (this.aDay[yd].aEvent[e].sEvent.charAt(0) != '-') )
				  {
					aHTML[aHTML.length] = '<td class="note">note</td><td>event with sEvent &ldquo;%0&ldquo;: consider removing it.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].sEvent );
					s.nNotes++;
					s.nLines++;
				  }
			  }
			if ( s.isLocalSite && (this.aDay[yd].aEvent[e].sLocation.indexOf('<a href="http:') != -1) )
			  {	// To suppress alert message, put more than one space between '<a' and 'href' in the location's URL
				if ( (this.aDay[yd].aEvent[e].sLocation.indexOf('upsdell') == -1) && (this.aDay[yd].aEvent[e].sLocation.indexOf('arenamaps') == -1) )
				  {
					aHTML[aHTML.length] = '<td class="note">note</td><td>%0 event location has a link &ldquo;%1&ldquo;: consider removing the link.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oType.t0, this.aDay[yd].aEvent[e].sLocation );
					s.nNotes++;
					s.nLines++;
				  }
			  }
			if ( this.aDay[yd].aEvent[e].oType.t1 == 'N'  )
			  {
				if ( s.isLocalSite && ((s.nDaysSince2000 - nCalendarDaysSince2000) > s.nOldNewsDays) )
				  {
					aHTML[aHTML.length] = '<td class="note">note</td><td>Old news item: &ldquo;%1&rdquo;; if it has expired, remove it</td></tr>\n'.blend( sDateStamp, this.aDay[yd].aEvent[e].sEvent );
					s.nNotes++;
					s.nLines++;
				  }
				if ( s.isLocalSite )
				  {
					if ( this.aDay[yd].aEvent[e].sEvent.indexOf('<del>') == 0 )
					  {
						aHTML[aHTML.length] = '<td class="note">note</td><td>Expired news item: &ldquo;%0: %1&rdquo;; remove it.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].sNewsTitle, this.aDay[yd].aEvent[e].sEvent );
						s.nNotes++;
						s.nLines++;
					  }
				  }	
				if ( s.isLocalSite && (typeof(this.aDay[yd].aEvent[e].sTitle) != 'undefined') )
				  {
					var sFirstLetter = this.aDay[yd].aEvent[e].sTitle.charAt(0);
					if ( sFirstLetter != sFirstLetter.toUpperCase() )
					  {
						aHTML[aHTML.length] = '<td class="note">note</td><td>News item title has initial lowercase character: %0</td></tr>\n'.blend( this.aDay[yd].aEvent[e].sTitle );
						s.nNotes++;
						s.nLines++;
					  }
				  }	

			  }

		  }
		continue;
	  }
	s.nDaysToCome++;
	var isSeriesDay = this.aDay[yd].isSeriesDay;
	var isTournamentDay = (this.aDay[yd].sTournament == '') ? false : true;
	var isWorkDay = isInRange( 1, this.aDay[yd].nWeekDay, 5 );
	var isGameDay = false;
	var isSeriesBangDay = false;
	var isSeriesGameDay = false;
	for ( var e = 0; e < this.aDay[yd].aEvent.length; ++e )
	  {
		var oType = new cType( this.aDay[yd].aEvent[e].oType );
		if ( this.aDay[yd].aEvent[e].isGame )
			isGameDay = true;
		if ( oType.t0 == 'H' )
			isWorkDay = false;
		if ( oType.t0.charAt(0) == 'S' )
		  {
			if ( oType.t3 == '!' )
				isSeriesBangDay = true;
			continue;
		  }
		else if ( (oType.t1 == 'G') && (oType.t2 == 'T') )
		  {
			isSeriesGameDay = true;
			continue;
		  }
	  }

	if ( this.aDay[yd].sTournament == '' )
	  {
		isTournamentOngoing = false;
	  }
	else
	  {
		if ( !isTournamentOngoing && (s.nDaysToCome < 4) && (s.nDaysToCome > 1) )
		  {
			aHTML[aHTML.length] = '<td class="note">note</td><td>%0: confirm schedule.</td></tr>\n'.blend( this.aDay[yd].sTournament );
			s.nNotes++;
			s.nLines++;
		  }
		isTournamentOngoing = true;
	  }

	if ( isTournamentDay && !isGameDay && (s.nDaysToCome < 10) )
	  {
		aHTML[aHTML.length] = '<td class="alert">alert</td><td>no game is scheduled on this tournament day: if this is wrong, tell the webmaster.</td></tr>\n';
		s.nAlerts++;
		s.nLines++;
	  }

	for ( var e = 0; e <= this.aDay[yd].aEvent.length; ++e )
	  {
		if ( e == this.aDay[yd].aEvent.length )
		  {
			if ( (s.nDaysToCome == 1) && s.isLocalSite )
			  {
				aHTML[0] = '<td colspan="2" style="color:#fff; background-color:#196;">%0 today for the <a href="index.htm" style="color:#9ff; font-weight:bold;" target="_top">%1 %2 team</a></td></tr>\n'.blend( (aHTML.length==1) ? ' no issue' : ' what&rsquo;s up', kal.ourSeason, kal.ourTeam+' '+kal.ourTeamLevel );
			  }
			break;
		  }
		switch ( this.aDay[yd].aEvent[e].oType.t0 )
		  {
		  case	'':
				continue;
		  case	'H':
				continue;
		  case	'N':
		  case	'N!':
				continue;
		  default:
				break;
		  }

		var t1_start = this.aDay[yd].aEvent[e].oTime.t1;
		var t1_end = this.aDay[yd].aEvent[e].oTime.t2;
		var t1_type = this.aDay[yd].aEvent[e].oType.eventType();

		// Check for issues with event

		if ( this.aDay[yd].aEvent[e].isGame && !isTournamentDay && this.aDay[yd].aEvent[e].isTournamentGame )
		  {
			aHTML[aHTML.length] = '<td class="error">error</td><td>%0 tournament game isn&rsquo;t during tournament: tell the webmaster.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','-',s.is12HourClock,'TBA') );
			s.nErrors++;
			s.nLines++;
		  }

		if ( this.aDay[yd].aEvent[e].isGame && !this.aDay[yd].aEvent[e].isCancelled && (s.nDaysToCome == 1) && (this.aDay[yd].aEvent[e].sScore1==='') )
		  {
			if ( (t1_start+210) < s.this_minute )
			  {
				aHTML[aHTML.length] = '<td class="warning">warning</td><td>%0 %1 game vs %2 has no result: tell the webmaster the result.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock), this.aDay[yd].aEvent[e].oType.description(), this.aDay[yd].aEvent[e].sTeam2 );
				s.nWarnings++;
				s.nLines++;
			  }
			else if ( s.isLocalSite )
			  {
				aHTML[aHTML.length] = '<td class="note">note</td><td><strong>%0 %1 game is scheduled vs %2.</strong></td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock,'TBA'), this.aDay[yd].aEvent[e].oType.description(), this.aDay[yd].aEvent[e].sTeam2 );
				s.nNotes++;
				s.nLines++;
			  }
		  }

		if ( (t1_start > 0) && (t1_type == 'game') && (t1_start < s.nWayEarlyGameTime) )
		  {
			aHTML[aHTML.length] = '<td class="warning">warning</td><td>%0 %1 game is very early in the day: if not okay, reschedule it.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock), this.aDay[yd].aEvent[e].oType.description() );
			s.nWarnings++;
			s.nLines++;
		  }
		else if ( isWorkDay && (t1_type == 'game')  )
		  {
			if ( (t1_start > 0) && (t1_start < s.nEarlyGameTime) )
			  {
				if ( !isInRange( 6, this.aDay[yd].nMonth, 7) )
				  {
					aHTML[aHTML.length] = '<td class="alert">alert</td><td>%0 %1 game is early on %2, a work day: if not okay, reschedule it.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock), this.aDay[yd].aEvent[e].oType.description(), kal.aWeekDayName[this.aDay[yd].nWeekDay] );
					s.nAlerts++;
					s.nLines++;
				  }
				else
				  {
					aHTML[aHTML.length] = '<td class="alert">alert</td><td>%0 %1 game is early on %2, a work day: if not okay, reschedule it.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock), this.aDay[yd].aEvent[e].oType.description(), kal.aWeekDayName[this.aDay[yd].nWeekDay] );
					s.nAlerts++;
					s.nLines++;
				  }
			  }
		  }

		if ( (t1_start > 0) && (this.aDay[yd].aEvent[e].oType.t1=='P') && (t1_start < s.nWayEarlyPracticeTime) )
		  {
			aHTML[aHTML.length] = '<td class="warning">warning</td><td>%0 %1 is very early in the day: if not okay, reschedule it.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock), this.aDay[yd].aEvent[e].oType.description() );
			s.nWarnings++;
			s.nLines++;
		  }
		else if ( isWorkDay && (this.aDay[yd].aEvent[e].oType.t1=='P') )
		  {
			if ( (t1_start > 0) && (t1_start < s.nEarlyPracticeTime) )
			  {
				var sPracticeType = (this.aDay[yd].aEvent[e].sEvent.length > 0) ? (' (' + this.aDay[yd].aEvent[e].sEvent + ') ') : '';
				aHTML[aHTML.length] = '<td class="warning">warning</td><td>%0 %1%2 is early on %3, a work day: if not okay, reschedule it.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock), this.aDay[yd].aEvent[e].oType.description(), sPracticeType, kal.aWeekDayName[this.aDay[yd].nWeekDay] );
				s.nWarnings++;
				s.nLines++;
			  }
		  }

		if ( (this.aDay[yd].aEvent[e].isRegularGame || this.aDay[yd].aEvent[e].isExhibitionGame) && (t1_start == 0) && (!this.aDay[yd].aEvent[e].isCancelled) )
		  {
			var sLocnMessage = '';
			if ( ((this.aDay[yd].aEvent[e].sLocation == '') || (this.aDay[yd].aEvent[e].sLocation == 'TBA')) )
				sLocnMessage = ' or location';
			aHTML[aHTML.length] = '<td class="warning">warning</td><td>%0 game with no start time%1: tell the webmaster when the time is known.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oType.description(), sLocnMessage );
			s.nWarnings++;
			s.nLines++;
		  }
		else if ( (this.aDay[yd].aEvent[e].isRegularGame || this.aDay[yd].aEvent[e].isExhibitionGame) && (!this.aDay[yd].aEvent[e].isCancelled) && ((this.aDay[yd].aEvent[e].sLocation == '') || (this.aDay[yd].aEvent[e].sLocation == 'TBA')) )
		  {
			aHTML[aHTML.length] = '<td class="warning">warning</td><td>%0 game with no location: tell the webmaster when the location is known.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oType.description() );
			s.nWarnings++;
			s.nLines++;
		  }

		if ( (this.aDay[yd].aEvent[e].isTournamentGame) && (t1_start == 0) && (s.nDaysToCome < 10) )
		  {
			aHTML[aHTML.length] = '<td class="warning">warning</td><td>tournament game in %0 day%1 with no start time: tell the webmaster when the time is known.</td></tr>\n'.blend( s.nDaysToCome - 1, calPlural( s.nDaysToCome - 1 ) );
			s.nWarnings++;
			s.nLines++;
		  }

		if ( (this.aDay[yd].aEvent[e].oType.t1=='P') && ((this.aDay[yd].aEvent[e].sLocation == '') || (this.aDay[yd].aEvent[e].sLocation == 'TBA')) )
		  {
			aHTML[aHTML.length] = '<td class="warning">warning</td><td>%0 practice has no location: tell the webmaster when the location is known.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oType.description() );
			s.nWarnings++;
			s.nLines++;
		  }

		if ( this.aDay[yd].aEvent[e].isGame && this.aDay[yd].aEvent[e].isCancelled )
		  {
			aHTML[aHTML.length] = '<td class="warning">warning</td><td>%0 game vs %1 was cancelled: reschedule it.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock,'TBA'), this.aDay[yd].aEvent[e].sTeam2 );
			s.nWarnings++;
			s.nLines++;
		  }

		if ( isTournamentDay && this.aDay[yd].aEvent[e].isRegularGame )
		  {
			if ( this.aDay[yd].aEvent[e].oType.t4 == '!' )
			  {
				aHTML[aHTML.length] = '<td class="note">note</td><td>%0 regular game is scheduled on a tournament day: if not okay, reschedule the game.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock,'TBA') );
				s.nNotes++;
				s.nLines++;
			  }
			else
			  {
				aHTML[aHTML.length] = '<td class="warning">warning</td><td>%0 regular game is scheduled on a tournament day: if not okay, reschedule the game.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock,'TBA') );
				s.nWarnings++;
				s.nLines++;
			  }
		  }
		else if ( isSeriesDay && this.aDay[yd].aEvent[e].isRegularGame )
		  {
			if ( this.aDay[yd].aEvent[e].oType.t4 == '!' )
			  {
				aHTML[aHTML.length] = '<td class="note">note</td><td>%0 regular game is scheduled on a series day: if not okay, reschedule the game.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock,'TBA') );
				s.nNotes++;
				s.nLines++;
			  }
			else
			  {
				aHTML[aHTML.length] = '<td class="warning">warning</td><td>%0 regular game is scheduled on a series day: if not okay, reschedule the game.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock,'TBA') );
				s.nWarnings++;
				s.nLines++;
			  }
		  }

		if ( isTournamentDay && this.aDay[yd].aEvent[e].isExhibitionGame )
		  {
			if ( this.aDay[yd].aEvent[e].oType.t4 == '!' )
			  {
				aHTML[aHTML.length] = '<td class="note">note</td><td>%0 exhibition game on a tournament day: if not okay, reschedule the game.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock,'TBA') );
				s.nNotes++;
				s.nLines++;
			  }
			else
			  {
				aHTML[aHTML.length] = '<td class="warning">warning</td><td>%0 exhibition game on a tournament day: if not okay, reschedule the game.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock,'TBA') );
				s.nWarnings++;
				s.nLines++;
			  }
		  }

		if ( isSeriesBangDay )
		  {
			if ( isTournamentDay && ((t1_type == 'practice') && !isSeriesGameDay) && (this.aDay[yd].aEvent[e].oType.t0!='P!') && (s.nDaysToCome < 21) )
			  {
				aHTML[aHTML.length] = '<td class="alert">alert</td><td>%0 practice on a non-game tournament day: if the practice should be skipped, tell the webmaster.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock) );
				s.nAlerts++;
				s.nLines++;
				continue;
			  }
			else if ( isSeriesDay && ((t1_type == 'practice') && !isSeriesGameDay) && (this.aDay[yd].aEvent[e].oType.t0!='P!') && (s.nDaysToCome < 21) )
			  {
				aHTML[aHTML.length] = '<td class="alert">alert</td><td>%0 practice on a non-game series day: if the practice should be skipped, tell the webmaster.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock) );
				s.nAlerts++;
				s.nLines++;
				continue;
			  }
		  }
		else
		  {
			if ( isTournamentDay && (t1_type == 'practice') && (this.aDay[yd].aEvent[e].oType.t0!='P!') && (s.nDaysToCome < 21) )
			  {
				aHTML[aHTML.length] = '<td class="alert">alert</td><td>%0 practice on a tournament day is skipped: if the practice shouldn&rsquo;t be skipped, tell the webmaster.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock) );
				s.nAlerts++;
				s.nLines++;
				continue;
			  }
			else if ( isSeriesDay && (t1_type == 'practice') && (this.aDay[yd].aEvent[e].oType.t0!='P!') && (s.nDaysToCome < 21) )
			  {
				aHTML[aHTML.length] = '<td class="alert">alert</td><td>%0 practice on a series day is skipped: if not okay, tell the webmaster.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock) );
				s.nAlerts++;
				s.nLines++;
				continue;
			  }
		  }




		if ( isTournamentDay && ((t1_type == 'practice') && (isSeriesGameDay || !isSeriesBangDay)) && (this.aDay[yd].aEvent[e].oType.t0!='P!') && (s.nDaysToCome < 21) )
		  {
			aHTML[aHTML.length] = '<td class="alert">alert</td><td>%0 practice on a tournament day is skipped: if the practice shouldn&rsquo;t be skipped, tell the webmaster.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock) );
			s.nAlerts++;
			s.nLines++;
			continue;
		  }
		else if ( isSeriesDay && ((t1_type == 'practice') && (isSeriesGameDay || !isSeriesBangDay)) && (this.aDay[yd].aEvent[e].oType.t0!='P!') && (s.nDaysToCome < 21) )
		  {
			aHTML[aHTML.length] = '<td class="alert">alert</td><td>%0 practice on a series day is skipped: if not okay, tell the webmaster.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','\n',s.is12HourClock) );
			s.nAlerts++;
			s.nLines++;
			continue;
		  }

		if ( t1_start == 0 )
			continue;

		if ( (t1_end > 0) && (t1_end <= t1_start) )
		  {
			aHTML[aHTML.length] = '<td class="error">error</td><td>%0 %1 starts after it ends; tell the webmaster.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','-',s.is12HourClock), this.aDay[yd].aEvent[e].oType.description() );
			s.nErrors++;
			s.nLines++;
			continue;
		  }

		if ( isSeriesDay && (t1_type == 'practice') )
			continue;

		// Check for conflicts between event and following events

		for ( var e2 = e+1; e2 < this.aDay[yd].aEvent.length; ++e2 )
		  {
			switch ( this.aDay[yd].aEvent[e2].oType.t0 )
			  {
			  case	'':
					continue;
			  case	'H':
					continue;
			  case	'N':
		 	  case	'N!':
					continue;
			  case	'P':
					if ( isSeriesDay||isTournamentDay )
						continue;
					break;
			  default:
					break;
			  }
			var t2_start = this.aDay[yd].aEvent[e2].oTime.t1;
			var t2_end = this.aDay[yd].aEvent[e2].oTime.t2;
			var t2_type = this.aDay[yd].aEvent[e2].oType.eventType();
			if ( this.aDay[yd].aEvent[e2].isGame )
				t2_type = 'game';
			if ( t2_start == 0 )
				continue;
			if ( t1_start <= t2_start )
			  {
				if ( t1_end >= t2_start )
				  {
					if ( t1_end > t2_start )
					  {
						aHTML[aHTML.length] = '<td class="error">error</td><td>%0 %1%2 overlaps with %3 %4%5: if not okay, reschedule.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','-',s.is12HourClock), t1_type, calCheckLocation(this.aDay[yd].aEvent[e].sLocation), this.aDay[yd].aEvent[e2].oTime.toHTML('','-',s.is12HourClock), t2_type, calCheckLocation(this.aDay[yd].aEvent[e2].sLocation) );
						s.nErrors++;
						s.nLines++;
						continue;
					  }
					else if ( !calCheckSchedulesSimilar(this.aDay[yd].aEvent[e].sLocation,this.aDay[yd].aEvent[e2].sLocation) )
					  {
						aHTML[aHTML.length] = '<td class="warning">warning</td><td>%0 %1%2 may overlap with %3 %4%5: confirm schedule.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','-',s.is12HourClock), t1_type, calCheckLocation(this.aDay[yd].aEvent[e].sLocation), this.aDay[yd].aEvent[e2].oTime.toHTML('','-',s.is12HourClock), t2_type, calCheckLocation(this.aDay[yd].aEvent[e2].sLocation) );
						s.nWarnings++;
						s.nLines++;
						continue;
					  }
				  }
				else if ( this.aDay[yd].aEvent[e].isGame && (t1_end <= 0) )
				  {
					if ( (t1_start + s.nGameTime) > t2_start )
					  {
						aHTML[aHTML.length] = '<td class="warning">warning</td><td>%0 %1%2 may overlap with %3 %4%5: confirm schedule.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','-',s.is12HourClock), t1_type, calCheckLocation(this.aDay[yd].aEvent[e].sLocation), this.aDay[yd].aEvent[e2].oTime.toHTML('','-',s.is12HourClock), t2_type, calCheckLocation(this.aDay[yd].aEvent[e2].sLocation) );
						s.nWarnings++;
						s.nLines++;
						continue;
					  }
				  }
				else if ( (this.aDay[yd].aEvent[e].oType.t1 == 'P') && (t1_end <= 0) )
				  {
					if ( (t1_start + s.nGameTime) > t2_start )
					  {
						aHTML[aHTML.length] = '<td class="warning">warning</td><td>%0 %1%2 may overlap with %3 %4%5: confirm schedule.</td></tr>\n'.blend( this.aDay[yd].aEvent[e].oTime.toHTML('','-',s.is12HourClock), t1_type, calCheckLocation(this.aDay[yd].aEvent[e].sLocation), this.aDay[yd].aEvent[e2].oTime.toHTML('','-',s.is12HourClock), t2_type, calCheckLocation(this.aDay[yd].aEvent[e2].sLocation) );
						s.nWarnings++;
						s.nLines++;
						continue;
					  }
				  }
			  }
		  }
	  }
  }
if ( aHTML.length > 0 )
  {
	sHTML += calGetCheckHTML( sDateStamp, aHTML );
	aHTML = new Array(1);
  }
if ( sHTML.length > 0 ) 
	sHTML = '<tr><th colspan="3" class="month_header">' + kal.aMonthName[m].toUpperCase() + ' ' + y + '</th></tr>\n' + sHTML;
return sHTML;
}


