<!-- hide -->
/* Javascript Application: Form Validator
** File Name: validate.js
** Version: 6.0
**/
var winShowErrors;
var strStyleSheet;
var strErrorWindowOutput = '';
var strSpecialFunction = '';

/* try this with the tag name property to test for form vs.element.*/

strStyleSheet = "/style.css";

function DoubleCheckMultiSelectsAny(strMultiSelect)
{
	var objMultiSelect = document.getElementById(strMultiSelect).options;
	var lngCounter;
	var blnReset;
	
	blnReset = false;
	for (lngCounter = 0; lngCounter < objMultiSelect.length; lngCounter++)
	{
		if (objMultiSelect[lngCounter].selected)
		{
			if (objMultiSelect[lngCounter].value == '-99')
			{
				blnReset = true;
				break;
			}
		}
	}
	
	if (blnReset)
	{
		for (lngCounter = 0; lngCounter < objMultiSelect.length; lngCounter++)
		{
			if (objMultiSelect[lngCounter].value == '-99')
			{
				objMultiSelect[lngCounter].selected = true;
			}
			else
			{
				objMultiSelect[lngCounter].selected = false;
			}
		}
	}
}

function DisableValidation(theElement, blnKeepValidator, blnKeepErrorName)
{
	switch (arguments.length)
	{
		case 0:
			return;
		case 1:
			blnKeepValidator = false;
			blnKeepErrorName = false;
			break;
		case 2:
			blnKeepErrorName = false;
			break;
		case 3:
			break;
	}
	
	theElement.setAttribute('required', null);
	
	if (!blnKeepValidator)
	{
		theElement.setAttribute('validator', null);
	}
		
	if (!blnKeepErrorName)
	{
		theElement.setAttribute('ErrorName', null);
	}
}

function EnableValidation(theElement, strValidator, strErrorName, strExtra)
{
	switch (arguments.length)
	{
		case 0:
			break;
		case 4:
			switch (strValidator)
			{
				case 'DropDown':
					theElement.setAttribute('AllowZero', strExtra);
					break;
			}			
		case 3:
			theElement.setAttribute('ErrorName', strErrorName);
		case 2:
			theElement.setAttribute('validator', strValidator);
		case 1:
			theElement.setAttribute('required', true);
			break;
	}
}

function validateForm(theForm, blnImmediateOutput)
{
	var arrFormElements = theForm.elements; 
	var blnIsValid, blnIsValidTemp;
	var intCounter;
	
	
	if (arguments.length == 1)
	{
		blnImmediateOutput = true;
	}

	blnIsValid = true;
	
	strErrorWindowOutput = '';
	
	for (intCounter = 0; intCounter < arrFormElements.length; intCounter++)
	{
		blnIsValidTemp = validateElementSilent(arrFormElements[intCounter], false, true);
		blnIsValid = blnIsValid && blnIsValidTemp;
	}
	
	// Check if we are returning this immediately
	if (blnImmediateOutput)
	{
		// OK. We want to display now, so check if there were errors
		if (strErrorWindowOutput != "")
		{
			// There were errors, so call showErrors
			DisplayErrors();
		}
	}
	return blnIsValid;
}

