<!--
var iconclicked = "";
var stopPropagation = false;

function fncSaveForm(varShowAlert,varDoValidate)		// saves form	
{	if (fncSave(varShowAlert))						// If saving page (varShowAlert determinese wether to show user alert or not)
		if(!self.fncValidateForm || typeof varDoValidate != "undefined")					// If there is no page level validation
			document.forms[0].submit();		// Submit the form
		else if(fncValidateForm())					// If there is page level validation, allow it to trap
			document.forms[0].submit();		// If the page passes, submit the form, otherwise, form is not submitted (validate function will alert the user)	
}

function fncSave(varParam)						// Verifies that user wants to save changes
{	if(stopPropagation)
	{	stopPropagation = false;
		return false;
	}
	else
	{	if (fncAnyChanges())								// Check if there have been any changes to form data
		{	if (((typeof varParam != "undefined") && (varParam != "close")) || iconclicked.toLowerCase()=='save')			// If anything was passed as a parameter except "close" or save icon clicked
				return true;										//	Do not alert user and save page
			else	if (confirm("Do you want to save the changes made on this screen?"))		// Ask user to confirm save of changes
				return true;										//	Save page
		}		
		return false;										// Do not save the page		
	}
}

function fncAnyChanges(objForm)												// Verifies if there have been any fields edited
{	if (typeof objForm == "undefined")
		var oForm = document.forms[0];
	else
		var oForm = objForm;
	for (var e = 0; e < oForm.length; e++)										// For every form element
	{	if (oForm[e].id.substring(oForm[e].id.lastIndexOf("_") + 1,oForm[e].id.length) != "nonsaving")	// only check if form field is for saving
		{	var strOriginalValue = oForm[e].originalValue;				// Read original value			
			if (typeof strOriginalValue != "undefined")						// field must have a defined value to compare
			{	switch (oForm[e].type)													// Detect form field type
				{	case "checkbox": case "radio":	
						if(oForm[e].name != "ScreenCompleted" && oForm[e].name != "SubScreenCompleted")	{							// For checkbox	
						if (strOriginalValue != oForm[e].checked)			// Compare aganist the 'checked' property
							return true;															// If values are different, there has been a change, return true						
						}
						break;			
					case "hidden":															// Ignore hidden fields
						break;			
					case "select-one":
						if (oForm[e][0])
							if (oForm[e][0].originalSelectedIndex != oForm[e].selectedIndex)		// Create and set originalValue property value to field's 'selectedIndex' prorety value
								return true;
						break;
					case "select-multiple":
						for (var x = 0; x < oForm[e].length; x++)
							if (oForm[e][x].validSelected != oForm[e][x].selected)
								return true;						
						break;
					default:																		// For all other fields
						if (strOriginalValue != oForm[e].value)				// Compare current value with the property 'originalValue' (set by fncInitialFormValues)				
							return true;															// If values are different, there has been a change, return true					
						break;
				}			
			}
		}
	}
	var frames = window.frames;
	for (var i = 0; i < frames.length; i++) {
		if (window.frames[i].fncAnyChanges)
			if (window.frames[i].document.forms)
				if (window.frames[i].fncAnyChanges(window.frames[i].document.forms[0]))
					return true;
	}

	return false;
}

function fncInitialFormValues ()											// Sets new properties for all form fields - 'validValue' and 'originalValue'
{	var oForm = document.forms[0];
	for (var e = 0; e < oForm.length; e++)								// For every form element
	{	switch (oForm[e].type)													// Detect form type
		{	case "checkbox": case "radio":								// For checkbox				
				oForm[e].originalValue = oForm[e].checked;		// Create and set originalValue property value to field's 'checked' prorety value
				oForm[e].lastValue = oForm[e].checked;				// Create and set lastValue property value to field value
				break;			
			case "select": case "select-one": 
				oForm[e].validValue = oForm[e].value;				// Create and set validValue property value to field value
				oForm[e].lastValue = oForm[e].value;					// Create and set lastValue property value to field value
				oForm[e].originalValue = oForm[e].value;			// Create and set originalValue property value to field val
				oForm[e].validSelectedIndex = oForm[e].selectedIndex;				// Create and set validValue property value to field value
				oForm[e].lastSelectedIndex = oForm[e].selectedIndex;					// Create and set lastValue property value to field value				
				oForm[e].originalSelectedIndex = oForm[e].selectedIndex;			// Create and set originalValue property value to field val
				if (oForm[e][0])
				{	oForm[e][0].validValue = oForm[e].value;				// Create and set validValue property value to field value
					oForm[e][0].lastValue = oForm[e].value;					// Create and set lastValue property value to field value
					oForm[e][0].originalValue = oForm[e].value;			// Create and set originalValue property value to field val
					oForm[e][0].validSelectedIndex = oForm[e].selectedIndex;				// Create and set validValue property value to field value
					oForm[e][0].lastSelectedIndex = oForm[e].selectedIndex;					// Create and set lastValue property value to field value				
					oForm[e][0].originalSelectedIndex = oForm[e].selectedIndex;			// Create and set originalValue property value to field val
				}
				break;
			case "select-multiple":
				oForm[e].originalValue = "";
				for (var x = 0; x < oForm[e].length; x++)
				{	oForm[e][x].validSelected = oForm[e][x].selected;
					oForm[e][x].lastSelected = oForm[e][x].selected;
					oForm[e][x].originalSelected = oForm[e][x].selected;
					if (oForm[e][x].selected)
						oForm[e].originalValue = oForm[e].originalValue + "," +  oForm[e][x].value;			// Create and set originalValue property value to field value					
				}				
				if (oForm[e].originalValue.length > 0)
					oForm[e].originalValue = oForm[e].originalValue.substring(1,oForm[e].originalValue.length);
				break;
			default:																		// For all other fields
				oForm[e].validValue = oForm[e].value;				// Create and set validValue property value to field value
				oForm[e].lastValue = oForm[e].value;					// Create and set lastValue property value to field value
				oForm[e].originalValue = oForm[e].value;			// Create and set originalValue property value to field value								
				break;
		}			
	}																			// Assumes all values from the database are valid	
}

