// TAKEN FROM http://developer.netscape.com/docs/examples/javascript/formval/overview.html


// BASIC DATA VALIDATION FUNCTIONS:
// Many of the below functions take an optional parameter eok (for "emptyOK")
// which determines whether the empty string will return true or false.
// Default behavior is controlled by global variable defaultEmptyOK.
//
// isWhitespace (s)                    Check whether string s is empty or whitespace.
// isLetter (c)                        Check whether character c is an English letter 
// isDigit (c)                         Check whether character c is a digit 
// isLetterOrDigit (c)                 Check whether character c is a letter or digit.
// isInteger (s [,eok])                True if all characters in string s are numbers.
// isSignedInteger (s [,eok])          True if all characters in string s are numbers; leading + or - allowed.
// isPositiveInteger (s [,eok])        True if string s is an integer > 0.
// isNonnegativeInteger (s [,eok])     True if string s is an integer >= 0.
// isNegativeInteger (s [,eok])        True if s is an integer < 0.
// isNonpositiveInteger (s [,eok])     True if s is an integer <= 0.
// isFloat (s [,eok])                  True if string s is an unsigned floating point (real) number. (Integers also OK.)
// isSignedFloat (s [,eok])            True if string s is a floating point number; leading + or - allowed. (Integers also OK.)
// isAlphabetic (s [,eok])             True if string s is English letters 
// isAlphanumeric (s [,eok])           True if string s is English letters and numbers only.
// 
// isInternationalPhoneNumber (s [,eok]) True if string s is a valid international phone number.
// isEmail (emailStr [,eOK])				 	 Check that the string emailStr is a valid Email.
// isYear (s [,eok])                   True if string s is a valid Year number.
// isIntegerInRange (s, a, b [,eok])   True if string s is an integer between a and b, inclusive.
// isMonth (s [,eok])                  True if string s is a valid month between 1 and 12.
// isDay (s [,eok])                    True if string s is a valid day between 1 and 31.
// daysInFebruary (year)               Returns number of days in February of that year.
// isDate_Parts (year, month, day)     True if string arguments form a valid date.
// isDate_Parts2 (day, month, year)    True if string arguments form a valid date.

// FUNCTIONS TO REFORMAT DATA:
//
// stripCharsInBag (s, bag)            Removes all characters in string bag from string s.
// stripCharsNotInBag (s, bag)         Removes all characters NOT in string bag from string s.
// stripWhitespace (s)                 Removes all whitespace characters from s.
// stripInitialWhitespace (s)          Removes initial (leading) whitespace characters from s.
// reformat (TARGETSTRING, STRING,     Function for inserting formatting characters or
//   INTEGER, STRING, INTEGER ... )       delimiters into TARGETSTRING.                                       


// FUNCTIONS TO PROMPT USER:
// FormError (control, message, errorbg)	Changes backround color of 'control' to 'errorbg' and alerts the user with 'message'
// NoError (control, normalbg)						Changes backround color of 'control' to 'normalbg'


// FUNCTIONS TO INTERACTIVELY CHECK FIELD CONTENTS:
// getRadioButtonValue (radio)         Get checked value from radio button.
//
//
// 18 Feb 97 created Eric Krock
//
// (c) 1997 Netscape Communications Corporation


// VARIABLE DECLARATIONS
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// whitespace characters
var whitespace = " \t\n\r";

// decimal point character differs by language and culture
var decimalPointDelimiter = "."

// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";

// characters which are allowed in international phone numbers (a leading + is OK)
var validWorldPhoneChars = digits + phoneNumberDelimiters + "+";

// non-digit characters which are allowed in credit card numbers
var creditCardDelimiters = " "

// Global variable defaultEmptyOK defines default return value 
// for many functions when they are passed an empty string. 
// By default, they will return defaultEmptyOK.
var defaultEmptyOK = true

var daysInMonth = new Array(12) 
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

// Check whether string s is empty.
function isEmpty(s)
{
	return ((s == null) || (s.length == 0))
}


// Returns true if string s is empty or whitespace characters only.
function isWhitespace (s)
{
	var i;

	// Is s empty?
	if (isEmpty(s)) return true;

	// Search through string's characters one by one
  // until we find a non-whitespace character.
  // When we do, return false; if we don't, return true.
	for (i = 0; i < s.length; i++)
  {   
  	// Check that current character isn't whitespace.
    var c = s.charAt(i);

    if (whitespace.indexOf(c) == -1) return false;
	}

	// All characters are whitespace.
  return true;
}