/*'********************************************************************************
'* Program: ValidateElementSilent
'*
'* Modified:
'*	1/13/03 Michael Howard
'*			-	Added reference to 'AllowZero' attribute which precludes a
'*				zero value for dropdown lists if found
'*
'**********************************************************************************/
function validateElementSilent(theElement, blnImmediateOutput, blnWriteToOutput, blnResetOutput)
{
	var strValidator = theElement.getAttribute('validator');
	var strPattern = new RegExp;
	var strName, strValue, strPattern, strPatternMessage;
	var strEnglishName;
	var blnIsValid, blnIsRequired, blnAllowZero, blnAllowNegative;
	var intMinLength, intMaxLength;
	
	switch(arguments.length)
	{
		case 3:
			blnResetOutput = false;
	}
	
	// Let's see if we are resetting the error messages
	if (blnResetOutput)
	{
		strErrorWindowOutput = '';
	}

	// Assume it is true for th elements that don't validate
	blnIsValid = true;	

	// If the element is not displayed for some reason, we don't want to validate it
	if (theElement.style.display == 'none')
	{
		strValidator = '';
	}
	
	// If the element is not enabled, we don't want to validate it.
	if (theElement.enabled == false || theElement.disabled == true)
	{
		strValidator = '';
	}

	// If there is a validator (even after previous test), do the validation
	if (strValidator)
	{
		// Get the element and English name (if there is one) to display
		strEnglishName = theElement.getAttribute("ErrorName");
		if (strEnglishName == null)
		{
			strEnglishName = theElement.getAttribute("name");
		}
		
		// Find out if this is a required field
		blnIsRequired = theElement.getAttribute('required');

		// See if we are validating another attribute
		if (theElement.getAttribute('validateAt') != null)
		{
			// Get the value of the element		
			strValue = processVal(theElement.getAttribute(theElement.getAttribute('validateAt')).toString());
		}
		else
		{
			// Get the value of the element		
			strValue = processVal(theElement.value);
		}		
		
		//alert(strValue);
		
		if (theElement.tagName != 'SELECT' && !theElement.multiple)
		{
			if (theElement.getAttribute('validateAt') != null)
			{
				theElement.setAttribute(theElement.getAttribute('validateAt'), strValue);
			}
			else
			{
				theElement.value = strValue;
			}
		}
		
		// Get the validator info
		strPattern  = objPatternsDict[strValidator];
		strPatternMessage = objPatternsMsg[strValidator];
		
		// Get the specific lengths
		intMinLength = theElement.getAttribute('MinimumLength');
		intMaxLength = theElement.getAttribute('MaximumLength');		
		
		// Determine if the value is valid
		if (strPattern == null)
		{
			strPatternMessage = 'Selected validation pattern is invalid.';
			blnIsValid = false;
		}
		else
		{
			if (strValidator != 'Password' && strValidator != 'StrictPassword')
			{
				//alert(strValidator + ' - ' + strPattern + ' = ' + strValue + ' - ' + strPattern.test(strValue));
				blnIsValid = strPattern.test(strValue);
			}
		}

		//alert('Ename - ' + strEnglishName);
		//alert('name - ' + theElement.getAttribute("name"));
		//alert('val - ' + strValue);
		//alert('patt - ' + strPattern);
		//alert(Number(ScriptEngineMajorVersion() + "." + ScriptEngineMinorVersion()));
		//alert('valid - ' + blnIsValid);
		//alert('req - ' + blnIsRequired);
		//alert(intMinLength);
		//alert(intMaxLength);

		// We have validated that the format of the date field is correct, now lets
		//	make sure that the value is a valid date	  
		if (strValidator == "Date" || strValidator == "Date8" || strValidator == "Date10" || strValidator == "DateBoth" || strValidator == "QuarterlyDate")
		{
			// We are checking a date, so make sure the value isn't empty
			if (strValue.length != 0)
			{
				// It's not empty, so check and update the validity
				try
				{

					blnIsValid = blnIsValid && isDate(strValue);
				}
				catch(e)
				{
					alert('dateutils.js was not included.');
					blnIsValid = false;
				}
				
				if (blnIsValid)
				{
					if (theElement.getAttribute('ForceLessThan') != null)
					{
						var OtherElement = document.getElementById(theElement.getAttribute('ForceLessThan'));
						if (validateElementSilent(OtherElement, false, false, false))
						{
							var FirstDate = new Date(FixDatesYear(strValue));
							var SecondDate = new Date(FixDatesYear(OtherElement.value));
							if (FirstDate >= SecondDate)
							{
								blnIsValid = false;
								strPatternMessage = 'The ' + strEnglishName + ' field value must come before the ' + OtherElement.getAttribute('ErrorName') + ' field value.';
							}
						}
					}
				}

				if (blnIsValid)
				{
					if (theElement.getAttribute('ForceLessThanDate') != null)
					{
						var FirstDate = new Date(FixDatesYear(strValue));
						var SecondDate = new Date(theElement.getAttribute('ForceLessThanDate'));
						if (FirstDate >= SecondDate)
						{
							blnIsValid = false;
							strPatternMessage = 'The ' + strEnglishName + ' field value must come before ' + theElement.getAttribute('ForceLessThanDate') + '.';
						}
					}
				}
				
				if (blnIsValid)
				{
					if (theElement.getAttribute('ForceGreaterThan') != null)
					{
						var OtherElement = document.getElementById(theElement.getAttribute('ForceGreaterThan'));
						if (validateElementSilent(OtherElement, false, false, false))
						{
							var FirstDate = new Date(FixDatesYear(strValue));
							var SecondDate = new Date(OtherElement.value);
							if (FirstDate <= SecondDate)
							{
								blnIsValid = false;
								strPatternMessage = 'The ' + strEnglishName + ' field value must come after the ' + OtherElement.getAttribute('ErrorName') + ' field value.';
							}
						}
					}
				}

				if (blnIsValid)
				{
					if (theElement.getAttribute('ForceGreaterThanDate') != null)
					{
						var FirstDate = new Date(FixDatesYear(strValue));
						var SecondDate = new Date(theElement.getAttribute('ForceGreaterThanDate'));
						if (FirstDate <= SecondDate)
						{
							blnIsValid = false;
							strPatternMessage = 'The ' + strEnglishName + ' field value must come after ' + theElement.getAttribute('ForceGreaterThanDate') + '.';
						}
					}
				}

				if (blnIsValid)
				{
					if (theElement.getAttribute('ForceLessEqualThan') != null)
					{
						var OtherElement = document.getElementById(theElement.getAttribute('ForceLessEqualThan'));
						if (validateElementSilent(OtherElement, false, false, false))
						{
							var FirstDate = new Date(FixDatesYear(strValue));
							var SecondDate = new Date(OtherElement.value);
							if (FirstDate > SecondDate)
							{
								blnIsValid = false;
								strPatternMessage = 'The ' + strEnglishName + ' field value must be equal to or come before the ' + OtherElement.getAttribute('ErrorName') + ' field value.';
							}
						}
					}
				}

				if (blnIsValid)
				{
					if (theElement.getAttribute('ForceLessEqualThanDate') != null)
					{
						var FirstDate = new Date(FixDatesYear(strValue));
						var SecondDate = new Date(theElement.getAttribute('ForceLessEqualThanDate'));
						if (FirstDate > SecondDate)
						{
							blnIsValid = false;
							strPatternMessage = 'The ' + strEnglishName + ' field value must be equal to or come before ' + theElement.getAttribute('ForceLessEqualThanDate') + '.';
						}
					}
				}
				
				if (blnIsValid)
				{
					if (theElement.getAttribute('ForceGreaterEqualThan') != null)
					{
						var OtherElement = document.getElementById(theElement.getAttribute('ForceGreaterEqualThan'));
						if (validateElementSilent(OtherElement, false, false, false))
						{
							var FirstDate = new Date(FixDatesYear(strValue));
							var SecondDate = new Date(OtherElement.value);
							if (FirstDate < SecondDate)
							{
								blnIsValid = false;
								strPatternMessage = 'The ' + strEnglishName + ' field value must be equal to or come after the ' + OtherElement.getAttribute('ErrorName') + ' field value.';
							}
						}
					}
				}

				if (blnIsValid)
				{
					if (theElement.getAttribute('ForceGreaterEqualThanDate') != null)
					{
						var FirstDate = new Date(FixDatesYear(strValue));
						var SecondDate = new Date(theElement.getAttribute('ForceGreaterEqualThanDate'));
						if (FirstDate < SecondDate)
						{
							blnIsValid = false;
							strPatternMessage = 'The ' + strEnglishName + ' field value must be equal to or come after ' + theElement.getAttribute('ForceGreaterEqualThanDate') + '.';
						}
					}
				}
			}
			
			if(strValidator == 'QuarterlyDate')
			{
				var theTestDate = new Date(FixDatesYear(strValue));
				blnIsValid = (((theTestDate.getMonth() == 0) || (theTestDate.getMonth() == 3) || (theTestDate.getMonth() == 6) || (theTestDate.getMonth() == 9)) && (theTestDate.getDate() == 1))
			}
		} // if (strValidator = "Date"
		
		// Can't get the regular expression working for this, so I'll code it manually.
		if (strValidator == 'StrictPassword')
		{
			// Assume the password is correct
			blnIsValid = true;
			
			// Set the variable to check for size
			intMinLength = 6;
			intMaxLength = 25;

			// Use a RegEx to test if there are any lower case chars
			strPattern  = objPatternsDict['LowerCase'];
			if (!strPattern.test(strValue))
			{
				blnIsValid = false;
			}

			// Use a RegEx to test if there are any upper case chars
			//strPattern  = objPatternsDict['UpperCase'];
			//if (!strPattern.test(strValue))
			//{
			//	blnIsValid = false;
			//}

			// Use a RegEx to test if there are numbers 
			strPattern  = objPatternsDict['Number'];
			if (!strPattern.test(strValue))
			{
				blnIsValid = false;
			}
			
			// Now check if we are doing a confirm
			if (blnIsValid)
			{
				if (theElement.getAttribute('ConfirmPassword') != null)
				{
					var OtherElement = document.getElementById(theElement.getAttribute('ConfirmPassword'));
					if (validateElementSilent(OtherElement, false, false, false))
					{
						if (OtherElement.value != strValue)
						{
							blnIsValid = false;
							strPatternMessage = '.  <b><FONT color=red>Passwords do not match.</FONT><B>';
						}
					}
				}
			}
			
			// Now see if CompareName1 needs processing
			if (blnIsValid)
			{
				if (theElement.getAttribute('CompareName1') != null)
				{
					var CompareName = document.getElementById(theElement.getAttribute('CompareName1'));
					var strTempValue = theElement.value.toLowerCase();
					var strTempCompare = CompareName.value.toLowerCase();
					if (strTempCompare.length != 0)
					{
						if (strTempValue.indexOf(strTempCompare) != -1)
						{
							blnIsValid = false;
							strPatternMessage = '. <B><FONT color=red>Password contains your first name.</FONT></B>';
						}
					}
				}
			}

			// Now see if CompareName2 needs processing
			if (blnIsValid)
			{
				if (theElement.getAttribute('CompareName2') != null)
				{
					var CompareName = document.getElementById(theElement.getAttribute('CompareName2'));
					var strTempValue = theElement.value.toLowerCase();
					var strTempCompare = CompareName.value.toLowerCase();
					if (strTempCompare.length != 0)
					{
						if (strTempValue.indexOf(strTempCompare) != -1)
						{
							blnIsValid = false;
							strPatternMessage = '. <B><FONT color=red>Password contains your last name.</FONT></B>';
						}
					}
				}
			}
		}
		
		// Percentage validation is a little special
		if (strValidator == 'Percentage')
		{
			if (parseInt(strValue, 10) < 0 || parseInt(strValue, 10) > 100)
			{
				blnIsValid = false;
			}
		}
		
		// Allow neg in decimals and currency
		if (strValidator == "Decimal" || strValidator == "Currency")
		{		
			// Check if the drop down can allow negative values
			blnAllowNeg = eval(theElement.getAttribute('AllowNegative'));

			if (blnAllowNeg == null)
			{
				blnAllowNeg = false;
			}
			
			if (!blnAllowNeg)
			{
				// We can't allow negative numbers, so check if it is
				if (strValue.substring(0, 1) == '-')
				{
					// It is, so invalidate
					blnIsValid = false;
				}
			}
		}


		// Drop down validation are a little special, so check if this is drop down
		if (strValidator == "DropDown")
		{
			// Check if the drop down can allow negative values
			blnAllowNeg = eval(theElement.getAttribute('AllowNegative'));
			if (blnAllowNeg == null)
			{
				blnAllowNeg = false;
			}
			
			if (!blnAllowNeg)
			{
			
				// We can't allow negative numbers, so check if it is
				if (strValue.substring(0, 1) == '-')
				{
				
					// It is, so invalidate
					blnIsValid = false;
					
				}
			}

			// Check if the drop down can allow zero (added 1/13/03 MSH)
			blnAllowZero = eval(theElement.getAttribute('AllowZero'));
			if (blnAllowZero == null)
			{
				blnAllowZero = false;
			}
			
			if (!blnAllowZero)
			{
				// We can't allow zero, so check if it is
				if (strValue == '0')
				{
					// It is, so invalidate
					blnIsValid = false;
				}
			}
		}

		// If this is a number, we need to test for ForceGreaterThanNumber, etc
		if (strValidator == 'Numeric')
		{
			if (blnIsValid)
			{
				if (theElement.getAttribute('ForceGreaterThanNumber') != null)
				{
					if (parseInt(strValue,10) <= parseInt(theElement.getAttribute('ForceGreaterThanNumber'),10))
					{
						blnIsValid = false;
						strPatternMessage = 'The ' + strEnglishName + ' field value must be greater than ' + theElement.getAttribute('ForceGreaterThanNumber') + '.';
					}
				}
			}
			if (blnIsValid)
			{
				if (theElement.getAttribute('ForceGreaterEqualThanNumber') != null)
				{
					if (parseInt(strValue,10) < parseInt(theElement.getAttribute('ForceGreaterThanNumber'),10))
					{
						blnIsValid = false;
						strPatternMessage = 'The ' + strEnglishName + ' field value must be greater than or equal to ' + theElement.getAttribute('ForceGreaterEqualThanNumber') + '.';
					}
				}
			}
			if (blnIsValid)
			{
				if (theElement.getAttribute('ForceLessThanNumber') != null)
				{
					if (parseInt(strValue,10) >= parseInt(theElement.getAttribute('ForceLessThanNumber'),10))
					{
						blnIsValid = false;
						strPatternMessage = 'The ' + strEnglishName + ' field value must be less than ' + theElement.getAttribute('ForceLessThanNumber') + '.';
					}
				}
			}
			if (blnIsValid)
			{
				if (theElement.getAttribute('ForceLessEqualThanNumber') != null)
				{
					if (parseInt(strValue,10) > parseInt(theElement.getAttribute('ForceLessThanNumber'),10))
					{
						blnIsValid = false;
						strPatternMessage = 'The ' + strEnglishName + ' field value must be less than or equal to ' + theElement.getAttribute('ForceLessEqualThanNumber') + '.';
					}
				}
			}

			if (blnIsValid)
			{
				if (theElement.getAttribute('ForceGreaterThan') != null)
				{
					var OtherElement = document.getElementById(theElement.getAttribute('ForceGreaterThan'))
					if (parseInt(strValue,10) <= parseInt(OtherElement.value,10))
					{
						blnIsValid = false;
						strPatternMessage = 'The ' + strEnglishName + ' field value must be greater than ' + OtherElement.getAttribute('ErrorName') + '.';
					}
				}
			}
			if (blnIsValid)
			{
				if (theElement.getAttribute('ForceGreaterEqualThan') != null)
				{
					var OtherElement = document.getElementById(theElement.getAttribute('ForceGreaterEqualThan'))
					if (parseInt(strValue,10) < parseInt(OtherElement.value,10))
					{
						blnIsValid = false;
						strPatternMessage = 'The ' + strEnglishName + ' field value must be greater than or equal to ' + OtherElement.getAttribute('ErrorName') + '.';
					}
				}
			}
			if (blnIsValid)
			{
				if (theElement.getAttribute('ForceLessThan') != null)
				{
					var OtherElement = document.getElementById(theElement.getAttribute('ForceLessThan'))
					if (parseInt(strValue,10) >= parseInt(OtherElement.value,10))
					{
						blnIsValid = false;
						strPatternMessage = 'The ' + strEnglishName + ' field value must be less than ' + OtherElement.getAttribute('ErrorName') + '.';
					}
				}
			}
			if (blnIsValid)
			{
				if (theElement.getAttribute('ForceLessEqualThan') != null)
				{
					var OtherElement = document.getElementById(theElement.getAttribute('ForceLessEqualThan'))
					if (parseInt(strValue,10) > parseInt(OtherElement.value,10))
					{
						blnIsValid = false;
						strPatternMessage = 'The ' + strEnglishName + ' field value must be less than or equal to ' + OtherElement.getAttribute('ErrorName') + '.';
					}
				}
			}
		}

		// See if we need to valid min length
		if (intMinLength != null)
		{
			if (strValue.length < intMinLength)
			{
				blnIsValid = false;
			}
		}
		
		// See if we need to validate max length
		if (intMaxLength != null)
		{
			if (strValue.length > intMaxLength)
			{
				blnIsValid = false;
			}
		}
		

		// Now we want to see if it's a required field.
		if (blnIsRequired != null)
		{
			// It is a required field, so check if it's blank
			if (strValue.length == 0)
			{
				// It's blank, so invalidate it.
				blnIsValid = false;
			}
		}
		else
		{
			// It's not required, so check if it's blank
			if (strValue.length == 0)
			{
				// It's blank, so we don't want it to be invalid
				blnIsValid = true;
			}
		}

		// We've done all the checking. Continue if this is valid								
		if (!blnIsValid)
		{
			if (blnWriteToOutput)
			{
				AddError(theElement, '', strEnglishName, blnIsRequired, strPatternMessage, intMinLength, intMaxLength);
			}
		}
	} // if strValidator

	// Check if we are returning this immediately
	if (blnImmediateOutput)
	{
		// OK. We want to display now, so check if there were errors
		if (strErrorWindowOutput != "")
		{
			// There were errors, so call showErrors
			DisplayErrors();
		}
	}
	
	
	return blnIsValid;
}