function fncDisable ()
{	for(var x = 0;x<document.forms.length;x++) 
		for(var y = 0;y<document.forms[x].elements.length;y++)
			if (document.forms[x].elements[y].type!="hidden")
				document.forms[x].elements[y].disabled = true;
}

function fncTrim (strString)
{	strString = strString + "";
	var i = 0;   
	var j = strString.length - 1;   
	var whitespace = " \t\n\r";
	for(var i = 0; i <= j; i++)
		if (whitespace.indexOf(strString.charAt(i)) == -1)
			break;
	if(i - 1 != j)
		while (whitespace.indexOf(strString.charAt(j)) != -1)
			j--;
	return strString.substring(i,j+1);
}

function validate(objField,strFieldType)						// Backwards compatibility with older function
{	return fncValidateField(objField,strFieldType); }

function fncValidateField(objField,strFieldType,strParam,strRange,strDefaultValue,intMaxLength)
{	stopPropagation = false;
	if(objField.name)															// if a form object is passed
	{	var strFieldValue = "" + objField.value;				// convert value to a string
		var bolObject = true;
	}
	else																				// a value is passed	
	{	var strFieldValue = "" + objField;							// convert value to a string
		var bolObject = false;
	}
	if (strFieldValue.match(/^[ ]+$/) == null)				// if value is not all spaces	
		strFieldValue = fncTrim(strFieldValue);			// Trim the value
	else
		strFieldValue = " ";												// make it one space
	var patComma = /,/g;
	switch (strFieldType)
	{	case "integer": case "float": case "currency":
			strFieldValue = strFieldValue.replace(patComma,"");
			if ((strFieldValue == "") || (strFieldValue == " ") || (!bolObject && isNaN(strFieldValue)))	// if we are doing an internal calculation (not an object) and isNaN
				strFieldValue = "0";			
			//if (typeof(intMaxLength) != "undefined")
				//if (strFieldValue.substring(0,1) == "-")
					//intMaxLength = intMaxLength - 1;
			if ((strFieldType == "float") && (strFieldValue.substring(strFieldValue.length - 1,strFieldValue.length) == "."))			
				strFieldValue = strFieldValue.substring(0,strFieldValue.length - 1);			
			break;			
		case "year": 
			if (strFieldValue == " ")
				strFieldValue = "";
			break;
		default:	//case "date": case "dob": case "zip": case "email": case "ssn":
			if (strFieldValue == "")
				strFieldValue = " ";
			break;
	}	
	var strMaskRegExp = "";										// initialize format mask for input
	var strValueRegExp = "";										// initialize value mask for input
	var strMaskMessage = "";									// initialize alert message when mask criteria isn't met	
	var strCustomMessage = "";
	if (strFieldType=="float")
		var strFieldLabel = "number";
	else
		var strFieldLabel = strFieldType;	
	switch(strFieldType)												// Define RegExp based on field type
	{	case "alphanumeric": 
			strMaskRegExp = /^[a-z 0-9]+$/i;				// matches a series of characters and numbers
			break;				
		/*
		case "address":
			strValueRegExp = /^((\ )|([a-zA-Z0-9,\s.\-']+))$/;	// matches a series of characters, integers, spaces, commas, apostophes, or dashes
			break;
		*/
		case "other":
			strMaskRegExp = /^((\ )|([a-zA-Z0-9,\s.\-\/]+))$/;	// matches a series of characters, integers, spaces, commas, apostophes, or dashes
			strCustomMessage = "Only the following characters are allowed: alphanumeric characters, commas, periods, forward slashes, or dashes";
			break;
		case "character":							
			strMaskRegExp = /^[ a-z]+$/i;						// matches a series of characters and spaces
			break;
		case "currency":
			strMaskRegExp = /^((\ )|(\$?-?([1-9]{1}[0-9]{0,2}(\,?[0-9]{3})*(\.[0-9]{1,2})?|[1-9]{1}[0-9]{0,}(\.[0-9]{1,2})?|0(\.[0-9]{1,2})?|(\.[0-9]{1,2})?)))$/;
			strMaskMessage = " in the format x,xxx,xxx.xx or xxxxxxx.xx or xxxxxxx";
			break;		
		case "date": case "dob":
			var strDelimiter = "(\\/|-|\\\|.)";																															  	// date delimiters
			var str31Months = "(0[13578]|1[02])";																													// months with 31 days
			var str31Days = "([0][1-9]|[1-2][0-9]|3[01])";																									// days up to 31
			var str31DayMonths = "(" + str31Months + strDelimiter + "?" +str31Days+ ")";												// US default	
			var strFebMonths = "(02)";																																		// February
			var strFebDays = "([0][1-9]|[1-2][0-9])";																												// days up to 29
			var strFebruary = "(" + strFebMonths + strDelimiter + "?" + strFebDays + ")";													// US default	
			var str30Months = "(0[469]|11)";																															// months with 30 days
			var str30Days = "([0][1-9]|[1-2][0-9]|30)";																										// days up to 30	
			var str30DayMonths = "(" + str30Months + strDelimiter + "?" + str30Days + ")";											// US default	
			var strYear = "(\\d{2}|\\d{4})";																																// year format
			var strTime = "(((0?[1-9]|1[012])(:[0-5]\\d){0,2}( [AP]M)))|(([01]\\d|2[0-3])(:[0-5]\\d){1,2})";				// time format
			var strBlank = "(\\ )";																																					// blank format
			var strStandardDate = "(((0?[1-9]|[1-2][0-9]|3[01])\\-(Jan|Mar|May|Jul|Aug|Oct|Dec))|((0?[1-9]|[1-2][0-9]|30)\\-(Apr|Jun|Sep|Nov))|((0?[1-9]|[1-2][0-9])\\-Feb))\\-" + strYear;	// univeral date format
			strMaskMessage = 	" in the format 03/09/74, 03/09/1974, 030974, 03091974, or 09-Mar-1974"			// US default message			
			if (typeof strDateFormat != "undefined")																													// if a datae format is defined
			{	if (strDateFormat == "UK")																																	// if date format is UK
				{	str31DayMonths = "(" + str31Days + strDelimiter + "?" +str31Months + ")";											// UK default date format for months with 31 days
					strFebruary = "(" + strFebDays + strDelimiter + "?" + strFebMonths + ")";													// UK default date format for February
					str30DayMonths = "(" + str30Days + strDelimiter + "?" + str30Months + ")";											// UK default date format for months with 30 days
					strMaskMessage = 	" in the format 09/03/74, 09/03/1974, 090374, 09031974, or 09-Mar-1974"	// UK deafult message				
				}
			}				
			strMaskRegExp = new RegExp("^(" + strBlank + "|\\d{6}|\\d{8}|(\\d{2}" + strDelimiter + "\\d{2}" + strDelimiter + strYear + ")|(\\d{1,2}\\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\-" + strYear + "))$","i");
			strValueRegExp = new RegExp("^(" + strBlank + "|((" + str31DayMonths + "|" + strFebruary + "|"	+ str30DayMonths + ")" + strDelimiter + "?" + strYear + ")|(" + strStandardDate + "))$","i");	//Case insensitive				
			break;								
		case "datetime":
			var strDelimiter = "(\\/|-|\\\|.)";																															  	// date delimiters
			var str31Months = "(0[13578]|1[02])";																													// months with 31 days
			var str31Days = "([0][1-9]|[1-2][0-9]|3[01])";																									// days up to 31
			var str31DayMonths = "(" + str31Months + strDelimiter + "?" +str31Days+ ")";												// US default	
			var strFebMonths = "(02)";																																		// February
			var strFebDays = "([0][1-9]|[1-2][0-9])";																												// days up to 29
			var strFebruary = "(" + strFebMonths + strDelimiter + "?" + strFebDays + ")";													// US default	
			var str30Months = "(0[469]|11)";																															// months with 30 days
			var str30Days = "([0][1-9]|[1-2][0-9]|30)";																										// days up to 30	
			var str30DayMonths = "(" + str30Months + strDelimiter + "?" + str30Days + ")";											// US default	
			var strYear = "(\\d{2}|\\d{4})";																																// year format
			var strTime = "(((0?[1-9]|1[012])(:[0-5]\\d){0,2}( [AP]M)))|(([01]\\d|2[0-3])(:[0-5]\\d){1,2})";				// time format
			var strBlank = "(\\ )";																																					// blank format
			var strStandardDate = "(((0?[1-9]|[1-2][0-9]|3[01])\\-(Jan|Mar|May|Jul|Aug|Oct|Dec))|((0?[1-9]|[1-2][0-9]|30)\\-(Apr|Jun|Sep|Nov))|((0?[1-9]|[1-2][0-9])\\-Feb))\\-" + strYear;	// univeral date format
			//strMaskMessage = 	" in the format 03/09/74, 03/09/1974, 030974, 03091974, or 09-Mar-1974"			// US default message			
			if (typeof strDateFormat != "undefined")																													// if a datae format is defined
			{	if (strDateFormat == "UK")																																	// if date format is UK
				{	str31DayMonths = "(" + str31Days + strDelimiter + "?" +str31Months + ")";											// UK default date format for months with 31 days
					strFebruary = "(" + strFebDays + strDelimiter + "?" + strFebMonths + ")";													// UK default date format for February
					str30DayMonths = "(" + str30Days + strDelimiter + "?" + str30Months + ")";											// UK default date format for months with 30 days
					//strMaskMessage = 	" in the format 09/03/74, 09/03/1974, 090374, 09031974, or 09-Mar-1974"	// UK deafult message				
				}
			}				
			strMaskRegExp = new RegExp("^(" + strBlank + "|\\d{6}|\\d{8}|(\\d{2}" + strDelimiter + "\\d{2}" + strDelimiter + strYear + ")|\\d{6}|\\d{8}|(\\d{2}" + strDelimiter + "\\d{2}" + strDelimiter + strYear + ")|(\\d{1,2}\\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\-" + strYear + ")|(\\d{1,2}\\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\-" + strYear + strBlank + strTime + "))$","i");
			strValueRegExp = new RegExp("^(" + strBlank + "|((" + str31DayMonths + "|" + strFebruary + "|"	+ str30DayMonths + ")" + strDelimiter + "?" + strYear + ")|((" + str31DayMonths + "|" + strFebruary + "|"	+ str30DayMonths + ")" + strDelimiter + "?" + strYear + strBlank + strTime + ")|(" + strStandardDate + ")|(" + strStandardDate + strBlank + strTime+ "))$","i");	//Case insensitive				
			strCustomMessage  = "Only Date or Date Times are allowed"
			break;								
		case "email":
			strMaskRegExp =  /^((\ )|(\S+@[^\.]\S*\.[a-zA-Z]{2,}))$/;
			strMaskMessage = 	" in the format AllOneWord@AllOneWord.atleast_2_characters"
			break;		
		case "float": case "temperature": case "percent":			
			strValueRegExp = /^((\ )|([-]?(([1-9]{1}[0-9]{0,2}\,\d{3}(\,\d{3})*(\.\d+)?)|([0-9]{1}(\.\d+)?)|((\.\d+)?)|([0-9]{1}\d+))(\.\d+)?))$/;	// matches a floting point number
			break;
		case "numeric month":
			strValueRegExp = /^((\ )|((([1-9]{1}[0-9]{0,2}\,\d{3}(\,\d{3})*(\.\d+)?)|([0-9]{1}(\.\d+)?)|((\.\d+)?)|([0-9]{1}\d+))(\.\d+)?))$/;	// matches a floting point number
			break;
		case "integer":								
			strValueRegExp = /^((\ )|0|(-?[1-9]\d{0,2}(((\,\d{3})+)|\d*)))$/;		// blank space|zero|any (negative or positive) integer not starting with zero with commas or without
			break;			
		case "positive integer":								
			strValueRegExp = /^((\ )|([1-9]\d{0,2}(((\,\d{3})+)|\d*)))$/;		// blank space|any positive integer not starting with zero with commas or without
			break;			
		case "numeric":								
			strValueRegExp = /^((\ )|\d*)$/;		// blank space|any positive integer or nothing 
			break;			
		case "mi":							
			strMaskRegExp = /^((\ )|([a-z]{1}))$/i;					// matches 1 character
			break;		
		/*
		case "percent":
			strMaskRegExp = /^((\ )|((0|[1-9]\d?(\.\d{1,2})?|100)))$/;		//[1-9][0-9]?$/;					// matches 1 character
			strMaskMessage = 	" with values from 0 to 100 with up to 2 decimal places (99.99)";
			break;		
		case "phone":	 case "fax": case "beeper":				
			strMaskRegExp =  /^((\ )|(((((1-|1)?([\(]\d{3}[\)]))|((1-|1)?\d{3}))?(-| )?([^0-1]){1}\d{2}(-| )?\d{4}((x|\ )\d{1,5})?))$/;
			strMaskMessage = 	" in the format 1(111)222-3333, 1-111-222-3333, 1113334444x55555";
			break;
		*/		
		case "phonewithareacodeau":
			strMaskRegExp =  /^(((\ )|((1\ |1-|1)?(([\(]\d{3}[\)])|(\d{3}))[-|\ ]?([^0-1]){1}\d{2}[-|\ ]?\d{4}((x|\ )\d{1,5})?)))|(((\ )|((1\ |1-|1)?(([\(]\d{2}[\)])|(\d{2}))[-|\ ]?([^0-1]){1}\d{3}[-|\ ]?\d{4}((x|\ )\d{1,5})?)))$/;
			strCustomMessage = "Only phone number with area code is allowed in formats like:\n1 (111) 222-3333, 111-222-3333, 1113334444x55555 or\n 1(01) 2222-3333, 01-2222-3333, 0133334444x55555";
			break;
		case "phonewithareacode":
			strMaskRegExp =  /^((\ )|((1\ |1-|1)?(([\(]\d{3}[\)])|(\d{3}))[-|\ ]?([^0-1]){1}\d{2}[-|\ ]?\d{4}((x|\ )\d{1,5})?))$/;
			strCustomMessage = "Only phone number with area code is allowed in formats like:\n1 (111) 222-3333, 111-222-3333, 1113334444x55555";
			break;
		case "search":
			strMaskRegExp = /^[\S ]+$/i;						// matches any non-whitespace character and spaces
			break;				
		case "ssn":
			strMaskRegExp = /^((\ )|(\d{3}[-]?\d{2}[-]?\d{4}))$/;
			strMaskMessage = " in the format DDD-DD-DDDD or DDDDDDDDD, where D is a digit";
			break;
		case "time":
			strMaskRegExp = /^((\ )|(((0?[1-9]|1[012])(:[0-5]\d){0,2}( [AP]M)))|(([01]\d|2[0-3])(:[0-5]\d){1,2}))$/;	// 12 or 24 hour format
			strMaskMessage = " in the format 11:59 PM, 11:59:59 PM, 23:59:59";
			break;					
		case "year":
			strMaskRegExp = /^((\d){4}|()|(\ ))$/;
			strMaskMessage = 	" in the format YYYY";
			break;			
		case "yearrange":
			strMaskRegExp = /^((\d){4}|(\d){4}-(\d){4}|(\ ))$/;
			strCustomMessage = "Must be in the format YYYY or YYYY-YYYY";
			break;
		case "zip":
			strMaskRegExp =  /^((\ )|((\d{5})|(\d{5}(-){1}\d{4})|([A-Z]\d[A-Z][ ]\d[A-Z]\d)))$/;
			strMaskMessage = 	" in the format 5 digit US ZIP (12345), 5 digit US ZIP+4 (12345-1234), or Canadian (A1A 1A1)";
			break;
		default:
	}				
	if (strMaskRegExp != "" && (strFieldValue.match(strMaskRegExp) == null))												// There is a mask set and check if matching the RegExp causes an error or not		
	{	if (strCustomMessage != "")																															// There is a custom message
			strMaskMessage = strCustomMessage;																									// Use it
		else																																									// Use default message
			strMaskMessage = "Only " + strFieldLabel + " values allowed" + strMaskMessage;
		return fncFailedMask (strFieldType,objField,strMaskMessage,strDefaultValue);									// failed to match mask: return false, send message to user, write last valid value, set focus to field			
	}
	else if (strFieldValue.match(strValueRegExp) == null)																					// passed through mask. Check if value RegExp matches		
		return fncFailedMask (strFieldType,objField,"This is not a valid " + strFieldLabel,strDefaultValue);		// failed to match value regexp: return false, send message to user, write last valid value, set focus to field				
	else																																									// passed through value regexp, now do further checks if needed	
	{	switch(strFieldType)
		{	case "currency": case "integer": case "float":				
				switch(strFieldType)
				{	case "currency": case "float":
						if (typeof strParam != "undefined")																					// if a parameter has been specified
							if (strParam != "nocomma")																							// if it is not this value
								strFieldValue = fncPrecision (strFieldValue,strParam);											// set precision of number							
						var intDecimalIndex = strFieldValue.indexOf(".");															// Find index of decimal
						if (intDecimalIndex != -1)																									// If there is a decimal
						{	var strTemp = strFieldValue.substring(0,intDecimalIndex);										// Get integer part of string
							var strDecimal = strFieldValue.substring(intDecimalIndex,strFieldValue.length);	// Get decimal part of string								
						}
						else																													
						{	var strTemp = strFieldValue;																						// Integer part of string is entire value
								var strDecimal = ""	//.00";																									// Set to the default decimal value
						}
						break;
					default:					
						var strTemp = strFieldValue;
						var strDecimal = "";	
						break;
				}
				if (strTemp.substr(0,1) == "-")
				{	var strSign = "-";
					strTemp = strTemp.substr(1);
				}
				else
					var strSign = "";					
				if (strTemp.length > 3 && strFieldValue.indexOf(",") == -1)															// If there are more than 3 significant digits and there are no commas
				{	var strNewValue = "";																													// used to accumulate comma delimited sections
					do																																					// since length of string is > 3
					{	strNewValue =  "," + strTemp.substring(strTemp.length - 3,strTemp.length) + strNewValue;	// Get digits to right of commas
						strTemp = strTemp.substring(0,strTemp.length - 3);																// Get digits to left of commas
					}	
					while (strTemp.length > 3)																											// only need commas on blocks of more than 3 digits
					strTemp = strTemp + strNewValue;																								// Last value to left of first comma plus all comma delimted groups of 3
				}
				strFieldValue = strSign + strTemp + strDecimal;																			// Final field value is nteger part plus decimal part
				if (typeof strRange != "undefined")																									// if a range has been specified
				{	if (strRange != "")
					{	var arBounds = strRange.split("-");
						var numLowerBound = arBounds[0] - 0;
						var numUpperBound = arBounds[1] - 0;
						if ((strFieldValue.replace(patComma,"") - 0 < numLowerBound) || (strFieldValue.replace(patComma,"") - 0 > numUpperBound))
							return fncFailedMask (strFieldType,objField,"Number must be between " + numLowerBound + " and " + numUpperBound,strDefaultValue);											// validation failed 					
					}
				}
				if (typeof strParam != "undefined")																									// if a parameter has been specified
					if (strParam == "nocomma")																											// if set to no commas
						strFieldValue = strFieldValue.replace(/,/g,"");																		// remove the commas
				break;					
			case "date": case "datetime": case "dob":				
				if (strFieldValue != " ")
				{	if ((strFieldValue.length < 6) || (strFieldValue.length == 7))
						return fncFailedMask (strFieldType,objField,"Only " + strFieldLabel + " values allowed" + strMaskMessage,strDefaultValue);
					var arMonth = new Array("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");	// set array of months
					var datDate = new Date();																												// current date
					var datFullYear = datDate.getFullYear();																						// current full year (4 digits)					
					var bolMonth = false;																														// initialize month in date to false
					var intMonth = -1;
					for (var x = 1; x < arMonth.length; x++)																						// search through month array
					{	if (strFieldValue.toLowerCase().indexOf(arMonth[x].toLowerCase()) > -1)																				// if a month is found in the date
						{	intMonth = x;
							bolMonth = true;																														// set to true
						}
					}
					if (bolMonth)																																	// if a month is in the date
					{	var arDate = strFieldValue.split("-");																						// split into array by "-"
						strDay = arDate[0];																													// day is the first value
						if (strDay.length == 1)																												
							strDay = "0" + strDay;																											// pad with leading zero
						strMonth = arMonth[intMonth];	//arDate[1];																												// month is the second value						
						strYear = arDate[2];																													// year is the last value
					}
					else																																					// numbers only in the date
					{	var strDelimiter = "";																													// initiallze delimenter to none
						var arDelimiters = new Array("/","\\","-",".");																			// set what Delimiters are allowed
						for (var x = 0; x < arDelimiters.length; x++)																			// search for Delimiter
							if (strFieldValue.indexOf(arDelimiters[x]) > -1)																	// if one is found
							{	strDelimiter = arDelimiters[x];																							// save the value
								break;																																	// end for loop
							}
						if (strDelimiter != "")																													// if there is a Delimiter
						{	var arDate = strFieldValue.split(strDelimiter);																	// split into array by Delimiter								
							strMonth = arDate[0];																											// month is the first value
							strDay = arDate[1];																												// day is the second value
							if (typeof strDateFormat != "undefined") {
								if (strDateFormat == "UK") {																							// UK formatted date
									strMonth = arDate[1];																									// month is the first value	
									strDay = arDate[0];																										// day is the second									
								}
							}
							if (strMonth.indexOf("0") == 0)																																								
								strMonth = strMonth.substring(1,2);																				// remove leading zero in month
							strMonth = arMonth[strMonth]																								// assign string month value using integer value						
							strYear = arDate[2];																												// year is the last value
						}					
						else																																				// if there are no Delimiters
						{	strDay = strFieldValue.substring(2,4);																				// day is the second value
							strMonth = strFieldValue.substring(0,2);																			// month is the first value							
							if (typeof strDateFormat != "undefined") {
								if (strDateFormat == "UK") {																							// UK formatted date
									strDay = strFieldValue.substring(0,2);																		// day is the second value
									strMonth = strFieldValue.substring(2,4);																	// month is the first value									
								}
							}
							if (strMonth.indexOf("0") == 0)																							// if month has a leading zero
								strMonth = strMonth.substring(1,2);																				// disregard it												
							strMonth = arMonth[strMonth];																							// Convert Month from a number to a word						
							strYear =  strFieldValue.substring(4,strFieldValue.length);												// year is the last value	
						}
					}
					if(!strYear)
						return fncFailedMask (strFieldType,objField,"Only " + strFieldLabel + " values allowed" + strMaskMessage,strDefaultValue);
			
					if (strYear.length == 2)																													// if year is 2-digit
						if (strYear >= 50)																														// determine century
							strYear = "19" + strYear;	//strYear = ((((datFullYear - 50) % 100) - strYear) * -1) + 100 + datFullYear - 50;						
						else
							strYear = "20" + strYear;					
					if ( !(((strYear % 4 == 0) && (strYear % 100 != 0)) || (strYear % 400 == 0)) && strDay == "29" && strMonth == "Feb")						// Check for leap year
						return fncFailedMask (strFieldType,objField,"A non-leap-year must have less than 29 days in February",strDefaultValue);					// Date 02/29/xxxx doesn't exist in a leap year so return false
					if (strFieldType == "dob")
						if ((datFullYear < strYear) || (datDate < Date.parse(strMonth + "/" + strDay + "/" + strYear)))
							strYear = strYear - 100;
					strFieldValue = strDay + "-" + strMonth + "-" + strYear;
					if ((strYear < 1753) || (strYear > 9999))																																							// SQL server's lower and upper bound
						return fncFailedMask (strFieldType,objField,"Only dates between 01-Jan-1753 and 31-Dec-9999 are allowed",strDefaultValue);		// Date is valid but in acceptable range
					if (typeof strRange != "undefined")																																										// if a range has been specified
					{	var datBound = strRange;																							
						switch (strParam)
						{	case ">":																															// date must be greater than strParam
								if (Date.parse(strFieldValue.replace(/-/g," ")) <= Date.parse(datBound.replace(/-/g," ")))
									return fncFailedMask (strFieldType,objField,"Date must be after " + datBound,strDefaultValue);	// validation failed	
								break;					
							case "<":																													// date must be less than strParam
								if (Date.parse(strFieldValue.replace(/-/g," ")) >= Date.parse(datBound.replace(/-/g," ")))
									return fncFailedMask (strFieldType,objField,"Date must be before " + datBound,strDefaultValue);			// validation failed
								break;
							case ">=":																															// date must be greater than strParam
								if (Date.parse(strFieldValue.replace(/-/g," ")) < Date.parse(datBound.replace(/-/g," ")))
									return fncFailedMask (strFieldType,objField,"Date must be on or after " + datBound,strDefaultValue);	// validation failed						
								break;
							case "<=":																													// date must be less than strParam
								if (Date.parse(strFieldValue.replace(/-/g," ")) > Date.parse(datBound.replace(/-/g," ")))
									return fncFailedMask (strFieldType,objField,"Date must be on or before " + datBound,strDefaultValue);			// validation failed												
								break;
						}
					}									
					switch (strMonth)
					{	case "Jan": objField.month = 1; break;
						case "Feb": objField.month = 2; break;
						case "Mar": objField.month = 3; break;
						case "Apr": objField.month = 4; break;
						case "May": objField.month = 5; break;
						case "Jun": objField.month = 6; break;
						case "Jul": objField.month = 7; break;
						case "Aug": objField.month = 8; break;
						case "Sep": objField.month = 9; break;
						case "Oct": objField.month = 10; break;
						case "Nov": objField.month = 11; break;
						case "Dec": objField.month = 12; break;
					}				
					objField.day = strDay;
					objField.year = strYear;
				}
				break;
			case "search":				
				if ((strFieldValue.match(/^in|and|or$/i) != null) || ((strFieldValue.match(/^[a-z{1}]$/i) != null) && (strFieldValue.length==1)))	// If value is "IN" or "AND" or "OR" or if value is a single letter
					return fncFailedMask (strFieldType,objField,"Single letters and \"and\", \"in\", and  \"or\" are not allowed",strDefaultValue);											// validation failed 
				break;
			case "temperature":
				if (strFieldValue.indexOf(".") > 0)																			// if there is a fractional part, we may need to round it
				{	if (parseFloat(strFieldValue) < 0)																			// if number is negative
						strFieldValue = parseFloat(strFieldValue) - .05 + "";									// subtract .05
					else																															// if number is positive
						strFieldValue = parseFloat(strFieldValue) + .05 + "";									// add .05						
					if (strFieldValue.indexOf(".") > 0)																		// if there is still a decimal
					{	if (strFieldValue.indexOf(".") < strFieldValue.length - 2)								// if there are at least two significant digits
							strFieldValue = strFieldValue.slice(0,strFieldValue.indexOf(".") + 2);	// truncate value to tenth place
					}
					else																															// there is no decimal, add one
						strFieldValue = strFieldValue + ".0";
				}				
				break;
			case "numeric month":
				if(parseFloat(strFieldValue) < 0.00 || parseFloat(strFieldValue) > 12.00)
					return fncFailedMask (strFieldType,objField,"Months must be between 0 and 12",strFailedValue);
		}
		if (typeof(intMaxLength) != "undefined")
		{	switch(strFieldType)
			{	case "currency": case "integer": case "float":	
					var strFieldLength = strFieldValue.replace(patComma,"").replace(/\./g,"");
					strFieldLength = strFieldLength.length;
					var strFailedValue = strDefaultValue;
					break;
				default:
					var strFieldLength = strFieldValue.length;
					var strFailedValue = strFieldValue.substr(0,intMaxLength);
			}
			if ((strFieldLength > intMaxLength) || ((strFieldValue.replace(patComma,"").replace(/\./g,"")).match(strValueRegExp)) == null)
				return fncFailedMask (strFieldType,objField,"Maximum length of " + intMaxLength + " has been exceeded",strFailedValue);												// failed to match value regexp: return false, send message to user, write last valid value, set focus to field
		}
		if(objField.name)
			fncUpdateFieldProperties (objField,strFieldValue);		
		else		
			return (strFieldValue);		
	}
	return true;															// allow events to continue
}

