/* <%--
//
//	File: 		validate/date.js
//	Purpose:	Provide date JavaScript validation operations
//  Usage:    This file contains functions for validating date fields
//            using JavaScript.  Note that the format of dates can vary
//            greatly from system to system so it is important that these
//            functions be as flexible as possible.  Generally the date
//            object will not passed in as there may be multiple objects
//            associated with a date.
//            NOTE: Even though date fields can be represented on a form
//            with multiple objects the functions below refer to it as
//            one field, which it logically is.
//            fieldTypes - All "fieldType" parameters should match the type
//              as used in the HtmlBuildDate function in HTMLBuild, ie:
//                - HIDDEN - Specifies a form HIDEEN field that should be in
//                           YYYYMMDD (datestring) format
//                - INPUT - Specifies a form INPUT field
//                - INPUTSHADOW - Specifies a form INPUT field with a SHADOW one
//																that can be used to hold different formats
//            See the file header.js for details on the validation process.
//  Dependencies:  validate/number.js


// ------ PUBLIC FUNCTION INDEX
// VAL_AppendDateError ( errMsg, form, fieldName, fieldType )
// VAL_CheckDateError( errFieldName, msg, form )
// VAL_DateRequiredWithMessage ( form, fieldRef, fieldType, desc, dateFormat )
// VAL_DateCheckWithMessage ( form, fieldRef, fieldType, desc, dateFormat, dateRequired )
// VAL_DateIsGreaterOrEqualWithMessages ( form, before, after, beforeDesc, afterDesc, dateType, dateFormat )
// VAL_DateIsGreaterOrEqualWithMessage ( form, before, after, beforeDesc, afterDesc, dateType, dateFormat )
// VAL_DateCheckFromToError( form, fromDate, toDate, fromDateLabel, toDateLabel, dateType, fromDateRequired, toDateRequired, dependentlyRequired, dateFormat)
// VAL_DateCopy( form, fieldNameFrom, fieldNameTo, dateType )
// VAL_DateSet( form, fieldName, dateType, dateFormat, dateString )
// VAL_DateStringToDateValue( dateString )
// VAL_DateMsg( fieldname, dateFormat )
// VAL_GetDateFirstField( form, fieldName, fieldType )
// VAL_IsBlankDate( form, fieldName, fieldType )
// VAL_IsDate( form, fieldName, fieldType, options, dateFormat )
// VAL_IsDayOfMonth( day, month, year )

--%> */


// ------ GLOBAL PREFERENCES
// Also see js_constants.jsp


// ------------------------------------------------------------------------ //
// Supplied date field is required, builds appropriate error message.
// Returns false if blank or invalid, true if supplied and valid.

function VAL_DateRequiredWithMessage ( form, fieldRef, fieldType, desc, dateFormat )
{
	return VAL_DateCheckWithMessage ( form, fieldRef, fieldType, desc, dateFormat, true );
}


// ------------------------------------------------------------------------ //
// Builds an error message if the supplied date field contains a non-blank
// invalid date. Returns true if blank or valid, false if invalid.

function VAL_DateCheckWithMessage ( form, fieldRef, fieldType, desc, dateFormat, dateRequired )
{
	var retVal = true;
	if ( VAL_IsBlankDate ( form, fieldRef.name, fieldType ) ) {
		if (dateRequired == true) {
			VAL_AppendRequired ( desc, form.elements[VAL_GetDateFirstField( form, fieldRef.name, fieldType )] );
			retVal = false;
		}
	} else if ( ! VAL_CheckDateError ( VAL_IsDate ( form, fieldRef.name, fieldType, "", dateFormat ),
																		 VAL_DateMsg ( desc, dateFormat ), form ) )	{
		retVal = false;
	}
	return retVal;
}


// ------------------------------------------------------------------------ //
// Checks a date pair to make sure they are in the right order and valid.

function VAL_DateIsGreaterOrEqualWithMessages (
	form,						// a form reference with the date to validate
	before,					// field reference to before/to date
	after,					// field reference to after/from date
	beforeDesc,			// description of before field of date pair
	afterDesc,			// description of after field of date pair	
	beforeDateType,	// the type of before/to date, like CFG_DateEntryType
	afterDateType,	// the type of after/from date, like CFG_DateEntryType		
	dateFormat			// date format to use
) {
	var status = true;
	if (!VAL_DateCheckWithMessage ( form, after, afterDateType, afterDesc, dateFormat )) {
		status = false;
	}
	if (!VAL_DateCheckWithMessage ( form, before, beforeDateType, beforeDesc, dateFormat )) {
		status = false;
	}
	status = status && VAL_DateIsGreaterOrEqualWithMessage ( form, before, after, beforeDesc, afterDesc, beforeDateType, afterDateType, dateFormat );
	return status;
}