function DisplayErrors()
{
	if (strErrorWindowOutput.length != 0)
	{
		winShowErrors = openDialog("/admin/SystemMsg/ErrorReport.asp", null, "center:yes; help:no; resizable:no; scroll: yes; status:no; dialogWidth:350px; dialogHeight:280px");
	}
}

function processVal(strFormValue)
{
	while(strFormValue.charAt(0) == " ")
	{
		strFormValue = strFormValue.substring(1,strFormValue.length); 
	}
	while(strFormValue.charAt(strFormValue.length-1) == " ")
	{
		strFormValue = strFormValue.substring(0,strFormValue.length-1); 
	}
	return strFormValue
}

function AddError(theElement, strFunction, strEnglishName, blnIsRequired, strPatternMessage, intMinLength, intMaxLength)
{
	switch (arguments.length)
	{
		case 1:
			strFunction = '';
		case 2:
			strEnglishName = theElement.getAttribute("ErrorName");
			if (strEnglishName == null)
			{
				strEnglishName = theElement.getAttribute("name");
			}
		case 3:
			blnIsRequired = theElement.getAttribute("required");
		case 4:
			strPatternMessage = objPatternsMsg[theElement.getAttribute("validator")];
		case 5:
			intMinLength = null;
		case 6:
			intMaxLength = null;
	}

	strErrorWindowOutput += '<LI>' + strEnglishName.bold() + '<BR>&nbsp;&nbsp;&nbsp;&nbsp;';
	if (blnIsRequired != null)
	{
		strErrorWindowOutput += '(This field is required and may not be left blank)&nbsp;';
	}

	if (intMinLength != null || intMaxLength != null)
	{
		strErrorWindowOutput += 'The length of this field must be ';
		if (intMinLength == intMaxLength)
		{
			strErrorWindowOutput += 'exactly ' + intMinLength;
		}
		else
		{
			if (intMinLength != null)
			{
				strErrorWindowOutput += 'a minimum of ' + intMinLength;
			}
			if (intMinLength != null && intMaxLength != null)
			{
				strErrorWindowOutput += ' and ';
			}
			if (intMaxLength != null)
			{
				strErrorWindowOutput += 'a maximum of ' + intMaxLength;
			}
		}
		strErrorWindowOutput += ' character(s).&nbsp;';
	}

	strErrorWindowOutput += strPatternMessage + '<BR></LI><BR>';
	
	if (strFunction != '')
	{
		strErrorWindowOutput += '<A HREF="#" OnClick="javascript:' + strFunction + '">';
	}
	else
	{
		strErrorWindowOutput += '<A HREF="#" OnClick="javascript:fncGoToErr(\'' + theElement.getAttribute("name") + '\')">';
	}
	strErrorWindowOutput += 'Go to this Item &gt;&gt;</A><BR><BR>';
}