// Removes all characters which appear in string bag from string s.
function stripCharsInBag (s, bag)
{
	var i;
  var returnString = "";

  // Search through string's characters one by one.
  // If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++)
  {   
  	// Check that current character isn't whitespace.
    var c = s.charAt(i);
    if (bag.indexOf(c) == -1) returnString += c;
	}

  return returnString;
}


// Removes all characters which do NOT appear in string bag from string s.
function stripCharsNotInBag (s, bag)
{
	var i;
  var returnString = "";

  // Search through string's characters one by one.  If character is in bag, append to returnString.
	for (i = 0; i < s.length; i++)
  {   
  	// Check that current character isn't whitespace.
    var c = s.charAt(i);
    if (bag.indexOf(c) != -1) returnString += c;
	}

  return returnString;
}


// Removes all whitespace characters from s.
// Global variable whitespace (see above) defines which characters are considered whitespace.
function stripWhitespace (s)
{
	return stripCharsInBag (s, whitespace)
}


// WORKAROUND FUNCTION FOR NAVIGATOR 2.0.2 COMPATIBILITY.
//
// The below function *should* be unnecessary.  In general,
// avoid using it.  Use the standard method indexOf instead.
//
// However, because of an apparent bug in indexOf on 
// Navigator 2.0.2, the below loop does not work as the
// body of stripInitialWhitespace:
//
// while ((i < s.length) && (whitespace.indexOf(s.charAt(i)) != -1))
//   i++;
//
// ... so we provide this workaround function charInString
// instead.
//
// charInString (CHARACTER c, STRING s)
//
// Returns true if single character c (actually a string)
// is contained within string s.
function charInString (c, s)
{
	for (i = 0; i < s.length; i++)
  {
		if (s.charAt(i) == c) return true;
	}
  return false
}


// Removes initial (leading) whitespace characters from s.
// Global variable whitespace (see above) defines which characters are considered whitespace.
function stripInitialWhitespace (s)
{
	var i = 0;

	while ((i < s.length) && charInString (s.charAt(i), whitespace))
		i++;

	return s.substring (i, s.length);
}


// Returns true if character c is an English letter 
// (A .. Z, a..z).
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.
function isLetter (c)
{
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}


// Returns true if character c is a digit 
// (0 .. 9).
function isDigit (c)
{
	return ((c >= "0") && (c <= "9"))
}


// Returns true if character c is a letter or digit.
function isLetterOrDigit (c)
{
	return (isLetter(c) || isDigit(c))
}


// isInteger (STRING s [, BOOLEAN emptyOK])
// Returns true if all characters in string s are numbers.
//
// NOTES:
// Accepts non-signed integers only. Does not accept floating point, exponential notation, etc.
// We don't use parseInt because that would accept a string with trailing non-numeric characters.
function isInteger (s)
{
	var i;

	if (isEmpty(s)) 
  	if (isInteger.arguments.length == 1) return defaultEmptyOK;
    else return (isInteger.arguments[1] == true);

	// Search through string's characters one by one until we find a non-numeric character.
  // When we do, return false; if we don't, return true.
	for (i = 0; i < s.length; i++)
  {   
  	// Check that current character is number.
    var c = s.charAt(i);

    if (!isDigit(c)) return false;
	}

	// All characters are numbers.
  return true;
}


// isSignedInteger (STRING s [, BOOLEAN emptyOK])
// Returns true if all characters are numbers; first character is allowed to be + or - as well.
//
// NOTES:
// Does not accept floating point, exponential notation, etc.
// We don't use parseInt because that would accept a string with trailing non-numeric characters.
function isSignedInteger (s)
{
	if (isEmpty(s)) 
  	if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
    else return (isSignedInteger.arguments[1] == true);

	else
	{
  	var startPos = 0;
    var secondArg = defaultEmptyOK;

    if (isSignedInteger.arguments.length > 1)
    	secondArg = isSignedInteger.arguments[1];

		// skip leading + or -
    if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
    	startPos = 1;    
		return (isInteger(s.substring(startPos, s.length), secondArg))
	}
}


