
// Begin EditDate.js
// Created by:  Steve Seaquist
//
function EditDate			(pFNam, pFVal, pReqd)
{

if  (gDataValidation == 0)
	return true;

var  sFLen	= pFVal.length;
if ((sFLen == 0) && (pReqd == 0))
	return true;

var e;
var mm;
var dd;
var yyyy;

if  (!EditMask (pFNam, pFVal, "99/99/9999", 1, 8, 10))
    return false;

mm		= pFVal.substring(0,2);
dd		= pFVal.substring(3,5);
e		= "ERROR.  " + pFNam + " must be of the form 'MM/DD/YY' or 'MM/DD/YYYY'.\n";

if  (sFLen == 8)
    { // The SBA infers century based on the year that the SBA came into existence:
    var yy	= pFVal.substring(6,8);
    if  (yy > 52)
	yyyy	= 1900 + yy;
    else
	yyyy	= 2000 + yy;
    }
else if (sFLen == 10)
    yyyy	= pFVal.substring(6,10);
else
    {
    alert (e + "'MM/DD/YYY' is not allowed.");
    return false;
    }

if      ((mm < 1) || (mm > 12))
	{
	alert (e + "'MM' must be in the range of 01-12.");
	return false;
	}
else if (((mm == 1) || (mm == 3) || (mm == 5) || (mm == 7) || (mm == 8) || (mm == 10) || (mm == 12)) 
	&& ((dd < 1) || (dd > 31)))
	{
	alert (e + "For this month, 'DD' must be in the range of 01-31.");
	return false;
	}
else if (((mm == 4) || (mm == 6) || (mm == 9) || (mm == 11)) 
	&& ((dd < 1) || (dd > 30)))
	{
	alert (e + "For this month, 'DD' must be in the range of 01-30.");
	return false;
	}
else if (mm == 2)
	{
	if  ((yyyy % 400 == 0) || ((yyyy % 100 > 0) && (yyyy % 4 == 0)))
	    {
	    if	((dd < 1) || (dd > 29))
		{
		alert (e + "For this year, 'DD' must be in the range of 01-29.");
		return false;
		}
	    }
	else
	    {
	    if  ((dd < 1) || (dd > 28))
		{
		alert (e + "For this year, 'DD' must be in the range of 01-28.");
		return false;
		}
	    }
	}

return true;
}
// End EditDate.js