function isElement(vElement){
	/*'***************************************************************	
		'* Program: 				isElement()
		'*
		'* Created By/Date:	James Laughlin 4/4/2002
		'*
		'* Purpose: 				This function loops through the forms
		'*									on a page and checks to see if the passed
		'*									in value is one of the elements on that page
		'*
		'* Return Value:		Boolean
		'*
		'* Input Parameters:	vElement - the name of the element that you
		'*										are looking for
		'*				
		'* Modified:	Person / Date / Reason:
		'*	
		'******************************************************************/

	var bRetVal, strElement, strForm
	
	bRetVal = false
	
	for(strForm in document.forms){
		// loop on the forms collection...
		if (strForm != 'length'){
			//only do this if this is not the 'length'
			for (strElement in documentForms(strForm)){
				//loop through the elements in this form
				if (strElement == vElement){
					//we found the element...return true.
					return true
				}
			}
		}
	}
	//found no such element...returning false
	return false
}

/*'**************************************************************************
'* Program:	validateMTabForm
'*
'* Created By/Date:	Michael Howard - 1/13/2003
'*
'* Purpose: To perform standard validation checks on a form that includes
'*					hidden tabs.
'*
'* Return Value:		boolean - true if validation is passed, false otherwise 
'*
'* Input Parameters:
'*
'*		theForm - string identifying the name attribute assigned
'*									 to the radio buttons in question
'*
'*		blnImmediateOutput - boolean indicating if error dialog should be
'*												 immediately displayed or if DisplayErrors
'*												 will be explicitly called later to allow for
'*												 custom validation.
'*
'*	Notes:
'*		This function is merely a copy of the standard 'validateForm' function
'*		modified to have the error dialog display the appropriate tab before
'*		attempting to set focus on the element to which the error is related.
'*		This was done to avoid modifying '\systemMsg\errorReport.asp'.  If
'*		this manner of implementing tabs is adopted by additional developers,
'*		modifying 'errorReport.asp' might be considered.
'*****************************************************************************/
function validateMTabForm(theForm, blnImmediateOutput)
{
	var arrFormElements = theForm.elements; 
	var blnIsValid, blnIsValidTemp;
	var intCounter;
	
	
	if (arguments.length == 1)
	{
		blnImmediateOutput = true;
	}

	blnIsValid = true;
	
	strErrorWindowOutput = '';
	
	for (intCounter = 0; intCounter < arrFormElements.length; intCounter++)
	{
		blnIsValidTemp = validateElementSilent(arrFormElements[intCounter], false, false);

		if (!blnIsValidTemp)
		{
			AddError(arrFormElements[intCounter], strTabFormGoToErrorFunction(arrFormElements[intCounter].id));
		}
		
		blnIsValid = blnIsValid && blnIsValidTemp;
	}

	// Check if we are returning this immediately
	if (blnImmediateOutput)
	{
		// OK. We want to display now, so check if there were errors
		if (strErrorWindowOutput != "")
		{
			// There were errors, so call showErrors
			DisplayErrors();
		}
	}
	return blnIsValid;

}//end function validateMTabForm