// ------------------------------------------------------------------------ //
// Builds an error message if the before date is greater than the after date.

function VAL_DateIsGreaterOrEqualWithMessage (
	form,						// a form reference with the date to validate
	before,					// field reference to before/to date
	after,					// field reference to after/from date
	beforeDesc,			// description of before field of date pair
	afterDesc,			// description of after field of date pair	
	beforeDateType,	// the type of before/to date, like CFG_DateEntryType
	afterDateType,	// the type of after/from date, like CFG_DateEntryType		
	dateFormat			// date format to use
	)
{
	var retVal = true;
	if (VAL_IsDateGreaterOrEqual ( form, before.name, beforeDateType, form, after.name, afterDateType, dateFormat ) == 0) {
		VAL_AppendDateError ( sprintf( VAL_dateNotEarlierMsg, beforeDesc, afterDesc ), form, before.name, beforeDateType );
		retVal = false;
	}
	return retVal;
}

// ------------------------------------------------------------------------ //
// Copies a date from one field to another.
// Assumes that the type and format are the same.
function VAL_DateCopy(
	form,									// a form reference with the date to validate
	fieldNameFrom,        // the field name to copy from
	fieldNameTo,          // the field name to copy to
	dateType							// the date type for the fields
)
{
	if (dateType == "INPUT" || dateType == "HIDDEN") {
		form.elements[fieldNameTo].value = form.elements[fieldNameFrom].value;
	} else if (dateType == "INPUTSHADOW") {
		// for shadows set the real field to blank if the shadow one is
		fromName = VAL_DateGetShadowFieldName(fieldNameFrom);
		toName = VAL_DateGetShadowFieldName(fieldNameTo);
		form.elements[toName].value = form.elements[fromName].value;
	}
}

// ------------------------------------------------------------------------ //
// Sets a date field from a date value
function VAL_DateSet(
	form,          // a form reference with the date to validate
	fieldName,     // the name of the date field
	dateType,      // the date type for the field
	dateFormat,    // date format to use
	dateString     // date string value to set
)
{
	if (dateType == "INPUT" || dateType == "HIDDEN") {
		form.elements[fieldName].value = VAL_DateValueToString( dateString, dateFormat );
	} else if (dateType == "INPUTSHADOW") {
		// for shadows set the real field to blank if the shadow one is
		shadowName = VAL_DateGetShadowFieldName(fieldName);
		form.elements[shadowName].value = VAL_DateValueToString( dateString, dateFormat );
	}
}

// ------------------------------------------------------------------------ //
// Takes in a pair of dates for from and to processing and validates them
// and ensures they are both valid and From is earlier than To.
// Parameters allow definition of which fields are required and whether they
// are both required if one is filled in.

function VAL_DateCheckFromToError(
	form,									// a form reference with the date to validate
	fromDate,							// field reference to after/from date
	toDate,								// field reference to before/to date
	fromDateLabel,				// description of the from date
	toDateLabel,					// description of the to date
	dateType,							// the type of date, like CFG_DateEntryType
	fromDateRequired,			// boolean, if true then from date is required
	toDateRequired,				// boolean, if true then to date is required
	dependentlyRequired,	// boolean, if one is present the other has to be as well
	dateFormat						// date format to use
)
{
	var fromBlank = VAL_IsBlankDate(form, fromDate.name, dateType );
	var toBlank = VAL_IsBlankDate(form, toDate.name, dateType );
	var fromOk;
	var toOk;

	fromOk = VAL_DateCheckWithMessage ( form, fromDate, dateType, fromDateLabel, dateFormat, fromDateRequired )
	toOk = VAL_DateCheckWithMessage ( form, toDate, dateType, toDateLabel, dateFormat, toDateRequired )

	if (dependentlyRequired) {
		if (fromBlank && toOk && !toBlank	) {
			VAL_AppendDateError ( sprintf( VAL_dateRequiredDependsMsg, fromDateLabel, toDateLabel ), form, toDate.name, dateType );
		} else if (fromOk && !fromBlank && toBlank) {
			VAL_AppendDateError ( sprintf( VAL_dateRequiredDependsMsg, toDateLabel, fromDateLabel ), form, fromDate.name, dateType );
		}
	}

	if (VAL_IsDateGreaterOrEqual(form, toDate.name, dateType, form, fromDate.name, dateType, dateFormat) == 0) {
		VAL_AppendDateError ( sprintf( VAL_dateNotEarlierMsg, toDateLabel, fromDateLabel ), form, fromDate.name, dateType );
	}
}

