//checkDate:
//Checks to make sure that the date is in mm/dd/yyyy format in 
//a text field in a form.  
//
//NOTE: There is NO RANGE CHECKING for the year. Users can legitimately enter
//      0001 for the date. Modify the reqular expression if you need to limit
//      the year. There is a modicum of range checking for the month and date.
//
//You'll need to add:
//
// <SCRIPT LANGUAGE="JavaScript" SRC="/apps/library/dateFunctions.js"></SCRIPT>
//
// to the <Head> portion of your file (Make sure the library directory path is
// correct.  You'l also need to add:
//
// onchange="checkDate(this);" 
//
// to the <INPUT> tag in your form. Make sure that you deal with the double quotes
// correctly. 
//
// TO-DOS:
//         The .focus() call does not work as I want.
//
//  -John Lutz 2001-08-09
//
function checkDate(theField)
{
  var dateReg = /^[0-1]\d\/[0-3]\d\/\d\d\d\d$/;
  if (! dateReg.exec(theField.value))
  {
    var alertStr = 'The date must be in mm/dd/yyyy format.';
    alert(alertStr);
    theField.focus();
    return false;
  }
  return true;
}

function dayMath(theField, intDays)
{
	if ( theField.value == '' ) {
       		theField.value = new Date();
       	}
       	
	var theDate = new Date();
	theDate.setTime(Date.parse(theField.value));
	var secs   = theDate.getTime();
	var offset = intDays * 1000 * 60 * 60 * 24;
	theDate.setTime(secs + offset);
	
	var theMonth = theDate.getMonth()+1; //Jan = 0
	if (theMonth < 10)
	{
		theMonth = "0" +theMonth
	}
	var dateNum  = theDate.getDate();
	if (dateNum < 10)
	{
		dateNum = "0" +dateNum
	}
	var theYear  = theDate.getFullYear();


 	theField.value = theMonth+ "/" +dateNum+ "/" +theYear;
	
	return true;
}