function fncUpdateFieldProperties (objField,strFieldValue)
{	switch (objField.type)													// Detect form type
	{	case "checkbox": case "radio":							// For checkbox							
			objField.lastValue = objField.checked;				// Create and set lastValue property value to field value			
			break;					
		case "select": case "select-one":
			objField.lastValue = objField.validValue;			// Create and set lastValue property value to field value
			objField.validValue = strFieldValue;					// Create and set validValue property value to field value	
			objField.value = strFieldValue;							// set Value property of field					
			objField.lastSelectedIndex = objField.validSelectedIndex;		// Create and set lastSelectedIndex property value to validSelectedIndex
			objField.validSelectedIndex = objField.selectedIndex;				// Create and set validSelectedIndex property value to selectedIndex	
			break;
		case "select-multiple":
			for (var x = 0; x < oForm[e].length; x++)				
			{	oForm[e][x].lastSelected = oForm[e][x].validselected;
				oForm[e][x].validSelected = oForm[e][x].selected;
			}
			break;
		default:																	// For all other fields
			objField.lastValue = objField.validValue;			// set lastValue property of field
			objField.validValue = strFieldValue;					// set validValue property of field			
			objField.value = strFieldValue;							// set Value property of field
			break;
	}	
}

function fncParse (strValue,strParse)
{	strValue = strValue + "";
	if (strParse)
		if (strParse == "float")
			return parseFloat(strValue.replace(/,/g,'').replace("$","").replace("£","")) - 0;
		else
			return parseInt(strValue.replace(/,/g,'').replace("$","").replace("£","")) - 0;
	else
		return parseFloat(strValue.replace(/,/g,'').replace("$","").replace("£","")) - 0;
}