// ------------------------------------------------------------------------ //
// Appends an error for a date field
function VAL_AppendDateError (
	errMsg,       // error message to use
	form,         // reference to the form
	fieldName,    // name of the date field
	fieldType     // the type of date i.e. how mapped to the form
)
{
	VAL_AppendError ( errMsg, form.elements[VAL_GetDateFirstField( form, fieldName, fieldType )] );
}

// ------------------------------------------------------------------------ //
// Checks whether an error has occurred using one of the VAL_ date validation
// functions.
// Returns a boolean as to whether or not an error occurred.

function VAL_CheckDateError(
  errFieldName, // a string value indicating the name of the field which is in
	              //   error, usually a date validation function result
	msg,	        // new error string to append
	form          // reference to the form, combined with field name to get an
	              //   object to set focus to
)
{
	if (errFieldName != "") {
		VAL_CheckError( false, msg, form.elements[errFieldName] );
	}
	return (errFieldName == "");
}

// ------------------------------------------------------------------------ //
function VAL_DateMsg(fieldname, dateFormat)
{
	if (dateFormat == null) {
		return sprintf( VAL_InvalidDateMsg, fieldname );
	} else {
		dateFormat = dateFormat.toUpperCase();
		var shortFormat = dateFormat.replace( "YYYY", "YY" );
		return sprintf( VAL_InvalidDateFormatMsg, fieldname, shortFormat, dateFormat );
	}
}

// ------------------------------------------------------------------------ //
// 	Checks whether a date field is blank.  
//	Returns a string with the field name if blank
// 	Returns an empty string "" if not blank

function VAL_IsBlankDate(
	form,      // a form reference with the date to validate
	fieldName, // the field name
	fieldType  // the type of date i.e. how mapped to the form
)
{
  var retVal = fieldName;
	if (fieldType == "INPUT" || fieldType == "HIDDEN") {
		if (!VAL_IsBlank( form.elements[fieldName].value )) {
		  retVal = "";
		}
	} else if (fieldType == "INPUTSHADOW") {
		// for shadows set the real field to blank if the shadow one is
		if (!VAL_IsBlank( form.elements[VAL_DateGetShadowFieldName(fieldName)].value )) {
		  retVal = "";
		} else {
			form.elements[fieldName].value = "";
		}
	}
	return retVal;
}

// ------------------------------------------------------------------------ //
// Returns the first form field associated with a date field.

function VAL_GetDateFirstField(
	form,      // a form reference with the date to validate
	fieldName, // the field name
	fieldType   // the type of date i.e. how mapped to the form
)
{
	var retVal = fieldName;
	if (fieldType == "INPUTSHADOW") {
		retVal = VAL_DateGetShadowFieldName( fieldName );
	} else if (fieldType == "HIDDEN") {
		retVal = "";
	}
	return retVal;
}

// ------------------------------------------------------------------------ //
// Performs date field validation.  See VAL_IsDateGetValue.
// Eg. usage to check if the date is in the future
// VALLOC.VAL_IsDate(form, "SVBManufacturerDealer_ExpirationDate", CFG_DateEntryType, "RANGE=FUTURE");

function VAL_IsDate(
	form,       // a form reference with the date to validate
	fieldName,  // the field name
	fieldType,  // the type of date i.e. how mapped to the form
	options,    // other options for date validation
	dateFormat	// date format to use
)
{
	var dateValue = new Date();
	return VAL_IsDateGetValue( form, fieldName, fieldType, dateValue, options, dateFormat );
}

// ------------------------------------------------------------------------ //
// Performs date field validation.  The options specify additional parameters
// to validate against.  Returns the value of the date in the 'dateValue'
// parameter.
// For the valid options see VAL_CheckDateOptions

