yearLengths = new Array (0,354,384,354,355,384,354,384,354,355,384,354,354,384,355,354,384,354,384,355);
monthLengths = new Array (0,30,29,30,29,30,29,30,29,30,29,30,29,30);
monthNames = new Array ("", "Samhain", "Dumhainn", "Ri&ugrave;r", "Naghaid", "Uarain", "Cuithe", "Geamhain", "Si&ugrave;fainn", "Eacha", "Eilm&igrave;", "Aodhrain", "Cadal", "Eadr&agrave;n");
dayNames = new Array ("Di D&ograve;mhnaich", "Di Luain", "Di M&agrave;irt", "Di Ciadain", "Di Ardaoin", "Di hAoine", "Di Sathairne"); 

epoch = new Date(1999,10,9,2);
daysSinceEpoch = 0;
yearCount = 1;
yearNum = 3099;
cycleCount = 164;
yearLength = 0;
dayCount = 0;
testDate = new Date();
testDate.setHours(2);
yearStartDateValue = Date.parse(epoch);
newDate = new Date();
yearStartDate = new Date();
dayOfWeek = testDate.getDay();
celtMonthStartDay = 6;

monthCount = 0;
monthNum = 0;
monthStartDate = new Date();
monthStartDateValue = Date.parse(yearStartDate);

setCeltYear();
setCeltMonth();

function setCeltYear()
{
	this.daysSinceEpoch = Math.floor(testDate.valueOf()/864e5) - Math.floor(epoch.valueOf()/864e5);
	i = 1;
	dayCount = yearLengths[i];
	yearLength = yearLengths[i];
	while (daysSinceEpoch >= dayCount)
	{
		yearCount++;
		yearNum++;
		if (yearCount > 19)
		{
			yearCount = 1;
			cycleCount++;
		}
		i = yearCount;
		yearStartDateValue += (yearLength*24*60*60*1000);
		yearStartDate = new Date(yearStartDateValue);
		yearLength = yearLengths[i];
		if ((yearCount == 19) && (cycleCount % 3 == 0)) { yearLength = 354; }
		if ((yearCount == 19) && (cycleCount % 45 == 0 )) { yearLength = 355; }
		dayCount += yearLength;
	}
}

function setCeltMonth()
{
	monthsInYear = 12;
	if ((yearCount == 4) || (yearCount == 9) || (yearCount == 14) || (yearCount == 19)) 
	{ 
		monthLengths[6] = 30; 
	}
	if ((cycleCount % 3 == 0) && (yearCount == 19)) { monthLengths[6] = 29; }
	if ((cycleCount % 45 == 0) && (yearCount == 19)) { monthLengths[6] = 30; }
	if ((yearCount == 2) || (yearCount == 5) || (yearCount == 7) || (yearCount == 10) || (yearCount == 13) || (yearCount == 16) || (yearCount == 18))
	{
		monthsInYear = 13;
	}
	dayCount = monthLengths[1]
	monthCount = 1;
	i = 1;
	daysSinceYearStart = Math.floor(testDate.valueOf()/864e5) - Math.floor(yearStartDate.valueOf()/864e5) + 1;
	dayNum = daysSinceYearStart;
	monthStartDateValue = Date.parse(yearStartDate);
	while (daysSinceYearStart > dayCount)
	{
		monthCount++;
		monthStartDateValue += (monthLengths[i]*24*60*60*1000);
		monthStartDate = new Date(monthStartDateValue);
		celtMonthStartDay = monthStartDate.getDay();
		i++;
		dayCount += monthLengths[i];
		dayNum = Math.floor(testDate.valueOf()/864e5) - Math.floor(monthStartDate.valueOf()/864e5) + 1;
	}
}

function getCeltDayName()
{
	getCeltDayName = dayNames[dayOfWeek];
	return getCeltDayName;
}

function getCeltDate()
{
	getCeltDate = dayNum;
	return getCeltDate;
}

function getCeltMonthName()
{
	getCeltMonthName = monthNames[monthCount];
	return getCeltMonthName;
}

function getCeltMonthName1()
{
	getCeltMonthName1 = monthNames[monthCount];
	return getCeltMonthName1;
}

function getCeltMonthLength()
{
	getCeltMonthLength = monthLengths[monthCount];
	return getCeltMonthLength;
}

function getCeltYear()
{
	getCeltYear = yearNum;
	return getCeltYear;
}

function getCeltFullDate()
{
	getCeltFullDate = dayNames[dayOfWeek] + ', ' + dayNum + ' ' + monthNames[monthCount];
	return getCeltFullDate;
}

function getCeltCount()
{
	getCeltCount = cycleCount + '&middot;' + yearCount + '&middot;' + monthCount + '&middot;' + dayNum;
	return getCeltCount;
}

function getCeltCount1()
{
	getCeltCount = cycleCount + '&middot;' + yearCount + '&middot;' + monthCount + '&middot;' + dayNum;
	return getCeltCount;
}

function getCeltYearCount()
{
	getCeltYearCount = yearCount;
	return getCeltYearCount;
}

function testOutput()
{
	testOutput = cycleCount + '&middot;' + yearCount + '&middot;' + monthCount + '&middot;' + dayNum + ' ' + monthNames[monthCount] + ' ' + yearNum + ' ' + dayNames[dayOfWeek] + ' (' + yearStartDate.toDateString() + ', ' + monthStartDate.toDateString() + ', ' + testDate.toDateString() + ')';
	return testOutput;
}