function fncPrecision (strValue,intPrecision)
{	var strDecimal = "";
	strValue = fncParse(strValue,'float');				// assume number is type float
	if (typeof intPrecision == "undefined")				// if no precision is specified
		intPrecision = 0;											// assume there is none
	strValue = Math.round(strValue * Math.pow(10,intPrecision))/Math.pow(10,intPrecision);	// calculate number to desired precision
	strValue = strValue + "";									// convert to string
	var intDecimal = strValue.indexOf(".");			// find decimal
	if (intDecimal == -1)											// if there is no decimal
	{	for (var x = 0; x < intPrecision; x++)			// for the precison of the number 
			strDecimal = strDecimal + "0";				// add zeros
		if (strDecimal.length > 0)								// if there is a decimal part
			strValue = strValue + "." + strDecimal;	// append it to the number
	}		
	else																		// there is a decimal
	{	intLengthFraction = strValue.length - intDecimal - 1;	// 
		if (intLengthFraction < intPrecision)
			for (var x = 0; x < intPrecision - intLengthFraction; x++)
				strValue = strValue + "0";				
	}
	return strValue;
}

function fncFailedMask (strFieldType,objField,strMessage,strDefaultValue)
{	stopPropagation = true;		
	if (objField.name)													// if a field was validated (not ust a value)
	{	alert(strMessage + ".");										// Send alert	
		if (typeof strDefaultValue != "undefined" && strDefaultValue != "")		// if a default value has been specified			
		{	objField.lastValue = strDefaultValue;			// set lastValue property of field
			objField.validValue = strDefaultValue;			// set validValue property of field
			objField.value = strDefaultValue;					// set Value property of field
		}
		else
			objField.value = objField.validValue || ""		// set field value to previous valid value		
	}
	//objField.focus();													// set focus to field	
	return false;															// stop events when 'return' is first (i.e. onchange="return validate(this,'integer');")
}