function VAL_IsDateGetValue(
	form,       // a form reference with the date to validate
	fieldName,  // the field name
	fieldType,  // the type of date i.e. how mapped to the form
	dateValue,  // a Date object, set to the parsed value
	options,    // other options for date validation
	dateFormat	// date format to use
)
{
	var retVal = VAL_IsBlankDate( form, fieldName, fieldType );
	if (retVal == "") {
		retVal = fieldName;
		if (fieldType == "INPUT") {
			var field = form.elements[fieldName];
			if (field == null) alert( "VAL_IsDate: bad field -> " + fieldName );
			if (VAL_IsDateInput( form.elements[fieldName], dateValue, dateFormat )) {
				retVal = "";
			}

		} else if (fieldType == "HIDDEN") {
			var field = form.elements[fieldName];
			if (field == null) alert( "VAL_IsDate: bad field -> " + fieldName );
			VAL_DateStringToDateValue( field.value, dateValue );
			retVal = "";

		} else if (fieldType == "INPUTSHADOW") {
			var shadowFieldName = VAL_DateGetShadowFieldName( fieldName );
			var shadowfield = form.elements[shadowFieldName];
			if (shadowfield == null) alert( "VAL_IsDate: bad shadow field -> " + shadowFieldName );
			if (VAL_IsDateInput( shadowfield, dateValue, dateFormat )) {
				retVal = "";
				// if the value is good then write it back to the real field
				var field = form.elements[fieldName];
				if (field == null) alert( "VAL_IsDate: bad field -> " + fieldName );
				var datestring = (dateValue.getMonth() + 1) + '/' + dateValue.getDate() + '/';
				var year = dateValue.getYear();
				if (year < 2000) {
					year = year + 1900;
				}
				datestring = datestring + year;
				field.value = datestring;
			}
		}

		if (retVal == "") {
			if (!VAL_CheckDateOptions( dateValue, options )) {
				retVal = VAL_GetDateFirstField( form, fieldName, fieldType );
			}
		}
	}
	return retVal;
}

// ------------------------------------------------------------------------ //
// Performs other checks on a date based on passed in options.  Returns a
// boolean if all the options were met successfully.
// options:
//   RANGE - determines what range the date may be in
//       values: FUTURE - The date must be in the future
//               FUTUREINC - The date must be in the future or today.
//               PAST - The date must be in the past or today.
//               PASTINC - The date must be in the past or today.

function VAL_CheckDateOptions(
	dateValue, // a Date object containing the date
	options    // a list of ; separted options specified above
)
{
	var retVal = true;
	while (retVal && (options != "")) {
		nextPos = options.indexOf( ';' );
		if (nextPos >= 0) {
		  nextOption = options.substr( 0, nextPos );
			options = options.substr( nextPos + 1 );
		} else {
		  nextOption = options;
			options = "";
		}
		nextPos = nextOption.indexOf( '=' );
		if (nextPos >= 0) {
		  optionName = nextOption.substr( 0, nextPos );
			optionValue = nextOption.substr( nextPos + 1 );
		} else {
			optionName = nextOption;
			optionValue = "";
		}
		if (optionName == "RANGE") {
		  retVal = VAL_CheckDateRange( dateValue, optionValue );
		}
	}
	return retVal;
}

// ------------------------------------------------------------------------ //
// Returns whether the date falls within a certain range.

function VAL_CheckDateRange(
	dateValue, // a Date object containing the date
	rangeType  // see VAL_CheckDateOptions and the RANGE option for values
)
{
	var retVal = true;
	var intCheck = 0;
	var now = new Date();

	intCheck = VAL_CompareDates(now, dateValue);
	
	if (rangeType == "FUTURE") {
	  retVal = (intCheck > 0);
	} else if (rangeType == "FUTUREINC") {
	  retVal = (intCheck >= 0);
	} else if (rangeType == "PAST") {
	  retVal = (intCheck < 0);
	} else if (rangeType == "PASTINC") {
	  retVal = (intCheck <= 0);
	}
	return retVal;
}

// ------------------------------------------------------------------------ //
// Returns 1 if the first date (representing by form1, fieldName1, fieldType1) 
// is greater than or equal the second date (representing by form2, fieldName2 and fieldType2).
// Returns 0 if it is not and returns -1 if the comparison was not done because
// one of the dates was blank or invalid.