/*'**************************************************************************
'* Program:	strTabFormGoToErrorFunction
'*
'* Created By/Date:	Michael Howard - 1/13/2003
'*
'* Purpose: Returns text of function passed to AddError function when using
'*					a tabbed form.  This block of code activates the appropriate tab
'*					before attempting to set focus on the error element
'*
'* Return Value:		String 
'*
'* Input Parameters:  strElementID - string identifying the element to which
'*																	 the error relates
'*
'* Note:		This code	assumes that the tab row (TR) identifies its
'*					corresponding tab	label (TD) with a non-standard attribute of
'*					'tablabelid'.
'*
'*****************************************************************************/
function strTabFormGoToErrorFunction(strElementID) {

	return	'var objGoTo = dialogArguments.document.getElementById(\'' + strElementID + '\'); ' +
					'var objTabSearch = objGoTo.parentElement; ' +
					'while (objTabSearch.tagName != \'BODY\') {' +
						'var strTabLabelID = objTabSearch.getAttribute(\'tablabelid\'); ' +
						'if (strTabLabelID != null) { ' +
							'dialogArguments.document.getElementById(strTabLabelID).click(); ' +
						'} ' +
						'objTabSearch = objTabSearch.parentElement; ' +
					'} ' +
					'objGoTo.focus(); ' +
					'window.close();';

}//end function strTabFormGoToErrorFunction

