//#####################################################
// Services Functions
//#####################################################
	
// Services Variables

	var seasonSortMode = 'Date';
	var nbrSeasons = -1;
	var homeSeason = -1;
	var nbrSeasonLines = -1;
	var seasonDefaultImage = '';

	var season = new Array();
	var seasonImageHome = new Array();
	var seasonImageMain = new Array();
	var seasonBgColour = new Array();
	var seasonTxtColour = new Array();
	var seasonTxtSize = new Array();
	var seasonBorderColour = new Array();
	var seasonLineName = new Array();
	var seasonLineDate = new Array();
	var seasonLineTime = new Array();
	var seasonLineDayDesc = new Array();
	var seasonLineService = new Array();
	var seasonLineLocation = new Array();
	var seasonLineDateCtl = new Array();
	var seasonLineLocCtl = new Array();

	var thisYearC = '';
	var thisDateC = '';
	var thisDayN = '';
	var thisMonthN = '';

//------------------------------------------------------------------------------------------------------------
//- SEASONAL FUNCTIONS ---------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
function setSeasonSortMode(vMode)
{
	seasonSortMode = vMode;
}
//------------------------------------------------------------------------------------------------------------
function setSeasonDefaultImage(vImage)
{
	seasonDefaultImage = vImage;
}
//------------------------------------------------------------------------------------------------------------
function getSeason()
{
	return season;
}
//------------------------------------------------------------------------------------------------------------
function getHomeSeason()
{
	return homeSeason;
}
//------------------------------------------------------------------------------------------------------------
function getSeasonNbr(vChkSeason)
{
	var returnNbr = "9999";
	for (var i = 0; i <= nbrSeasons; i++) {
		if (vChkSeason == season[i]) {
			if (i >= 1000) {
				returnNbr = i;
			} else if (i >= 100) {
				returnNbr = '0' + i;
			} else if (i >= 10) {
				returnNbr = '00' + i;
			} else {
				returnNbr = '000' + i;
			}
			i = nbrSeasons + 1;
		}
	}
	return returnNbr;
}
//------------------------------------------------------------------------------------------------------------
function addSeason(vSeason, vHomeSeason, vFromDate, vToDate, vBgColour, vImageHome, vImageMain, vTxtColour, vTxtSize, vBorderColour)
{

	if (isTodayInRange(vFromDate, vToDate) > 0) {
		nbrSeasons += 1;
		if (homeSeason <= -1) {
			if (vHomeSeason == 'yes') {
				homeSeason = nbrSeasons;
			}
		}
		season[nbrSeasons] = vSeason;
		seasonImageHome[nbrSeasons] = vImageHome;
		seasonImageMain[nbrSeasons] = vImageMain;
		seasonBgColour[nbrSeasons] = vBgColour;
		if (vTxtColour == null) {
			seasonTxtColour[nbrSeasons] = "white";
		}
		else {
			seasonTxtColour[nbrSeasons] = vTxtColour;
		}
		if (vTxtSize == null) {
			seasonTxtSize[nbrSeasons] = "24";
		}
		else {
			seasonTxtSize[nbrSeasons] = vTxtSize;
		}
		if (vTxtSize == null) {
			seasonBorderColour[nbrSeasons] = "white";
		}
		else {
			seasonBorderColour[nbrSeasons] = vBorderColour;
		}
	}
	
}
//------------------------------------------------------------------------------------------------------------
function addSeasonLine(vSeason, vDate, vTime, vDayDesc, vService, vLocation)
{
	var thisSeasonNbr = "";
	
// Get Season Number for the Specified Season
// Only Proceed if not "9999"

	thisSeasonNbr = getSeasonNbr(vSeason);

	if (thisSeasonNbr != "9999") {
	
		nbrSeasonLines += 1;
		seasonLineName[nbrSeasonLines] = vSeason;
		seasonLineDate[nbrSeasonLines] = vDate;
		seasonLineTime[nbrSeasonLines] = vTime;
		seasonLineDayDesc[nbrSeasonLines] = vDayDesc;
		seasonLineService[nbrSeasonLines] = vService;
		seasonLineLocation[nbrSeasonLines] = vLocation;
	
// Change Time to 24 hours for sort purposes
		var separator = vTime.indexOf(':');
		var am = vTime.indexOf('am');
		var pm = vTime.indexOf('pm');
		var time24 = '';
		if (separator >= 0) {
			time24 = vTime.substring(0,separator);
			if (pm >= 0) {
				time24 = Number(time24)+12;
			} else if (time24 <= 9) {
				time24 = '0'+time24;
			}
			time24 += vTime.substring(separator+1,vTime.length);
		} else if (am > 0) {
			time24 = vTime.substring(0,am)+'00';
			if (time24 <= 9) {
				time24 = '0'+time24;
			}
		} else if (pm > 0) {
			time24 = Number(vTime.substring(0,pm))+12
			time24 += '00'
		}	
		
// Set Sort Control
		if (seasonSortMode == 'Date') {
			seasonLineDateCtl[nbrSeasonLines] = thisSeasonNbr+vDate+time24+'@'+nbrSeasonLines;
		}
		else {
			seasonLineLocCtl[nbrSeasonLines] = thisSeasonNbr+vLocation+vDate+time24+'@'+nbrSeasonLines;
		}
		
	}
	
}
//------------------------------------------------------------------------------------------------------------
function writeSeasonHome()
{
	var htmlString = '';
	
	if (homeSeason > -1) {
		if (season[homeSeason] != '') {
			htmlString = '<table ';
			if (seasonBgColour[homeSeason] != '') {
				htmlString += ' bgcolor="'+seasonBgColour[homeSeason]+'"';
			}
			htmlString += ' cellspacing="1" cellpadding="3" border="0"><tbody>';
			if (seasonImageHome[homeSeason] != '') {
				htmlString += '<TR align="center" valign="top"><TD><A href="Parish/seasonalloc.html"><IMG border="0" src="'+seasonImageHome[homeSeason]+'"></A></TD></TR>';
			}
			htmlString += '<TR align="center" valign="top"><TD class="seasonal-name"><A href="Parish/seasonalloc.html"><SPAN style="color: '+seasonTxtColour[homeSeason]+'; font-size: '+seasonTxtSize[homeSeason]+'pt">&nbsp;&nbsp;'+season[homeSeason]+'&nbsp;&nbsp;</SPAN><TD></TR>';
			htmlString += '<TR align="center" valign="top"><TD class="seasonal-text"><A href="Parish/seasonalloc.html"><SPAN style="color: '+seasonTxtColour[homeSeason]+'">Services</SPAN></A></TD></TR>';
			htmlString += '</tbody></table>';
		}
		else {
			htmlString = '<IMG border="0" src="'+seasonDefaultImage+'">';
			htmlString += ' ' + season
		}
	}
	else {
		htmlString = '<IMG border="0" src="'+seasonDefaultImage+'">';
		htmlString += ' ' + season
	}
	document.write(htmlString);
		
}