function VAL_IsDateGreaterOrEqual(
	form1, fieldName1, fieldType1,	
	form2, fieldName2, fieldType2,
	dateFormat
)
{
	var retVal = -1;
	
	if (!VAL_IsBlankDate(form1, fieldName1, fieldType1) && !VAL_IsBlankDate(form2, fieldName2, fieldType2)) 
	{
		var date1 = new Date();
		var date2 = new Date();
		if ((VAL_IsDateGetValue( form1, fieldName1, fieldType1, date1, "", dateFormat ) == "") 
			&& (VAL_IsDateGetValue( form2, fieldName2, fieldType2, date2, "", dateFormat ) == ""))
		{
			var compRet = VAL_CompareDates(date1, date2);
			if (compRet == -1 || compRet == 0) 
			{
				retVal = 1;
			} else {
				retVal = 0;
			}
		}
	}
	return retVal;
}

// ------------------------------------------------------------------------ //
// This function is deprecated because of the name and should no longer be used.
// Please use VAL_IsDateGreaterOrEqual instead.
// THIS SHOULD BE REMOVED AT A LATER DATE

function VAL_IsGreaterOrEqual(
	form1, fieldName1, fieldType1,	
	form2, fieldName2, fieldType2
)
{
	return (VAL_IsDateGreaterOrEqual( form1, fieldName1, fieldType1,	form2, fieldName2, fieldType2 ) == 1);
}

// ------------------------------------------------------------------------ //

function VAL_CompareDates(
	date1Value, // a Date object containing the date
	date2Value  
)
{
	var retVal = 0;

	if (date2Value.getYear() < date1Value.getYear()) {
		retVal = -1;
	} else if (date2Value.getYear() > date1Value.getYear()) {
		retVal = 1;
	} else if (date2Value.getMonth() < date1Value.getMonth()) {
		retVal = -1;
	} else if (date2Value.getMonth() > date1Value.getMonth()) {
		retVal = 1;
	} else if (date2Value.getDate() < date1Value.getDate()) {
		retVal = -1;
	} else if (date2Value.getDate() > date1Value.getDate()) {
		retVal = 1;
	} // otherwise the dates are equal MDY wise


	return retVal;
}


// ------------------------------------------------------------------------ //
// Returns whether or not the day is valid for the month and year in
// question.
function VAL_IsDayOfMonth(
	day,   // day value from 1 to 31
	month, // month value from 1 to 12
	year   // 4-digit year value
)
{
	var monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	if (((year%4 == 0)&& (year % 100 != 0)) || (year%400 == 0))
	{
		monthDays[1] = 29;
	}
	return (day <= monthDays[month-1]);
}

// ------------------------------------------------------------------------ //
// Checks whether an input has a correct format.  Accepts formats
// MM/DD/YYYY or MM/DD/YY or MMDDYY or MMDDYYYY.
function VAL_IsDateInput(
	dateInput, // the date input field
	dateValue, // a Date object, set to the parsed value
	dateFormat // the date format to parse against
)
{
	if (dateFormat == null) {
		dateFormat = "MM/DD/YYYY";
	}
	dateFormat = dateFormat.toUpperCase();
	var hasSlashes = false;
	var isParsed = false;
	var retVal = false;
	var str = dateInput.value;
	var dayStr;
	var yearStr;
	var monthStr;
	nextPos = str.indexOf( '/' );
	if (nextPos >= 0) {
		hasSlashes = true;
		strBegin = str.substr( 0, nextPos );
		str = str.substr( nextPos + 1 );
		nextPos = str.indexOf( '/' );
		if (nextPos >= 0) {
			isParsed = true;
			// check the parsing based on the format
			if (dateFormat == "YYYY/MM/DD") {
				yearStr = strBegin;
				monthStr = str.substr( 0, nextPos );
				dayStr = str.substr( nextPos + 1 );
			} else if (dateFormat == "DD/MM/YYYY") {
				dayStr = strBegin;
				monthStr = str.substr( 0, nextPos );
				yearStr = str.substr( nextPos + 1 );
			} else {
				monthStr = strBegin;
				dayStr = str.substr( 0, nextPos );
				yearStr = str.substr( nextPos + 1 );
			}
		}
	} else {
		if (str.length == 6 || str.length == 8) {
			isParsed = true;
			// check the parsing based on the format
			if (dateFormat == "YYYY/MM/DD") {
				yearStr = str.substr( 0, str.length - 4 );
				monthStr = str.substr( str.length - 4, 2 );
				dayStr = str.substr( str.length - 2, 2 );
			} else if (dateFormat == "DD/MM/YYYY") {
				dayStr = str.substr( 0, 2 );
				monthStr = str.substr( 2, 2 );
				yearStr = str.substr( 4, str.length - 4 );
			} else {
				monthStr = str.substr( 0, 2 );
				dayStr = str.substr( 2, 2 );
				yearStr = str.substr( 4, str.length - 4 );
			}			
		}
	}
	if (isParsed) {
		if (VAL_IsDigitString( yearStr )) {
			if (yearStr.length == 2)
			{
				yearStr = VAL_ConvertTo4DYear(yearStr);
			}
			if (yearStr.length == 4)
			{
				if (VAL_IsIntegerRange( monthStr, 1, 12 ) &&
						VAL_IsIntegerRange( dayStr, 1, 31 ) &&
						VAL_IsIntegerMin( yearStr, 1900 ))
				{
					var month = parseInt( monthStr, 10 );
					var day = parseInt( dayStr, 10 );
					var year = parseInt( yearStr, 10 );
					if (VAL_IsDayOfMonth( day, month, year )) {
						// order matters because invalid days of a month may not work
						dateValue.setDate( 1 );
						dateValue.setMonth( month - 1 );
						dateValue.setYear( year );
						dateValue.setDate( day );
						retVal = true;
						if (!hasSlashes) {
							dateInput.value = VAL_DateValueToString( dateValue, dateFormat );
						}
					}
				}
			}
		}
	}
	return retVal;
}

