//isDate.js

//////////////////////////////////////////////////////////////////////////////
//Function:	isDate(date, bTwoYearOK)
//Input:	date as a date to be validated. fields seperated by a '/', valid dates are in the
//		format mm/dd/yyyy
//Returns:	true if valid date else false
//Output:	N/A
//Author:	Brien Hodges
//////////////////////////////////////////////////////////////////////////////
function isDate(date, bTwoYearOK, EarliestYear)
{
var inputDate;
var month;
var day;
var year;
var testDate;
var err;
var delimiter;

	err = 0;
	
	if (!EarliestYear)
		EarliestYear = 1000;
	
	//find out what is the delimiter for the date string
	if (date.indexOf('/') != -1)
	{
		delimiter = '/';
	}
	else if (date.indexOf('-') != -1)
	{
		delimiter = '-';
	}
	else if (date.indexOf('.') != -1)
	{
		delimiter = '.'
	}
	else
	{
		err = 1;
	}
	
	inputDate = date.split(delimiter);
	month = inputDate[0] -1; // month is 0 based
	day =  inputDate[1]; // day
	year = inputDate[2]; // year

	if (bTwoYearOK && year != '')
	{
		if (year < 100)
			if (year > 50)
				year = 1900 + year;
			else
				year = 2000 + year;
	}

	//since you can have dates that are less than 4 digits we want to make sure
	//that the date is at least 1000
	if (year < EarliestYear)
	{err = 1};

	//create a new date object
	testDate = new Date(year,month,day);

	//check to make sure that the date created is the same as the date
	//which was input.  if they match then its a real date.
	if (month != parseInt(testDate.getMonth()))
	{
		err = 1;
	}
	if (day != parseInt(testDate.getDate()))
	{
		err = 1;
	}
	if (year != parseInt(testDate.getFullYear()))
	{
		err = 1;
	}	
	if (err == 1)
	{
		return false;
	}
	return true;
}