//------------------------------------------------------------------------------------------------------------
function writeSeasonMain()
{
	var previousSeason = "";
	var thisSeason = "";
	var activeTable = 0;
	var nbrOutput = 0;
	var prevControl = '';
	var curIndex = -1;
	var curControl = '';
	var htmlString = '';
	
// Sort According to mode
	if (seasonSortMode == 'Date') {
		seasonLineDateCtl.sort();
	} else {
		seasonLineLocCtl.sort();
	}

// Process Lines

	for (var i = 0; i <= nbrSeasonLines; i++) {
				
	// Check Season

		if (seasonSortMode == 'Date') {
			separator = seasonLineDateCtl[i].indexOf('@');
			curIndex = seasonLineDateCtl[i].substring(separator+1,seasonLineDateCtl[i].length);
			thisSeason = seasonLineDateCtl[i].substring(0,4);
		} else {
			separator = seasonLineLocCtl[i].indexOf('@');
			curIndex = seasonLineLocCtl[i].substring(separator+1,seasonLineLocCtl[i].length);
			thisSeason = seasonLineLocCtl[i].substring(0,4);
		}
				
		// Start New Season

		if (thisSeason != previousSeason) {
			previousSeason = thisSeason;
								
			if (activeTable = 1) {
				htmlString = '</tbody></table><BR>';
				htmlString += '<table width="'+getPageWidth()+'" ><tbody><tr><hr></td></tr></tbody</table><BR>'		
				document.write(htmlString);
				activeTable = 0;
			}
		
			if (thisSeason != "9999") {
				activeTable = 1;
				
				htmlString = '<table width="'+getPageWidth()+'"border="0"><tbody><TR>';
				htmlString += '<TD valign="top" align="left" width="50%" class="page-title">'+seasonLineName[curIndex]+' Services</TD>';
		
				if (seasonSortMode == 'Date') {
					htmlString += '<TD align="right" width="30%"><A href="seasonalloc.html">Sort by Location</A></TD>';
				} else {
					htmlString += '<TD align="right" width="30%"><A href="seasonaldate.html">Sort by Date</A></TD>';
				}
				if (seasonImageMain[i] != '') {
					htmlString += '<TD align="right"><IMG border="0" src="../images/'+seasonImageMain[parseInt(thisSeason)]+'"></TD></TR>';
				} else {
					htmlString += '<TD align="right">&nbsp;</TD>';
				}
				htmlString += '</TR></tbody></table>';
				document.write(htmlString);
				
				htmlString = '<BR><table width="'+getPageWidth()+'" cellspacing="2" cellpadding="5" border="0"><tbody>';
				document.write(htmlString);
		
			}
		}
			
		// If New Date/Location - Header Row
		
		if (thisSeason != "9999") {

			var separator = '';
			if (seasonSortMode == 'Date') {
				if (seasonLineDate[curIndex] != prevControl) {
					thisYearC = extractDate(seasonLineDate[curIndex], 'year', 'chr');
					thisDateC = extractDate(seasonLineDate[curIndex], 'date', 'chr');
					thisDayN = extractDate(seasonLineDate[curIndex], 'day', 'nbr');
					thisMonthN = extractDate(seasonLineDate[curIndex], 'month', 'nbr');
					htmlString = '<TR valign="top">';
					if (seasonLineDayDesc[curIndex] != '') {
						htmlString += '<TD colspan="2" class="seasonal-daydesc">'+seasonLineDayDesc[curIndex]+'</TD>';
						htmlString += '<TD colspan="3" class="seasonal-date">'+getDayOfWeek(thisDayN-1,"short")+'&nbsp;&nbsp;&nbsp;&nbsp;'+thisDateC+' '+getShortMonth(thisMonthN-1) + ' '+thisYearC+'</TD>';
					} else {
						htmlString += '<TD colspan="5" class="seasonal-date">'+getDayOfWeek(thisDayN-1,"short")+'&nbsp;&nbsp;&nbsp;&nbsp;'+thisDateC+' '+getShortMonth(thisMonthN-1) + ' '+thisYearC+'</TD>';
					}
					htmlString += '</TR>';
					document.write(htmlString);
				}
				prevControl = seasonLineDate[curIndex];
			} else {
				if (seasonLineLocation[curIndex] != prevControl) {
					htmlString = '<TR valign="top">';
					htmlString += '<TD colspan="5" class="seasonal-location-header">'+seasonLineLocation[curIndex]+'</TD>';
					htmlString += '</TR>';
					document.write(htmlString);
				}
				prevControl = seasonLineLocation[curIndex];
			}
			
// Output Line

			nbrOutput += 1
			htmlString = '<TR valign="top">';
			if (seasonSortMode == 'Date') {
				htmlString += '<TD>&nbsp;</TD>';
				htmlString += '<TD align="right" class="seasonal-time">'+seasonLineTime[curIndex]+'</TD>';
				htmlString += '<TD>&nbsp;</TD>';
				htmlString += '<TD class="seasonal-service">'+seasonLineService[curIndex]+'</TD>';
				htmlString += '<TD class="seasonal-location">'+seasonLineLocation[curIndex]+'</TD>';
			} else {
				thisYearC = extractDate(seasonLineDate[curIndex], 'year', 'chr');
				thisDateC = extractDate(seasonLineDate[curIndex], 'date', 'chr');
				thisDayN = extractDate(seasonLineDate[curIndex], 'day', 'nbr');
				thisMonthN = extractDate(seasonLineDate[curIndex], 'month', 'nbr');
				htmlString += '<TD>&nbsp;</TD>';
				htmlString += '<TD class="seasonal-day">'+getDayOfWeek(thisDayN-1,"short")+'</TD>';
				htmlString += '<TD class="seasonal-date" width="85">'+thisDateC+' '+getShortMonth(thisMonthN-1) + ' '+thisYearC+'</TD>';
				htmlString += '<TD class="seasonal-time">'+seasonLineTime[curIndex]+'</TD>';
				htmlString += '<TD class="seasonal-service">'+seasonLineService[curIndex]+'</TD>';
				if (seasonLineDayDesc[curIndex] != '') {
					htmlString += '<TD class="seasonal-daydesc">'+seasonLineDayDesc[curIndex]+'</TD>';
				} else {
					htmlString += '<TD>&nbsp;</TD>';
				}
			}
			htmlString += '</TR>';
			document.write(htmlString);
		}
	}

	if (activeTable = 1) {
		htmlString = '</tbody></table><BR>';
		document.write(htmlString);
	}

	if (nbrOutput <= 0) {
		htmlString = '<BR>No Seasonal services have been scheduled at present. <BR><BR>The list of current scheduled services can be seen <A href="../Parish/services.html">here</A>.<BR>';
		document.write(htmlString);
	}

}

//------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
