<!--
/*
---------1---------2---------3---------4---------5---------6---------7---------8
12345678901234567890123456789012345678901234567890123456789012345678901234567890
*/
/*
**********************************************************************
Syntax:		isProperDate(<Date>)

Purpose:	Generic Date validation routine

Inputs:		vString	--	String to be written out

Outputs:	Writes out specified string followed by a newline character

Notes:		This function expects the date to be in one of the 
			following formats:
				+ mm/dd/yyyy
				+ mm/dd/yy
				+ mm-dd-yyyy or 
				+ mm-dd-yy
**********************************************************************
*/

function isProperDate(vDate) {
	var tmpDay = getDay(vDate)
//	alert(tmpDay)

	var tmpMon = getMonth(vDate)
//	alert(tmpMon)

	var tmpYear = getYear(vDate)
//	alert(tmpYear)

//	alert(isProperDay(tmpDay, tmpMon, tmpYear))
//	alert(isProperMonth(tmpMon))
//	alert(isProperYear(tmpYear))

	return isProperDay(tmpDay, tmpMon, tmpYear) && isProperMonth(tmpMon) && isProperYear(tmpYear)

}

/* 
-----------------------------------------------------------
	Supporting functions for isProperDate()
-----------------------------------------------------------
*/
/*
**********************************************************************
Syntax:		isWhiteSpace(<WhiteSpace>)

Purpose:	Check whether the given argument consists of charactes other 
			than a space and \t

Inputs:		vWhiteSpace	--	String to be checked

Outputs:	boolean true or false
**********************************************************************
*/

function isWhiteSpace(vWhiteSpace) {
	argWs = vWhiteSpace.toString()
		
	for (var intI=0; intI < argWs.length; intI++)
		if (argWs.charAt(intI) != ' ' && argWs.charAt(intI) != '\t')
			return false
		
	return true
}

/*
**********************************************************************
Syntax:		isLeapYear(<Year>)

Purpose:	Checks passed string to see if it is a leap year or not

Inputs:		vWhiteSpace	--	String to be checked

Outputs:	Writes out specified string followed by a newline character
**********************************************************************
*/

function isLeapYear(vYear) {
	return ((vYear % 4 == 0) && (vYear % 100 != 0)) || (vYear % 400 == 0) 
}

/*
**********************************************************************
Syntax:		daysInMonth(<Month>, <Year>)

Purpose:	Determines the Number of days that a month contains based 
			on the month and year specified

Inputs:		vMonth	--	Month to CheckString to be checked
			vYear	--	String to be checked

Outputs:	returns the number of days in the month

**********************************************************************
*/

function daysInMonth(vMonth, vYear) {
	switch (Number(vMonth)) {
		case 1:				// Jan
		case 3:				// Mar
		case 5:				// May
		case 7:				// Jul
		case 8:				// Aug
		case 10:			// Oct
		case 12:			// Dec
			return 31;
			break;
			
		case 4:				// Apr
		case 6:				// Jun
		case 9:				// Sep
		case 11:			// Nov
			return 30;
			break;
			
		case 2:				// Feb
			if (isLeapYear(vYear))
				return 29
			else
				return 28
			break;
			
		default:
			return 0;
	}
}

/*
**********************************************************************
Syntax:		getDateSeparator(<Date>)

Purpose:	Function to return the date separator

Inputs:		vDate	--	Date string to be evaluated

Outputs:	returns the date separator

Notes:		This function expects the date to be in one of the 
			following formats:
				+ mm/dd/yyyy
				+ mm/dd/yy
				+ mm-dd-yyyy or 
				+ mm-dd-yy

**********************************************************************
*/

function getDateSeparator(vDate) {
	// Are there invalid separators?
	if ((vDate.indexOf('-') > 0) && (vDate.indexOf('/') > 0))
		return ' '

	if (vDate.indexOf('-') > 0)
		return '-'
	else
		if (vDate.indexOf('/') > 0)
			return '/'
		else
			return ' '
}