/*'**************************************************************************
'* Program:	CheckRequiredRadioGroup
'*
'* Created By/Date:	Michael Howard - 1/13/2003
'*
'* Purpose: To add an error as part of a validation routine if the
'*					one of the radio buttons of the specified radio button
'*					group (strRadioName) has not been checked.
'*
'* Return Value:		NONE 
'*
'* Input Parameters:
'*
'*		strRadioName - string identifying the name attribute assigned
'*									 to the radio buttons in question
'*
'*		errorName - string denoting the description of the error that
'*								will be displayed on the error dialog box
'*
'*****************************************************************************/
function CheckRequiredRadioGroup(strRadioName, errorName)
{
	var rdoCalcTypes = document.getElementsByName(strRadioName);
	var blnReturn = false;
			
	for (intCounter = 0; intCounter < rdoCalcTypes.length; intCounter++)
	{
		if (rdoCalcTypes[intCounter].checked) {
			blnReturn = true;
			break;
		}
	}
				
	if (!blnReturn) {
		AddError(rdoCalcTypes[0], strTabFormGoToErrorFunction(rdoCalcTypes[0].id), errorName, true, '');
	}
		
	return blnReturn;
}// end function CheckRequiredRadioGroup


/*******************************************************************************
** Pattern and Message Library
*******************************************************************************/
var objPatternsDict = new Object();
var objPatternsMsg = new Object();