// isPositiveInteger (STRING s [, BOOLEAN emptyOK])
// Returns true if string s is an integer > 0.
function isPositiveInteger (s)
{
	var secondArg = defaultEmptyOK;

	if (isPositiveInteger.arguments.length > 1)
  	secondArg = isPositiveInteger.arguments[1];

	// The next line is a bit byzantine.  What it means is:
  // a) s must be a signed integer, AND
  // b) one of the following must be true:
  //    i)  s is empty and we are supposed to return true for empty strings
  //    ii) this is a positive, not negative, number
	return (isSignedInteger(s, secondArg)
  	&& ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
}


// isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
// Returns true if string s is an integer >= 0.
function isNonnegativeInteger (s)
{
	var secondArg = defaultEmptyOK;

	if (isNonnegativeInteger.arguments.length > 1)
  	secondArg = isNonnegativeInteger.arguments[1];

	// The next line is a bit byzantine.  What it means is:
  // a) s must be a signed integer, AND
  // b) one of the following must be true:
  //    i)  s is empty and we are supposed to return true for empty strings
  //    ii) this is a number >= 0
	return (isSignedInteger(s, secondArg)
  	&& ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}


// isNegativeInteger (STRING s [, BOOLEAN emptyOK])
// Returns true if string s is an integer < 0.
function isNegativeInteger (s)
{
	var secondArg = defaultEmptyOK;

  if (isNegativeInteger.arguments.length > 1)
		secondArg = isNegativeInteger.arguments[1];

	// The next line is a bit byzantine.  What it means is:
  // a) s must be a signed integer, AND
  // b) one of the following must be true:
  //    i)  s is empty and we are supposed to return true for empty strings
	//    ii) this is a negative, not positive, number
	return (isSignedInteger(s, secondArg)
  	&& ( (isEmpty(s) && secondArg)  || (parseInt (s) < 0) ) );
}


// isNonpositiveInteger (STRING s [, BOOLEAN emptyOK])
// Returns true if string s is an integer <= 0.
function isNonpositiveInteger (s)
{
	var secondArg = defaultEmptyOK;

	if (isNonpositiveInteger.arguments.length > 1)
  	secondArg = isNonpositiveInteger.arguments[1];

	// The next line is a bit byzantine.  What it means is:
  // a) s must be a signed integer, AND
  // b) one of the following must be true:
  //    i)  s is empty and we are supposed to return true for empty strings
	//    ii) this is a number <= 0

	return (isSignedInteger(s, secondArg)
  	&& ( (isEmpty(s) && secondArg)  || (parseInt (s) <= 0) ) );
}


// isFloat (STRING s [, BOOLEAN emptyOK])
// True if string s is an unsigned floating point (real) number. 
//
// NOTES:
// Also returns true for unsigned integers. If you wish to distinguish between integers and floating point numbers, first call isInteger, then call isFloat.
// Does not accept exponential notation.
function isFloat (s)
{
	var i;
  var seenDecimalPoint = false;

	if (isEmpty(s)) 
  	if (isFloat.arguments.length == 1) return defaultEmptyOK;
    	else return (isFloat.arguments[1] == true);

	if (s == decimalPointDelimiter) return false;
	// Search through string's characters one by one until we find a non-numeric character.
  // When we do, return false; if we don't, return true.

	for (i = 0; i < s.length; i++)
  {   
  	// Check that current character is number.
    var c = s.charAt(i);

		if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
			else if (!isDigit(c)) return false;
	}

	// All characters are numbers.
  return true;
}


// isSignedFloat (STRING s [, BOOLEAN emptyOK])
// True if string s is a signed or unsigned floating point (real) number. First character is allowed to be + or -.
//
// NOTES:
// Also returns true for unsigned integers. If you wish to distinguish between integers and floating point numbers, first call isSignedInteger, then call isSignedFloat.
// Does not accept exponential notation.
function isSignedFloat (s)
{
	if (isEmpty(s)) 
  	if (isSignedFloat.arguments.length == 1) return defaultEmptyOK;
    	else return (isSignedFloat.arguments[1] == true);

	else
	{
  	var startPos = 0;
    var secondArg = defaultEmptyOK;

    if (isSignedFloat.arguments.length > 1)
			secondArg = isSignedFloat.arguments[1];

		// skip leading + or -
    if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
    	startPos = 1;    

    return (isFloat(s.substring(startPos, s.length), secondArg))
	}
}


// isAlphabetic (STRING s [, BOOLEAN emptyOK])
// Returns true if string s is English letters 
// (A .. Z, a..z) only.
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.
function isAlphabetic (s)
{
	var i;

	if (isEmpty(s)) 
  	if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
    	else return (isAlphabetic.arguments[1] == true);

	// Search through string's characters one by one until we find a non-alphabetic character.
  // When we do, return false; if we don't, return true.
	for (i = 0; i < s.length; i++)
  {   
  	// Check that current character is letter.
    var c = s.charAt(i);

    if (!isLetter(c))
    	return false;
	}

	// All characters are letters.
  return true;
}


// isAlphanumeric (STRING s [, BOOLEAN emptyOK])
// Returns true if string s is English letters 
// (A .. Z, a..z) and numbers only.
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.
function isAlphanumeric (s)
{
	var i;

	if (isEmpty(s)) 
		if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
    	else return (isAlphanumeric.arguments[1] == true);

	// Search through string's characters one by one
  // until we find a non-alphanumeric character.
  // When we do, return false; if we don't, return true.
	for (i = 0; i < s.length; i++)
  {   
  	// Check that current character is number or letter.
		var c = s.charAt(i);

    if (! (isLetter(c) || isDigit(c) ) )
    	return false;
	}

	// All characters are numbers or letters.
  return true;
}


// reformat (TARGETSTRING, STRING, INTEGER, STRING, INTEGER ... )       
// Handy function for arbitrarily inserting formatting characters or delimiters of various kinds within TARGETSTRING.
//
// reformat takes one named argument, a string s, and any number of other arguments.  The other arguments must be integers or
// strings.  These other arguments specify how string s is to be reformatted and how and where other strings are to be inserted
// into it.
//
// reformat processes the other arguments in order one by one.
// * If the argument is an integer, reformat appends that number of sequential characters from s to the resultString.
// * If the argument is a string, reformat appends the string to the resultString.
//
// NOTE: The first argument after TARGETSTRING must be a string. (It can be empty.)  The second argument must be an integer.
// Thereafter, integers and strings must alternate.  This is to provide backward compatibility to Navigator 2.0.2 JavaScript
// by avoiding use of the typeof operator.
//
// It is the caller's responsibility to make sure that we do not
// try to copy more characters from s than s.length.
//
// EXAMPLES:
// * To reformat a 10-digit U.S. phone number from "1234567890" to "(123) 456-7890" make this function call:
//   reformat("1234567890", "(", 3, ") ", 3, "-", 4)
//
// * To reformat a 9-digit U.S. Social Security number from "123456789" to "123-45-6789" make this function call:
//   reformat("123456789", "", 3, "-", 2, "-", 4)
function reformat (s)
{
	var arg;
  var sPos = 0;
  var resultString = "";

	for (var i = 1; i < reformat.arguments.length; i++)
	{
  	arg = reformat.arguments[i];

    if (i % 2 == 1) resultString += arg;
		else
		{
    	resultString += s.substring(sPos, sPos + arg);
      sPos += arg;
		}
	}

  return resultString;
}


// isInternationalPhoneNumber (STRING s [, BOOLEAN emptyOK])
function isInternationalPhoneNumber (s)
{
	if (isEmpty(s)) 
  	if (isInternationalPhoneNumber.arguments.length == 1) return defaultEmptyOK;
    else return (isInternationalPhoneNumber.arguments[1] == true);

	var i
	for (i =0; i <= s.length -1; i++)
	{
		if (validWorldPhoneChars.indexOf(s.charAt(i)) == -1)
			return false

	} // End for loop

	return true;
}


// isEmail (emailStr [, BOOLEAN emptyOK==false])
// Check that string emailStr is a valid Email.
function isEmail (emailStr, emptyOK)
{
	if (isEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
  if ((emptyOK == true) && (isEmpty(emailStr))) return true;

	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/
	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */
	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat);

	if (matchArray==null)
	{
		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */

		// Email address seems incorrect (check @ and .'s)
		return false;
	}

	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++)
	{
		if (user.charCodeAt(i)>127)
		{
			// The username contains invalid characters.
			return false;
		}
	}

	for (i=0; i<domain.length; i++)
	{
		if (domain.charCodeAt(i)>127)
		{
			// The domain name contains invalid characters.
			return false;
  	}
	}

	// See if "user" is valid 
	if (user.match(userPat)==null)
	{
		// user is not valid
		return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
	{
		// this is an IP address
		for (var i=1;i<=4;i++)
		{
			if (IPArray[i]>255)
			{
				//Destination IP address is invalid!
				return false;
			}
		}

		return true;
	}

	// Domain is symbolic name.  Check if it's valid.
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;

	for (i=0;i<len;i++)
	{
		if (domArr[i].search(atomPat)==-1)
		{
			// The domain name does not seem to be valid.
			return false;
		}
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1)
	{
		// The address must end in a well-known domain or two letter country code
		return false;
	}

	// Make sure there's a host name preceding the domain.
	if (len<2)
	{
		// The address is missing a hostname!
		return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
}


// isYear (STRING s [, BOOLEAN emptyOK])
// Returns true if string s is a valid Year number.  Must be 2 or 4 digits only.
// NOTE: For B.C. compliance, write your own function. ;->
function isYear (s)
{
	if (isEmpty(s)) 
  	if (isYear.arguments.length == 1) return defaultEmptyOK;
    else return (isYear.arguments[1] == true);

	if (!isNonnegativeInteger(s)) return false;
		return ((s.length == 2) || (s.length == 4));
}


// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
// Returns true if string s is an integer within the range of integer arguments a and b, inclusive.
function isIntegerInRange (s, a, b)
{
	if (isEmpty(s)) 
  	if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
    else return (isIntegerInRange.arguments[1] == true);

	// Catch non-integer strings to avoid creating a NaN below,
  // which isn't available on JavaScript 1.0 for Windows.
  if (!isInteger(s, false)) return false;

	// Now, explicitly change the type to integer via parseInt so that the comparison code below will work both on 
	// JavaScript 1.2 (which typechecks in equality comparisons) and JavaScript 1.1 and before (which doesn't).
	var num = parseInt (s);
  return ((num >= a) && (num <= b));
}


// isMonth (STRING s [, BOOLEAN emptyOK])
// Returns true if string s is a valid month number between 1 and 12.
function isMonth (s)
{
	if (isEmpty(s)) 
  	if (isMonth.arguments.length == 1) return defaultEmptyOK;
    else return (isMonth.arguments[1] == true);

	return isIntegerInRange (s, 1, 12);
}


// isDay (STRING s [, BOOLEAN emptyOK])
// Returns true if string s is a valid day number between 1 and 31.
function isDay (s)
{
	if (isEmpty(s)) 
  	if (isDay.arguments.length == 1) return defaultEmptyOK;
    else return (isDay.arguments[1] == true);   

	return isIntegerInRange (s, 1, 31);
}


// daysInFebruary (INTEGER year)
// Given integer argument year, returns number of days in February of that year.
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 );
}

// isDate_Parts (STRING year, STRING month, STRING day)
// Returns true if string arguments year, month, and day form a valid date.
function isDate_Parts (year, month, day)
{
	// catch invalid years (not 2- or 4-digit) and invalid months and days.
  if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

	// Explicitly change type to integer to make code work in both JavaScript 1.1 and JavaScript 1.2.
	var intYear = parseInt(year);
  var intMonth = parseInt(month);
  var intDay = parseInt(day);

	// catch invalid days, except for February
  if (intDay > daysInMonth[intMonth]) return false; 
  if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

	return true;
}

// isDate_Parts2 (STRING day STRING month, STRING month)
// Returns true if string arguments year, month, and day form a valid date.
function isDate_Parts2 (day, month, year)
{
	// catch invalid years (not 2- or 4-digit) and invalid months and days.
  if (! (isDay(day, false) && isMonth(month, false) && isYear(year, false))) return false;
	
	// Explicitly change type to integer to make code work in both JavaScript 1.1 and JavaScript 1.2.

  var intDay = parseInt(day);
	var intMonth = parseInt(month);
	var intYear = parseInt(year);  

	// catch invalid days, except for February
  if (intDay > daysInMonth[intMonth]) return false; 
  if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

	return true;
}


/* FUNCTIONS TO NOTIFY USER OF INPUT REQUIREMENTS OR MISTAKES. */
// FormError (FORMFIELD control, STRING message, STRING errorbg)
// Sets background color of 'control' to 'errorbg', then displays 'message' to user.
function FormError(control, message, errorbg)
{
	if(control.style) control.style.background = errorbg;

	alert(message);

	control.focus(); 
	//control.blur();	//REMOVED AS IT SEEMS A BIT POINTLESS...!!!  WHY FOCUS A CONTROL JUST TO BLUR IT AGAIN...???
	if ( control.select )
        control.select();

	return false;
}


// NoError (FORMFIELD control, STRING normalbg)
// Sets background color of 'control' to 'normalbg', to restore forms changed by FormError.
function NoError(control, normalbg)
{
	if(control.style) control.style.background = normalbg;
}


/* FUNCTIONS TO INTERACTIVELY CHECK VARIOUS FIELDS. */
// Get checked value from radio button.
function getRadioButtonValue (radio)
{
	for (var i = 0; i < radio.length; i++)
  {
		if (radio[i].checked) { break }
	}

  return radio[i].value
}