/*
**********************************************************************
Syntax:		getYear(<Date>)

Purpose:	Function to return the year portion of a date

Inputs:		vDate	--	Date string to be evaluated

Outputs:	returns the year portion of a date

Notes:		This function expects the date to be in one of the 
			following formats:
				+ mm/dd/yyyy
				+ mm/dd/yy
				+ mm-dd-yyyy or 
				+ mm-dd-yy

**********************************************************************
*/

function getYear(vDate) {
	var dateSep = getDateSeparator(vDate)
		
	if (dateSep == ' ')
		return 0

	if(vDate.split(dateSep).length == 3)
		return vDate.split(dateSep)[2]
	else
		return 0
}

/*
**********************************************************************
Syntax:		getMonth(<Date>)

Purpose:	Function to return the month portion of a date

Inputs:		vDate	--	Date string to be evaluated

Outputs:	returns the month portion of a date

Notes:		This function expects the date to be in one of the 
			following formats:
				+ mm/dd/yyyy
				+ mm/dd/yy
				+ mm-dd-yyyy or 
				+ mm-dd-yy
**********************************************************************
*/

function getMonth(vDate) {
	var dateSep = getDateSeparator(vDate)
		
	if (dateSep == ' ')
		return 0

	if(vDate.split(dateSep).length == 3)
		return vDate.split(dateSep)[0]
	else
		return 0
}

/*
**********************************************************************
Syntax:		getDay(<Date>)

Purpose:	Function to return the day portion of a date

Inputs:		vDate	--	Date string to be evaluated

Outputs:	returns the day portion of a date

Notes:		This function expects the date to be in one of the 
			following formats:
				+ mm/dd/yyyy
				+ mm/dd/yy
				+ mm-dd-yyyy or 
				+ mm-dd-yy
**********************************************************************
*/

function getDay(vDate) {
	var dateSep = getDateSeparator(vDate)
		
	if (dateSep == ' ')
		return 0

	if(vDate.split(dateSep).length == 3)
		return vDate.split(dateSep)[1]
	else
		return 0
}

/*
**********************************************************************
Syntax:		isProperDay(<Day>, <Month>, <Year>)

Purpose:	Function to tell whether the given day is valid

Inputs:		vDate	--	Date string to be evaluated

Outputs:	boolean TRUE or FALSE
**********************************************************************
*/

function isProperDay(vDay, vMonth, vYear) {
	if ((isWhiteSpace(vDay)) || (vDay == 0))
		return false

	if ((vDay > 0) && (vDay < daysInMonth(vMonth, vYear) + 1))
		return true
	else 
		return false
}

/*
**********************************************************************
Syntax:		isProperMonth(<Month>)

Purpose:	Function to tell whether the given month is valid 

Inputs:		vDate	--	Date string to be evaluated

Outputs:	boolean TRUE or FALSE
**********************************************************************
*/

function isProperMonth(vMonth) {
	if ((isWhiteSpace(vMonth)) || (vMonth == 0))
		return false
		
	if ((vMonth > 0) && (vMonth < 13))
		return true
	else
		return false
}

/*
**********************************************************************
Syntax:		isProperYear(<Year>)

Purpose:	Function to tell whether the given Year is valid 

Inputs:		vDate	--	Date string to be evaluated

Outputs:	boolean TRUE or FALSE
**********************************************************************
*/

function isProperYear(vYear) {
	if ((isWhiteSpace(vYear)) || (vYear.toString().length > 4) || (vYear.toString().length == 3))
		return false
		
	switch (vYear.toString().length) {
		case 1:
			if (vYear >=0 && vYear < 10)
				return true
			else
				return false
				
		case 2:
			if (vYear >=0 && vYear < 100)
				return true
			else
				return false
				
		case 4:
			if (((vYear >=1900) || (vYear >=2000)) && ((vYear < 3000) || (vYear < 2000)))
				return true
			else
				return false
			
		default:
			return false
	}
}
// -->
