//---------------------------------------------------------------------
// Form Validation Functions
//
// All functions require a string value that is to be tested and
//  return true if valid, false otherwise
//
// Functions:
// 	isValidEmail(STRING emailAddress)
//	isValidDate_MMDDYYYY(STRING date)
//	isValidURL(STRING url)
//
// Modifications:
//   06/04/02 Ed Lucas     Created
//	
//---------------------------------------------------------------------

// isValidEmail(STRING emailAddress)
// returns true if string argument emailAddress forms a valid email address
function isValidEmail(emailAddress) {
	var rx
	
	rx = new RegExp("^ *[-a-zA-Z0-9\\_\\.\\-]+@[-a-zA-Z0-9\\_\\.\\-]+\\.[a-zA-Z]{2,3}?$");
	if (rx.exec(emailAddress) == null) {
		return false;
	} else {
		return true;
	}
}


// daysInFebruary(INTEGER year)
// Given integer argument year, returns number of days in February of that year.
// Written by Eric Krock, Netscape Communications Corporation
function daysInFebruary(year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}


// isValidDate_MMDDYYYY(STRING date)
// returns true if string argument date forms a valid date
function isValidDate_MMDDYYYY(date)
{
	var daysInMonth = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
	var dateArray = new Array();
	var rx
	
	//check for basic format, especially that we have 3 slashes
	rx = new RegExp("^[0-1]?[0-9]/[0-3]?[0-9]/[0-9]{4}$");
	if (rx.exec(date) == null) return false;

	//split into parts
	dateArray = date.split("/");
	if (!(dateArray.length = 3)) return false;
	
  var intMonth = dateArray[0];
  var intDay = dateArray[1];
  var intYear = dateArray[2];

	//check for valid values
  if (!(intYear >= 1000 && intYear <= 9999) || !(intMonth >= 1 && intMonth <= 12) || !(intDay >= 1 && intDay <= 31)) return false;

  //catch invalid days, except for February
  if (intDay > daysInMonth[intMonth - 1]) return false; 

	//test days in February
  if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

  return true;
}


// isValidURL(STRING url)
// returns true if string argument does not start with "http" or "ftp:"
function isValidURL(url) {
	if ((url.substr(0,4) == "http") || (url.substr(0,4) == "ftp:")) {
		return false;
	} else {
		return true;
	}
}

