/////////////////////////////////////////////////////////////////////////////
// Written by Rob Tietje for PTAC SDCOC.
// (c) Copyright SDCOC.  All rights Reserved.
/////////////////////////////////////////////////////////////////////////////

function MyDate(dateStr)
{
	// see if the date is formatted correctly
    var dateFilter = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;

	this.formatted = true;
    if (!dateFilter.test(dateStr))
	{
		this.formatted = false;

		return;
	}

	// set up class variables and daysPerMonth
	var dateArr = dateStr.split('-');

	this.year = Number(dateArr[0]);
	this.month = Number(dateArr[1]);
	this.day = Number(dateArr[2]);

	this.daysPerMonth = Array(31,28,31,30,31,30,31,31,30,31,30,31);

	this.IsLeapYear = function()
	{
		if (this.year % 4 == 0)
		{
			if (this.year % 400 == 0)
				return true;
			else if (this.year % 100 == 0)
				return false;

			return true;
		}

		return false;
	}

	if (this.IsLeapYear())
		this.daysPerMonth[1] += 1;

	this.Valid = function()
	{
		return this.month >= 1 && this.month <= 12 &&
			this.day >= 1 && this.day <= this.daysPerMonth[this.month - 1];
	}

	this.LessThan = function(year, month, day)
	{
		if (this.year == year)
		{
			if (this.month == month)
				return this.day < day;
			else
				return this.month < month;
		}
		else
			return this.year < year;
	}

	this.GreaterThan = function(year, month, day)
	{
		if (this.year == year)
		{
			if (this.month == month)
				return this.day > day;
			else
				return this.month > month;
		}
		else
			return this.year > year;
	}
}