//objPatternsDict.AlphaNum = /^\w|\s+$/i;
objPatternsDict.AlphaNum = /^[\w\W]+$/i;
objPatternsMsg.AlphaNum = 'This field must contain alphanumeric data.&nbsp;&nbsp;Example:  &quot;75th Cavalry&quot;';

///<(.*)>.*<\/\1>/
objPatternsDict.AlphaNumNoHTML = /^[a-zA-Z0-9_]*[^<]*[a-zA-Z0-9_]*[^>]*[a-zA-Z0-9_]*$/
objPatternsMsg.AlphaNumNoHTML = 'This field must contain alphanumeric data.&nbsp;&nbsp;HTML tags are not permitted.&nbsp;&nbsp;Example:  &quot;75th Cavalry&quot;';

objPatternsDict.AreaCode = /^\d{3}$/;
objPatternsMsg.AreaCode = 'This area code field must contain only numeric data only.&nbsp;&nbsp;Example:  &quot;512&quot;';

objPatternsDict.Blank = /\w+/i;
objPatternsMsg.Blank = '';

//objPatternsDict.Currency = /^\d{0,3}(\d{3})*\.\d{2}$/;
// ^(([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{2}))?|([1-9]{1}[0-9]{0,}(\.[0-9]{2}))?|(0(\.[0-9]{2}))?|((\.[0-9]{2}))?)$
objPatternsDict.Currency = /^(([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{2}))?|([1-9]{1}[0-9]{0,}(\.[0-9]{2}))?|(0(\.[0-9]{2}))?|((\.[0-9]{2}))?)$/;
objPatternsMsg.Currency = 'This currency field may contain numeric data ending with two decimal places.&nbsp;&nbsp;Example:  &quot;1,900.00&quot; or &quot;9,030,050.25&quot;';

objPatternsDict.Decimal = /^[-+]?\d+(\.\d+)?$/;
objPatternsMsg.Decimal = 'This decimal field may contain numeric data ending with zero or more decimal places.&nbsp;&nbsp;Example:  &quot;4.0&quot; or &quot;1234.5678&quot;';

objPatternsDict.GPA = /^\d{1,2}(\.\d*)?$/;
objPatternsMsg.GPA = 'This G.P.A. field may contain numeric data with as many as two digits to the left and two digits to the right of a decimal point.&nbsp;&nbsp;Example:  &quot;4.0&quot; or &quot;12.34&quot; or &quot;4&quot;';  

objPatternsDict.Duration = /^\d*$/;
objPatternsMsg.Duration = 'This field must contain a duration.&nbsp;&nbsp;Example:  &quot;1 hr., 15 mins.&quot;';

objPatternsDict.LowerCase = /[a-z]/;
objPatternsDict.UpperCase = /[A-Z]/;
objPatternsDict.LowerUpperCase = /[a-zA-Z]/;
objPatternsDict.Number = /\d/;

objPatternsDict.StrictPassword = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,25}$/;
objPatternsMsg.StrictPassword = 'This password field must contain a valid password.  A valid password must contain one or more letters and one or more numbers.&nbsp; A valid password can not contain your first or last name.&nbsp;&nbsp;Example: &quot;Password1&quot;';

objPatternsDict.Date10 = /^\d{2}[/]\d{2}[/]\d{4}$/;
objPatternsMsg.Date10 = 'This date field must contain an 10-digit date formatted as in the example.&nbsp;&nbsp;Example:  &quot;01/05/1999&quot;';

objPatternsDict.Date8 = /^\d{2}[/]\d{2}[/]\d{2}$/;
objPatternsMsg.Date8 = 'This date field must contain an 8-digit date formatted as in the example.&nbsp;&nbsp;Example:  &quot;01/05/99&quot;';

objPatternsDict.DateBoth = /^\d{1,}[/|-]\d{1,}[/|-](\d{2}|\d{4})$/;
objPatternsMsg.DateBoth = 'This date field must contain either an 8- or 10-digit date formatted as in the example.&nbsp;&nbsp;Example:  &quot;01/05/1999&quot; or &quot;1/5/99&quot; or &quot;01-05-1999&quot; or &quot;1-5-99&quot;';