// Author: Scott Horgen 
// Date: 1/19/04
//
// Description: fncRouteComments determines whether the current URL is being viewed in a frame 
//			    with a sibling frame containing comment information.  If a comment frame
//			    is detected then that frame is refreshed with a view of comments for the URL
//				passed to the function.
function fncRouteComments(redirectURL) {
	var tmpRedirectURL = redirectURL;
	var routeFound = false;
	var routeID = "";			
	var qStr = redirectURL.substring(1,redirectURL.length);
	var argsArray = qStr.split('&');
	var nameValue = "";
	for (var i = 0;(i < argsArray.length) && (routeFound == false);i++) {		
		nameValue = argsArray[i].split('=');
		if (nameValue[0] == "RoutedStepID") {
			routeFound = true;
			routeID = nameValue[1];
		}
	}	
	if (routeFound && (parent.frames.length > 0)) {			
		tmpReviewURL = "/messaging/review.asp?RouteStepID=" + routeID + "&RURL=" + tmpRedirectURL + "&comments=V0";
		parent.frames[0].location.href=tmpReviewURL;
	}	
	location.href=tmpRedirectURL;
}

	function fncRedirectToParent()
	{
		if (window.parent.location!=this.location)
		{	
			window.parent.document.location.href = window.parent.document.location;	
		}		
	}
	function fncLink (strLink)
	{	if (self.fncAnyChanges) 
			if (fncAnyChanges()) 
				if (confirm('Click \'OK\' to save your changes.')) 
				{	if (self.fncSaveForm) 
						fncSaveForm(false);
				} 
				else 
					location.href = strLink;
			else 
				location.href = strLink;
		else 
			location.href = strLink;
	}		
//Only IE supports innerText, so in order to achieve the same effect of innerText in other browsers
//use innerHTML first, then call ReplaceTags to strip out all the sub-tags	
function ReplaceTags(xStr){
	var regExp = /<\/?[^>]+>/gi;
	xStr = xStr.replace(regExp,"");
	return xStr;
}
// -->