// ------------------------------------------------------------------------ //
// turns a date string into a date value.  Assumes that the input is valid
function VAL_DateStringToDateValue(
	dateString,    // expects string in YYYYMMDD format
	dateValue      // a Date object, set to the parsed value
	)
{
	// order matters because invalid days of a month may not work
	dateValue.setDate( 1 );	
	dateValue.setMonth( dateString.substr( dateString.length - 4, 2 ) - 1 );
	dateValue.setYear( dateString.substr( 0, dateString.length - 4 ) );
	dateValue.setDate( dateString.substr( dateString.length - 2, 2 ) );
}

// ------------------------------------------------------------------------ //
// returns a string 
function VAL_DateValueToString(
	dateValue,
	dateFormat
)
{
	if (dateValue == null) {
		return "";
	}
	dateFormat = dateFormat.toUpperCase();
	var year = dateValue.getFullYear();
	var month = dateValue.getMonth() + 1;
	var day = dateValue.getDate();
	if (dateFormat == "YYYY/MM/DD") {
		return year + '/' +  month + '/' + day;
	} else if (dateFormat == "DD/MM/YYYY") {
		return day + '/' + month + '/' + year;
	} else {
		return month + '/' + day + '/' + year;
	}
}


// ------------------------------------------------------------------------ //
// returns the current century
function VAL_GetCentury ()
{
	var currentDate = new Date();
	var currentYear = currentDate.getFullYear();
	var temp = currentYear.toString();
	var century = parseInt(temp.substr(0, 2), 10);

	century *= 100;
	return century;
}

// ------------------------------------------------------------------------ //
// returns the 4 digit year for a 2 digit input
function VAL_ConvertTo4DYear (
	yearInput  	//the year input field
)
{
	var theYear;
	var currentDate = new Date();
	var this2DYear = currentDate.getYear() % 100;
	var thisCent = VAL_GetCentury();
	if (yearInput.length < 3) { // Unless it's mmddyyyy (ignore 0001)
		theYear = parseInt(yearInput, 10) - this2DYear;
		
		if (theYear > 50) {
			theYear = parseInt(yearInput, 10) + thisCent - 100;
			
		} else if (theYear > -50) {
				theYear	= parseInt(yearInput, 10) + thisCent;
				
		} else {
			theYear = parseInt(yearInput, 10) + thisCent + 100;
		}
	}

	return theYear.toString();
}

// ------------------------------------------------------------------------ //
// Gets the "shadow" name for a field.  Returns blank if the field cannot be parsed.
function VAL_DateGetShadowFieldName (
	fieldName
)
{
	var retVal = "";
	var stringArray = fieldName.split( "_" );
	var numberChunks = stringArray.length;
	if (numberChunks == 2 || numberChunks == 3) {
		retVal = stringArray[0] + "_" + stringArray[1] + "SHADOW";
		if (numberChunks == 3) {
			retVal += "_" + stringArray[2];
		}
	}
	return retVal;
}