objPatternsDict.Date = /^\d{1,}[/|-]\d{1,}[/|-](\d{2}|\d{4})$/;
objPatternsMsg.Date = 'This date field must contain either an 8- or 10-digit date formatted as in the example.&nbsp;&nbsp;Example:  &quot;01/05/1999&quot; or &quot;1/5/99&quot; or &quot;01-05-1999&quot; or &quot;1-5-99&quot;';

objPatternsDict.QuarterlyDate = /^\d{1,}[/|-]\d{1,}[/|-](\d{2}|\d{4})$/;
objPatternsMsg.QuarterlyDate = '<B><FONT color=red>This date must fall on the first day of a quarter.</FONT></B> This date field must contain either an 8- or 10-digit date formatted as in the example.&nbsp;&nbsp;Example:  &quot;01/01/1999&quot; or &quot;1/1/99&quot; or &quot;01-01-1999&quot; or &quot;1-1-99&quot;';

//objPatternsDict.Email = /^[a-z0-9_.]{2,}[@][a-z0-9_.]{2,}[.][a-z0-9]{2,}$/i;
objPatternsDict.Email = /^[a-z0-9_.\-]{2,}[@][a-z0-9_.\-]{2,}[.][a-z0-9]{2,}$/i;
objPatternsMsg.Email = 'This e-mail field must contain an address of at least 2 characters, a domain name of at least 2 characters and a domain suffix of at least 2 characters.  This field may also contain numerous sub-domains.&nbsp;&nbsp;Example:  &quot;user@website.com&quot; or &quot;first_last@city.state.us&quot; or &quot;first.last@unit.army.mil&quot;';

objPatternsDict.Numeric = /^\d*$/;
objPatternsMsg.Numeric = 'This numeric field must contain whole numbers only.&nbsp;&nbsp;Negative numbers are not allowed.&nbsp;&nbsp;Example:  &quot;250&quot;';

objPatternsDict.Percentage = /^\d*$/;
objPatternsMsg.Percentage = 'This percentage field must contain whole numbers only between 0 and 100.&nbsp;&nbsp;Example:  &quot;50&quot;';

//objPatternsDict.DropDown = /^[-]\d*$/;
objPatternsDict.DropDown = /^[a-zA-Z0-9\s.\-\{\}]+$/;
objPatternsMsg.DropDown = 'This drop down field must have a valid selection.';

objPatternsDict.Required = /./;
objPatternsMsg.Required = 'This field is required and may not be left blank.';

objPatternsDict.Telephone = /^([(]?\d{3}([)]|[-]))?\d{3}[-]\d{4}([x]\d{1,6})?$/;
objPatternsMsg.Telephone = '<br>This telephone number field must contain telephone number data only.  The area code is optional and the extension may be 1 to 6 digits long. Do not enter a space before the extension.<br><br><b>Examples</b><br>728-3500<br>728-3500x000000<br>(512)728-3500<br>(512)728-3500x000000';

objPatternsDict.Text = /^\D+[^\d]$/;
objPatternsMsg.Text = 'This text field must contain non-numeric data only.&nbsp;&nbsp;Example:  &quot;The quick brown fox.&quot;';

objPatternsDict.Time24 = /^\d{2}:\d{2}$/;
objPatternsMsg.Time24 = 'This time field may contain the time in 24-hour format.&nbsp;&nbsp;Example:  &quot;12:45&quot; or &quot;18:38&quot;';

objPatternsDict.Time12 = /^([0-1][0-9]|[2][0-3]):([0-5][0-9])\s[P,A][M]$/;
objPatternsMsg.Time12 = 'This time field may contain the time in 12-hour format.&nbsp;&nbsp;Example:  &quot;12:45&nbsp;PM&quot;';

objPatternsDict.Time = /^([0-1][0-9]|[2][0-3]):([0-5][0-9])\s[P,A][M]$/;
objPatternsMsg.Time = 'This time field may contain the time in 12-hour format.&nbsp;&nbsp;Example:  &quot;12:45&nbsp;PM&quot;';

objPatternsDict.Year = /^\d{4}$/;
objPatternsMsg.Year = 'This year field may contain four numeric characters.&nbsp;&nbsp;Example: &quot;2001&quot;';

objPatternsDict.ZipCode = /^\d{5}(-\d{4})?$/;
objPatternsMsg.ZipCode = 'This zip code field may contain numeric data formatted like the example.&nbsp;&nbsp;Example:  &quot;78671&quot; or &quot;78671-0034&quot;';

objPatternsDict.SSN = /^\d{3}-\d{2,3}-\d{3,4}$/;
objPatternsMsg.SSN = 'This SSN/SIN field must be formatted correctly. &nbsp;Example: &quot;123-45-6789&quot; or &quot;123-456-789&quot;.';

<!-- end hide -->