var m_strValidationPrompt = new String('');
var m_aryDateComparisons = new Array();
var m_aryStringComparisons = new Array();
var m_aryNumericComparisons = new Array();
var m_aryNumericSum = new Array();
var m_datToday = new Date();

function DateComparer(p_objDateElement1, p_objDateElement2, p_strCompareOperator) {
	this.Date1 = p_objDateElement1;
	this.Date2 = p_objDateElement2;
	this.CompareOperator = p_strCompareOperator;
	this.CompareDates = fnCompareDateMethod;
}
function StringComparer(p_objStringElement1, p_objStringElement2, p_strCompareOperator) {
	this.String1 = p_objStringElement1;
	this.String2 = p_objStringElement2;
	this.CompareOperator = p_strCompareOperator;
	this.CompareStrings = fnCompareStringElements;
}
function NumericComparer(p_objStringElement1, p_objStringElement2, p_strCompareOperator) {
	this.Number1 = p_objStringElement1;
	this.Number2 = p_objStringElement2;
	this.CompareOperator = p_strCompareOperator;
	this.CompareNumbers = fnCompareNumberElements;
}
function NumericSum(p_objNumber, p_objSumToCompare, p_strCompareOperator, p_objFriendly) {
	this.Number1 = p_objNumber;
	this.Friendly = p_objFriendly;
	this.SumToCompare = p_objSumToCompare;
	this.CompareOperator = p_strCompareOperator;
	this.CompareSum = fnCompareNumericSum;
}
function fnEnableDisableAll(p_blnDisabled) {
	if (document.all) {
		for (var i=1; i < document.all.length; i++) {
			document.all(i).disabled = p_blnDisabled;
		} 
	} 
}
function fnLimitTextAreaEntry(p_objTextBox, p_intMaxLength) {
	var strValue = new String(p_objTextBox.value);
	if (strValue.length > parseInt(p_intMaxLength, 10)) {
		strValue = strValue.substr(0, parseInt(p_intMaxLength, 10));
		p_objTextBox.value = strValue;
	}
}
function openBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) {
	if(window.screen)if(isCenter)if(isCenter=="true"){
		var myLeft = (screen.width - myWidth)/2;
		var myTop = (screen.height - myHeight)/2;
		features += (features != '')?',':'';
		features += ',left='+ myLeft +',top='+ myTop;
	}
	window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

function highLiteOn(objId){
	objId.className = "highLight";
	objId.style.paddingTop = '0px';
	objId.style.paddingRight = '0px';
	objId.style.paddingBottom = '10px';
	objId.style.paddingLeft = '0px';
}

function highLiteOff(objId){
	objId.className = objId.getAttribute('t');
	objId.style.paddingTop = '0px';
	objId.style.paddingRight = '0px';
	objId.style.paddingBottom = '0px';
	objId.style.paddingLeft = '0px';
}

function checkFile(field, extensions) {
	var fileName = field.value.replace(/"/gi,'');
	if (!checkFileExtension(field, fileName, extensions)) {
		fnVAL_AddPromptLine('This file type is not allowed for uploading.\nOnly the following file extensions are allowed: ' + extensions + '.\nPlease select another file and try again.');
		field.focus();
		return false;
	}
	return true;
}

function checkFileExtension(field, fileName, extensions) {
	var blnValid = true;
	var re = new RegExp("\\.(" + extensions.replace(/,/gi,"|").replace(/\s/gi,"") + ")$","i");
	var agt = navigator.userAgent.toLowerCase();
	var is_mac = (agt.indexOf("mac") != -1);
	var is_op = (agt.indexOf("opera") != -1);
	if (is_op) {
		var ext = fileName.substring(fileName.lastIndexOf('.')+1, fileName.length);
		var extArr = extensions.split(',');
		var extCheck = false;
		for (var i = 0; i < extArr.length; i++) {
			if (extArr[i].toLowerCase() == ext.toLowerCase()) {
				extCheck = true;
				break;
			}
		}
		if (extCheck == false) {
			blnValid=false;
		}
	} else {
		if (!re.test(fileName)) {
			blnValid=false;
		}
	}
	return blnValid;
}
function fnSubmit() {
	document.forms[0].submit();
}
function DoResetIDs() {
/*	if (document.all) {
		for (var i=1; i < document.all.length; i++) {
			if	(	document.all(i).tagName=="INPUT" 
				&&	document.all(i).type=="hidden"
				&&	document.all(i).id.substring(0,5)=="hidID"
				) {
				document.all(i).value = '';
			}
		} 
	} */
}
function DoAddNew(p_Type) {
	DoResetIDs();
	document.getElementById('hidType').value = p_Type;
	document.getElementById('hidID' + p_Type).value = '';
	document.getElementById('hidAction').value = '16';
	document.forms[0].submit();
}
function DoLoad(p_ID, p_Type) {
	DoResetIDs();
	document.getElementById('hidType').value = p_Type;
	document.getElementById('hidID' + p_Type).value = p_ID;
	document.getElementById('hidAction').value = '4';
	document.forms[0].submit();
}
function DoDelete(p_ID, p_Type) {
	if (window.confirm("Are you sure you want to delete?\nClick OK to continue.")) {
		document.getElementById('hidType').value = p_Type;
		document.getElementById('hidID' + p_Type).value = p_ID;
		document.getElementById('hidAction').value = '3';
		document.forms[0].submit();
	}
}
function DoSave(p_objForm, p_Type) {
	try {
		if (document.getElementById('hidType')) document.getElementById('hidType').value = p_Type;
		if (document.getElementById('hidAction')) document.getElementById('hidAction').value = '1';
		if (fnSubmitForm(p_objForm)) {
			p_objForm.submit();
			//DoLoad('');
			//fnSubmit();
		}
	} catch(e) { 
		alert(e); 
	}
}
function DoEventReport(p_ID, p_Type) {
	document.getElementById('hidType').value = p_Type;
	document.getElementById('hidAction').value = '14';
	document.getElementById('hidID' + p_Type).value = p_ID;
	document.forms[0].submit();
}
function DoMethodOfPayment(p_ID, p_Type) {
	document.getElementById('hidType').value = p_Type;
	document.getElementById('hidAction').value = '13';
	document.getElementById('hidID' + p_Type).value = p_ID;
	document.forms[0].submit();
}
function DoFields(p_ID, p_Type) {
	document.getElementById('hidType').value = p_Type;
	document.getElementById('hidAction').value = '12';
	document.getElementById('hidID' + p_Type).value = p_ID;
	document.forms[0].submit();
}
function DoAgenda(p_ID, p_Type) {
	document.getElementById('hidType').value = p_Type;
	document.getElementById('hidAction').value = '11';
	document.getElementById('hidID' + p_Type).value = p_ID;
	document.forms[0].submit();
}
function DoSend(p_ID, p_Type) {
	document.getElementById('hidType').value = p_Type;
	document.getElementById('hidAction').value = '10';
	document.getElementById('hidID' + p_Type).value = p_ID;
	document.forms[0].submit();
}
function DoTestSend(p_ID, p_Type) {
	document.getElementById('hidType').value = p_Type;
	document.getElementById('hidAction').value = '9';
	document.getElementById('hidID' + p_Type).value = p_ID;
	document.forms[0].submit();
}
function DoEnable(p_ID, p_Type) {
	document.getElementById('hidType').value = p_Type;
	document.getElementById('hidAction').value = '7';
	document.getElementById('hidID' + p_Type).value = p_ID;
	document.forms[0].submit();
}
function DoDisable(p_ID, p_Type) {
	document.getElementById('hidType').value = p_Type;
	document.getElementById('hidAction').value = '6';
	document.getElementById('hidID' + p_Type).value = p_ID;
	document.forms[0].submit();
}
function DoContentEdit(p_ID, p_type) {
	openBrWindow('editor.aspx?type=' + p_type + '&id=' + p_ID,'edwin','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no','700','510','true');
}
function DoContentPreview(p_ID, p_type) {
	openBrWindow('preview.aspx?type=' + p_type + '&id=' + p_ID,'edwin','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no','700','510','true');
}
function DoSort(p_ID, p_Change, p_Type) {
	document.getElementById('hidType').value = p_Type;
	document.getElementById('hidAction').value = '5';
	document.getElementById('hidID' + p_Type).value = p_ID;
	document.getElementById('hidSortChange').value = p_Change;
	document.forms[0].submit();
}
function DoSubItems(p_ID, p_Type) {
	document.getElementById('hidType').value = p_Type;
	document.getElementById('hidAction').value = '8';
	document.getElementById('hidID' + p_Type).value = p_ID;
	document.forms[0].submit();
}
function fnSubmitForm(p_objForm) {
	//show saving div, hide form
	try {
		var blnStandardResult = fnVAL_Validate(p_objForm, false);
		var blnCustomResult = true;
		
		if (window.fnCustomCheck) {
			blnCustomResult = fnCustomCheck();
		}
		if (blnStandardResult && blnCustomResult) {
			//enable all disabled fields
			fnEnableDisableAll(false);
			return true;
		} else {
			//hide saving div, show form
			fnVAL_ShowValidationPrompt();
			return false;
		}
	} catch (e) {
		throw e;
	} 
}

function fnVAL_Validate(p_objForm, p_blnShowPrompt) {
	var arrElements = null;
	//reset prompt line
	m_strValidationPrompt = new String('');
	//reset date comparison array
	m_aryDateComparisons = new Array();
	//reset string comparisons array
	m_aryStringComparisons = new Array();
	//
	m_aryNumericComparisons = new Array();
	//
	m_aryNumericSum = new Array();
	//reset today's date
	fnSetToday();
	
	var strValidationString = new String('');
	var strValidationFunction = new String('');
	var strValidationParameters = new String('');
	var strFriendlyName = new String('');

	var aryValidations = new Array();
	
	var reLessThanSign = /</;
	var objCurrentFormElement;
	
	if ( p_objForm.all )
		arrElements = p_objForm.all;
	else
		arrElements = p_objForm.elements;
	
	//clear routine
	for (i=1; i < arrElements.length ;i++){
		// Turn off validation element.  If this is the second submit attempt we want the old
		//  misses turned off.  They will be turned back on if the error is still there.

		// Turn all feedback UI off, then turn them on below.  This pass is required because 
		//  some asp.net user controls have similar names and would turn off a previously 
		//  enalbed flag.  (EX:  ctlActivity:cboList, ctlActivity:cboList1, ctlActivity:cboList2)
		var objCurrentFormElement = arrElements[i];
		if (objCurrentFormElement.name) {
			fnVAL_SetValidationState(objCurrentFormElement, true);
		}
	}
	
	for (var i = 0; i < arrElements.length ;i++) { //Iterate through each form element to check for standard validations
		objCurrentFormElement = arrElements[i];
		if (objCurrentFormElement.name && objCurrentFormElement.disabled == false) {
			strValidationString = objCurrentFormElement.getAttribute('V'); //Grab the validation string if any
			if (strValidationString != null && strValidationString != undefined && strValidationString != '') { //Found a validation string
				aryValidations = strValidationString.split('~'); //now split into array of validations to check
				for (var j = 0; j < aryValidations.length; j++) { //Iterate through each validation
					strValidationParameters = new String(''); //reset validation parameters
					strValidationString = new String(aryValidations[j]);
					if (strValidationString.indexOf(':') > -1) { //check to see if any parameters are included with validation tag
						strValidationFunction = strValidationString.substr(0, strValidationString.indexOf(':')); // grab the validation tag
						strValidationParameters = strValidationString.substr(strValidationString.indexOf(':') + 1); // grab the validation tags parameters
					} else {
						strValidationFunction = strValidationString; //no parameters were found so grab the validation function
					}
					// Less than sign validation (this character will be blocked)
					if (reLessThanSign.test(objCurrentFormElement.value)) {
						fnVAL_AddPromptLine('Please remove the less than "<" character from the ' + fnVAL_GetFormElementFriendlyName(objCurrentFormElement) + ' field.');
						fnVAL_SetValidationState(objCurrentFormElement, false);
					}
					
					//	These tags can be used to automate the validation process when a form is submitted.
					//	The tags can used individually or in combination separating each tag by a ~ to be used as a delimiter
					//	They will need to be placed into a custom attribute called "V" inside of the html element
					//		Examples:
					//					<input type="text" id="text1" V="R">  (This will make this text box Required)
					//					<input type="text" id="text1" V="R~I">  (This will make this text box Required and will only accept integers)
					//					<input type="text" id="text1" V="R~CD>:(0,0)">  (This will make this text box Required and will compare the date value to another form field)
					switch (strValidationFunction.toUpperCase()) {
						// Required Validation
						// Usage: R
						case 'R'	:	fnCheckEmpty(objCurrentFormElement, strValidationParameters);
										break;
						// Required Select Box Choice 
						// Usage: SC
						case 'SC'	:	fnCheckEmptyDropDown(objCurrentFormElement, strValidationParameters);
										break;
						// Date Check Validation
						// Usage: D
						case 'D'	:	fnCheckUSDate(objCurrentFormElement, strValidationParameters);
										break;
						// Time Check Validation
						// Usage: T
						case 'T'	:	fnCheckTime(objCurrentFormElement, strValidationParameters);
										break;
						// Valid Numbers Only Validaion
						// Usage: N
						case 'N'	:	fnCheckNumeric(objCurrentFormElement, strValidationParameters);
										break;
						// Valid Numbers <> 0
						// Usage: NN0
						case 'NN0'	:	fnCheckNumericNotEqualToZero(objCurrentFormElement, strValidationParameters);
										break;
						// Valid positive number
						// Usage: N+
						case 'N+'	:	fnCheckNumericPositive(objCurrentFormElement, strValidationParameters);
										break;
						// Valid number equal to or greater than 0
						// Usage: N0 (that is a zero 0, not an O)
						case 'N0'	:	fnCheckNumericGreaterEqualZero(objCurrentFormElement, strValidationParameters);
										break;
						// Valid integer
						// Usage: NI
						case 'NI'	:	fnCheckInteger(objCurrentFormElement, strValidationParameters)
										break;
						// Valid positive integer
						// Usage: NI+
						case 'NI+'	:	fnCheckIntegerPositive(objCurrentFormElement, strValidationParameters);
										break;
						// Valid integer equal to or greater than 0
						// Usage: NI0 (that is a zero 0, not an O)
						case 'NI0'	:	fnCheckIntegerGreaterEqualZero(objCurrentFormElement, strValidationParameters);
										break;
						// Valid Alpha Only Validation
						// Usage: AA
						case 'AA'	:	fnCheckAlphaOnly(objCurrentFormElement, strValidationParameters);
										break;
						// Valid Alpha Numeric Only Validation
						// Usage: AN
						case 'AN'	:	fnCheckAlphaNumericOnly(objCurrentFormElement, strValidationParameters);
										break;
						// Email
						// Usage: E
						case 'E'	:	fnCheckEmail(objCurrentFormElement, strValidationParameters);
										break;
						// Url - web address
						// Usage: U
						case 'U'	:	fnCheckURL(objCurrentFormElement, strValidationParameters);
										break;
						// Phone Number
						// Usage: P
						case 'P'	:	fnCheckPhoneNumber(objCurrentFormElement, strValidationParameters);
										break;
						// SSN
						// Usage: SSN
						case 'SSN'	:	fnCheckSSN(objCurrentFormElement, strValidationParameters);
										break;
						// Zip
						// Usage: Z
						case 'Z'	:	fnCheckZip(objCurrentFormElement, strValidationParameters);
										break;
						// Zip (California) 
						// Usage: ZC
						case 'ZC'	:	fnCheckZipCalifornia(objCurrentFormElement, strValidationParameters);
										break;
						// Single quotes
						// Usage: U
						case 'Q'	:	fnCheckSingleQuote(objCurrentFormElement, strValidationParameters);
										break;
						// HTML
						// Usage: H
						case 'H'	:	fnCheckHTML(objCurrentFormElement, strValidationParameters);
										break;
										
						//		Note:	The following are comparison tags.
						//				There must be 2 elements on the screen with the SAME tag to make this work
						//				Additionally they must have the same arrayIndex
						//				arrayIndex must be an integer
						//				The comparisonIndex can be 0 or 1 and the paired elements must not have the same comparisonIndex
						//				Elements with a comparisonIndex of 0 will be to the left of the operator, while comparisonIndex will be to the right of the operator
						//				These rules apply to the tags:
						//												CS<operator>
						//												CD<operator>
										
						// Strings equal
						// Usage: CS==:(arrayIndex, comparisonIndex)
						// Example 1:
						//	<input type="text" id="text1" V="CS==:(0,0)"> Item will be placed in the 0 index spot in the string arrays to compare and will be to the left of the operator ==)
						//	<input type="text" id="text2" V="CS==:(0,1)"> Item will be placed in the 0 index spot in the string arrays to compare and will be to the right of the operator ==)
						//		Will evaluate if text1 == text2
						case 'CS=='	:	fnAddToStringArray(objCurrentFormElement, strValidationParameters, '==');
										break;
						// Strings not equal
						// Usage: CS!=:(arrayIndex, comparisonIndex)
						case 'CS!='	:	fnAddToStringArray(objCurrentFormElement, strValidationParameters, '!=');
										break;
						// Strings greater than or equal
						// Usage: CS>=:(arrayIndex, comparisonIndex)
						// Example 1:
						//	<input type="text" id="text1" V="CS>=:(0,0)"> Item will be placed in the 0 index spot in the string arrays to compare and will be to the left of the operator >=)
						//	<input type="text" id="text2" V="CS>=:(0,1)"> Item will be placed in the 0 index spot in the string arrays to compare and will be to the right of the operator >=)
						//		Will evaluate if text1 >= text2
						case 'CS>='	:	fnAddToStringArray(objCurrentFormElement, strValidationParameters, '>=');
										break;
						// Strings less than or equal
						// Usage: CS<=:(arrayIndex, comparisonIndex)
						case 'CS<='	:	fnAddToStringArray(objCurrentFormElement, strValidationParameters, '<=');
										break;
						// Strings greater than
						// Usage: CS>:(arrayIndex, comparisonIndex)
						case 'CS>'	:	fnAddToStringArray(objCurrentFormElement, strValidationParameters, '>');
										break;
						// Strings less than
						// Usage: CS<:(arrayIndex, comparisonIndex)
						case 'CS<'	:	fnAddToStringArray(objCurrentFormElement, strValidationParameters, '<');
										break;


						// Dates equal
						// Usage: CD==:(arrayIndex, comparisonIndex)
						case 'CD=='	:	fnAddToDateArray(objCurrentFormElement, strValidationParameters, '==');
										break;
						// Dates not equal
						// Usage: CD!=:(arrayIndex, comparisonIndex)
						case 'CD!='	:	fnAddToDateArray(objCurrentFormElement, strValidationParameters, '!=');
										break;
						// Dates greater than or equal
						// Usage: CD>=:(arrayIndex, comparisonIndex)
						case 'CD>='	:	fnAddToDateArray(objCurrentFormElement, strValidationParameters, '>=');
										break;
						// Dates less than or equal
						// Usage: CD<=:(arrayIndex, comparisonIndex)
						case 'CD<='	:	fnAddToDateArray(objCurrentFormElement, strValidationParameters, '<=');
										break;
						// Dates greater than
						// Usage: CD>:(arrayIndex, comparisonIndex)
						case 'CD>'	:	fnAddToDateArray(objCurrentFormElement, strValidationParameters, '>');
										break;
						// Dates less than
						// Usage: CD<:(arrayIndex, comparisonIndex)
						case 'CD<'	:	fnAddToDateArray(objCurrentFormElement, strValidationParameters, '<');
										break;
								
						// Numeric Sum Numeric
						// Usage: SN:(arrayIndex, total that must be <=)
						case 'SN=='	:	fnAddToNumericSumArray(objCurrentFormElement, strValidationParameters, '==');
										break;
						// Numeric Sum not equal
						// Usage: CN!=:(arrayIndex, comparisonIndex)
						case 'SN!='	:	fnAddToNumericSumArray(objCurrentFormElement, strValidationParameters, '!=');
										break;
						// Numeric Sum greater than or equal
						// Usage: CN>=:(arrayIndex, comparisonIndex)
						case 'SN>='	:	fnAddToNumericSumArray(objCurrentFormElement, strValidationParameters, '>=');
										break;
						// Numeric Sum less than or equal
						// Usage: CN<=:(arrayIndex, comparisonIndex)
						case 'SN<='	:	fnAddToNumericSumArray(objCurrentFormElement, strValidationParameters, '<=');
										break;
						// Numeric Sum greater than
						// Usage: CN>:(arrayIndex, comparisonIndex)
						case 'SN>'	:	fnAddToNumericSumArray(objCurrentFormElement, strValidationParameters, '>');
										break;
						// Numeric Sum less than
						// Usage: CN<:(arrayIndex, comparisonIndex)
						case 'SN<'	:	fnAddToNumericSumArray(objCurrentFormElement, strValidationParameters, '<');
										break;
										
						// Numbers equal
						// Usage: CN==:(arrayIndex, comparisonIndex)
						case 'CN=='	:	fnAddToNumericArray(objCurrentFormElement, strValidationParameters, '==');
										break;
						// Numbers not equal
						// Usage: CN!=:(arrayIndex, comparisonIndex)
						case 'CN!='	:	fnAddToNumericArray(objCurrentFormElement, strValidationParameters, '!=');
										break;
						// Numbers greater than or equal
						// Usage: CN>=:(arrayIndex, comparisonIndex)
						case 'CN>='	:	fnAddToNumericArray(objCurrentFormElement, strValidationParameters, '>=');
										break;
						// Numbers less than or equal
						// Usage: CN<=:(arrayIndex, comparisonIndex)
						case 'CN<='	:	fnAddToNumericArray(objCurrentFormElement, strValidationParameters, '<=');
										break;
						// Numbers greater than
						// Usage: CN>:(arrayIndex, comparisonIndex)
						case 'CN>'	:	fnAddToNumericArray(objCurrentFormElement, strValidationParameters, '>');
										break;
						// Numbers less than
						// Usage: CN<:(arrayIndex, comparisonIndex)
						case 'CN<'	:	fnAddToNumericArray(objCurrentFormElement, strValidationParameters, '<');
										break;
						// END OF PAIRED TAGS
										
						// Date equal to today
						// Usage: CDT==
						case 'CDT==':	fnCompareDateToToday(objCurrentFormElement, '==');
										break;
						// Date not equal to today
						// Usage: CDT!=
						case 'CDT!=':	fnCompareDateToToday(objCurrentFormElement, '!=');
										break;
						// Date greater than or equal to today
						// Usage: CDT>=
						case 'CDT>=':	fnCompareDateToToday(objCurrentFormElement, '>=');
										break;
						// Date less than or equal to today
						// Usage: CDT<=
						case 'CDT<=':	fnCompareDateToToday(objCurrentFormElement, '<=');
										break;
						// Date greater than to today
						// Usage: CDT>
						case 'CDT>'	:	fnCompareDateToToday(objCurrentFormElement, '>');
										break;
						// Date less than to today
						// Usage: CDT<
						case 'CDT<'	:	fnCompareDateToToday(objCurrentFormElement, '<');
										break;
					} //end switch
				} // end this elements validation for loop
			} // end this elements "if" check to see whether strValidationString has anything or not
		} // end this elements check to see if it has a name is not disabled
	} // end the forms for loop of each element
	
	// loop through our array of dates to compare
	for (var i = 0; i < m_aryDateComparisons.length; i++) 
		m_aryDateComparisons[i].CompareDates(m_aryDateComparisons[i].Date1, m_aryDateComparisons[i].Date2, m_aryDateComparisons[i].CompareOperator);

	// loop through our array of strings to compare
	for (var i = 0; i < m_aryStringComparisons.length; i++) 
		m_aryStringComparisons[i].CompareStrings(m_aryStringComparisons[i].String1, m_aryStringComparisons[i].String2, m_aryStringComparisons[i].CompareOperator);

	// loop through our array of numbers to compare
	for (var i = 0; i < m_aryNumericComparisons.length; i++) 
		if (m_aryNumericComparisons[i] && m_aryNumericComparisons[i].Number1 && m_aryNumericComparisons[i].Number2) 
			m_aryNumericComparisons[i].CompareNumbers(m_aryNumericComparisons[i].Number1, m_aryNumericComparisons[i].Number2, m_aryNumericComparisons[i].CompareOperator);

	// loop through our array of numeric sums to compare
	for (var i = 0; i < m_aryNumericSum.length; i++) 
		m_aryNumericSum[i].CompareSum(m_aryNumericSum[i].Number1, m_aryNumericSum[i].SumToCompare, m_aryNumericSum[i].CompareOperator, m_aryNumericSum[i].Friendly);

	//check validation prompt for results
	if (m_strValidationPrompt == '') {
		return true; // all is well
	} else { // Uh Oh!
		if ( p_blnShowPrompt ){  
			fnVAL_ShowValidationPrompt(); // Show user the prompt
		}
		if (document.fnEnableSaveButton) fnEnableSaveButton(); // Renable the save button
		return false;
	}
}
function fnVAL_ShowValidationPrompt(){
	var strPrompt = 'Before your action can be completed, please address the following issues:\n\n' + m_strValidationPrompt;
	alert(strPrompt);
	m_strValidationPrompt = new String('');
	if (document.fnEnableSaveButton) fnEnableSaveButton();
}

function fnGetDateString(p_datDate) {
	if (p_datDate != null && p_datDate > '') {
		p_datDate = new Date(p_datDate);
		var strMonth = (p_datDate.getMonth() + 1 > 9) ? p_datDate.getMonth() + 1 : '0' + (p_datDate.getMonth() + 1);
		var strDate = (p_datDate.getDate() > 9) ? p_datDate.getDate() : '0' + p_datDate.getDate();
		return strMonth + '/' + strDate + '/' + p_datDate.getFullYear();
	} else {
		return '';
	}
}
function fnAddToDateArray(p_objFormElement, p_strValidationParameters, p_strCompareOperator) {
	var aryParameters = p_strValidationParameters.split(',');

	if (m_aryDateComparisons[aryParameters[0]] == null)
		m_aryDateComparisons[aryParameters[0]] = new DateComparer(new Array(), new Array(), '');

	if (aryParameters[1] == 0)
		m_aryDateComparisons[aryParameters[0]].Date1.push(p_objFormElement);
	else
		m_aryDateComparisons[aryParameters[0]].Date2.push(p_objFormElement);

	m_aryDateComparisons[aryParameters[0]].CompareOperator = p_strCompareOperator;
}
function fnCompareDates(p_datFirst, p_datSecond, p_strCompareOperator) {
	if (p_datFirst != null && p_datSecond != null && p_datFirst != '' && p_datSecond != '') {
		return eval('new Date(\'' + p_datFirst + '\') ' + p_strCompareOperator + ' new Date(\'' + p_datSecond + '\')');
	} else {
		return false;
	}
}
function fnCompareDateMethod(p_objDateArray1, p_objDateArray2, p_strCompareOperator) {
	var intDateLength1 = p_objDateArray1.length;
	var intDateLength2 = p_objDateArray2.length;

	if ( intDateLength1 == 1 && intDateLength2 == 1 ){
		fnCompareDateElements(p_objDateArray1[0], p_objDateArray2[0], p_strCompareOperator);

	}else if ( intDateLength1 == 1 && intDateLength2 > 1 ){
		for (var i=0 ; i<p_objDateArray2.length; i++)
			fnCompareDateElements(p_objDateArray1[0], p_objDateArray2[i], p_strCompareOperator);

	}else if ( intDateLength1 > 1 && intDateLength2 == 1 ) {
		for (var i=0 ; i<p_objDateArray1.length; i++)
			fnCompareDateElements(p_objDateArray1[i], p_objDateArray2[0], p_strCompareOperator);
	}

}
function fnCompareDateElements(p_objDateElement1, p_objDateElement2, p_strCompareOperator) {
	var blnResult = true;
	var datFirst = fnGetDateString(p_objDateElement1.value);
	var datSecond = fnGetDateString(p_objDateElement2.value);
	if (datFirst > '' && datSecond > '' & !fnCompareDates(datFirst, datSecond, p_strCompareOperator)) {
		fnVAL_SetValidationState(p_objDateElement1, false);
		fnVAL_SetValidationState(p_objDateElement2, false);
		switch(p_strCompareOperator) {
			case '=='	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objDateElement1) + ' must be equal to ' + fnVAL_GetFormElementFriendlyName(p_objDateElement2) + '.'); break;
			case '!='	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objDateElement1) + ' must not be equal to ' + fnVAL_GetFormElementFriendlyName(p_objDateElement2) + '.'); break;
			case '>='	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objDateElement1) + ' must be greater than or equal to ' + fnVAL_GetFormElementFriendlyName(p_objDateElement2) + '.'); break;
			case '<='	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objDateElement1) + ' must be less than or equal to ' + fnVAL_GetFormElementFriendlyName(p_objDateElement2) + '.'); break;
			case '>'	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objDateElement1) + ' must be greater than ' + fnVAL_GetFormElementFriendlyName(p_objDateElement2) + '.'); break;
			case '<'	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objDateElement1) + ' must be less than ' + fnVAL_GetFormElementFriendlyName(p_objDateElement2) + '.'); break;
		}
	}
}
function fnAddToStringArray(p_objFormElement, p_strValidationParameters, p_strCompareOperator) {
	var aryParameters = p_strValidationParameters.split(',');
	if (aryParameters[0] >= m_aryStringComparisons.length) m_aryStringComparisons[aryParameters[0]] = new StringComparer();
	if (aryParameters[1] == 0) m_aryStringComparisons[aryParameters[0]].String1 = p_objFormElement;
	else m_aryStringComparisons[aryParameters[0]].String2 = p_objFormElement;
	m_aryStringComparisons[aryParameters[0]].CompareOperator = p_strCompareOperator;
}
function fnCompareStrings(p_strFirst, p_strSecond, p_strCompareOperator) {
	if (p_strFirst != null && p_strSecond != null && p_strFirst != '' && p_strSecond != '') {
		return eval('new String(\'' + new String(p_strFirst).replace(/'/, '\' + String.fromCharCode(39) + \'') + '\') ' + p_strCompareOperator + ' new String(\'' + new String(p_strSecond).replace(/'/, '\' + String.fromCharCode(39) + \'') + '\')');
	} else {
		return false;
	}
}
function fnCompareStringElements(p_objStringElement1, p_objStringElement2, p_strCompareOperator) {
	if (!fnCompareStrings(p_objStringElement1.value, p_objStringElement2.value, p_strCompareOperator)) {
		fnVAL_SetValidationState(p_objStringElement1, false);
		fnVAL_SetValidationState(p_objStringElement2, false);
		switch(p_strCompareOperator) {
			case '=='	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objStringElement1) + ' must be equal to ' + fnVAL_GetFormElementFriendlyName(p_objStringElement2) + '.'); break;
			case '!='	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objStringElement1) + ' must not be equal to ' + fnVAL_GetFormElementFriendlyName(p_objStringElement2) + '.'); break;
			case '>='	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objStringElement1) + ' must be greater than or equal to ' + fnVAL_GetFormElementFriendlyName(p_objStringElement2) + '.'); break;
			case '<='	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objStringElement1) + ' must be less than or equal to ' + fnVAL_GetFormElementFriendlyName(p_objStringElement2) + '.'); break;
			case '>'	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objStringElement1) + ' must be greater than ' + fnVAL_GetFormElementFriendlyName(p_objStringElement2) + '.'); break;
			case '<'	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objStringElement1) + ' must be less than ' + fnVAL_GetFormElementFriendlyName(p_objStringElement2) + '.'); break;
		}	
	}
}
function fnAddToNumericSumArray(p_objFormElement, p_strValidationParameters, p_strCompareOperator) {
	var aryParameters = p_strValidationParameters.split(',');
	if (aryParameters[0] >= m_aryNumericSum.length) {
		m_aryNumericSum[aryParameters[0]] = new NumericSum();
		m_aryNumericSum[aryParameters[0]].Friendly = fnVAL_GetFormElementFriendlyName(p_objFormElement);
		if (isNumeric(p_objFormElement.value)) {
			m_aryNumericSum[aryParameters[0]].Number1 = new Number(p_objFormElement.value);
		} else {
			m_aryNumericSum[aryParameters[0]].Number1 = new Number(0);
		}
		m_aryNumericSum[aryParameters[0]].CompareOperator = p_strCompareOperator;
		m_aryNumericSum[aryParameters[0]].SumToCompare = aryParameters[1];
	} else {
		if (isNumeric(p_objFormElement.value)) m_aryNumericSum[aryParameters[0]].Number1 += new Number(p_objFormElement.value);
	}
}
function fnCompareNumericSum(p_objNumericSum, p_objSumToCompare, p_strCompareOperator, p_strFriendly) {
	if (!fnCompareNumbers(p_objNumericSum, p_objSumToCompare, p_strCompareOperator)) {
		switch(p_strCompareOperator) {
			case '=='	:	fnVAL_AddPromptLine('Sum ' +  p_strFriendly + ' must be equal to ' + new String(p_objSumToCompare) + '.'); break;
			case '!='	:	fnVAL_AddPromptLine('Sum ' +  p_strFriendly + ' must not be equal to ' + new String(p_objSumToCompare) + '.'); break;
			case '>='	:	fnVAL_AddPromptLine('Sum ' +  p_strFriendly + ' must be greater than or equal to ' + new String(p_objSumToCompare) + '.'); break;
			case '<='	:	fnVAL_AddPromptLine('Sum ' +  p_strFriendly + ' must be less than or equal to ' + new String(p_objSumToCompare) + '.'); break;
			case '>'	:	fnVAL_AddPromptLine('Sum ' +  p_strFriendly + ' must be greater than ' + new String(p_objSumToCompare) + '.'); break;
			case '<'	:	fnVAL_AddPromptLine('Sum ' +  p_strFriendly + ' must be less than ' + new String(p_objSumToCompare) + '.'); break;
		}	
	}
}
function fnAddToNumericArray(p_objFormElement, p_strValidationParameters, p_strCompareOperator) {
	var aryParameters = p_strValidationParameters.split(',');
	if (aryParameters[0] >= m_aryNumericComparisons.length) {
		m_aryNumericComparisons[aryParameters[0]] = new NumericComparer();
	}
	if (aryParameters[1] == 0) {
		m_aryNumericComparisons[aryParameters[0]].Number1 = p_objFormElement;
	} else {
		m_aryNumericComparisons[aryParameters[0]].Number2 = p_objFormElement;
	}
	m_aryNumericComparisons[aryParameters[0]].CompareOperator = p_strCompareOperator;
}
function fnCompareNumbers(p_strFirst, p_strSecond, p_strCompareOperator) {
	if (p_strFirst != null && p_strSecond != null && p_strFirst != '' && p_strSecond != '') {
		return eval('Number(\'' + new Number(p_strFirst) + '\') ' + p_strCompareOperator + ' Number(\'' + new Number(p_strSecond) + '\')');
	} else {
		return false;
	}
}
function fnCompareNumberElements(p_objNumberElement1, p_objNumberElement2, p_strCompareOperator) {
	if (!fnCompareNumbers(p_objNumberElement1.value, p_objNumberElement2.value, p_strCompareOperator)) {
		fnVAL_SetValidationState(p_objNumberElement1, false);
		fnVAL_SetValidationState(p_objNumberElement2, false);
		switch(p_strCompareOperator) {
			case '=='	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objNumberElement1) + ' must be equal to ' + fnVAL_GetFormElementFriendlyName(p_objNumberElement2) + '.'); break;
			case '!='	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objNumberElement1) + ' must not be equal to ' + fnVAL_GetFormElementFriendlyName(p_objNumberElement2) + '.'); break;
			case '>='	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objNumberElement1) + ' must be greater than or equal to ' + fnVAL_GetFormElementFriendlyName(p_objNumberElement2) + '.'); break;
			case '<='	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objNumberElement1) + ' must be less than or equal to ' + fnVAL_GetFormElementFriendlyName(p_objNumberElement2) + '.'); break;
			case '>'	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objNumberElement1) + ' must be greater than ' + fnVAL_GetFormElementFriendlyName(p_objNumberElement2) + '.'); break;
			case '<'	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objNumberElement1) + ' must be less than ' + fnVAL_GetFormElementFriendlyName(p_objNumberElement2) + '.'); break;
		}	
	}
}
function fnCompareDateToToday(p_objFormElement, p_strCompareOperator) {
	var datFirst = fnGetDateString(p_objFormElement.value);
	var datSecond = fnGetDateString(m_datToday);
	if (datFirst > '' && datSecond > '' & !fnCompareDates(datFirst, datSecond, p_strCompareOperator)) {
		fnVAL_SetValidationState(p_objFormElement, false);
		switch(p_strCompareOperator) {
			case '=='	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be equal to today\'s date.'); break;
			case '!='	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must not be equal to today\'s date.'); break;
			case '>='	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be greater than or equal to today\'s date.'); break;
			case '<='	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be less than or equal to today\'s date.'); break;
			case '>'	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be greater than to today\'s date.'); break;
			case '<'	:	fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be less than to today\'s date.'); break;
		}		
	}	
}
function fnCheckEmpty(p_objFormElement, p_strValidationParameters) {
	if ( p_objFormElement.type == 'radio' ){
		return fnCheckEmptyRadio(p_objFormElement, p_strValidationParameters);

	}else if (p_objFormElement.type == 'checkbox') {
	    if (!p_objFormElement.checked) {
		    fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' is a required field.');
		    fnVAL_SetValidationState(p_objFormElement, false);
		}
	    return p_objFormElement.checked
	} else if	(isEmpty(p_objFormElement.value, p_strValidationParameters)) {
		fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' is a required field.');
		fnVAL_SetValidationState(p_objFormElement, false);
		return false;
	}
	return true;
}
function fnCheckEmptyRadio(p_objFormElement, p_strValidationParameters) {
	var objElement = document.getElementById(p_objFormElement.name);

	if ( fnVAL_GetSelectedRadioIndex(objElement) < 0 ) {
		fnVAL_AddPromptLine('You must choose an option for ' + fnVAL_GetFormElementFriendlyName(p_objFormElement) + '.');
		fnVAL_SetValidationState(p_objFormElement, false);
		return false;
	}
	return true;
}
function fnCheckEmptyDropDown(p_objFormElement, p_strValidationParameters) {
	if (isEmpty(p_objFormElement.options[p_objFormElement.selectedIndex].value, p_strValidationParameters)) {
		fnVAL_AddPromptLine('You must choose an option for ' + fnVAL_GetFormElementFriendlyName(p_objFormElement) + '.');
		fnVAL_SetValidationState(p_objFormElement, false);
		return false;
	}
	return true;
}
function fnCheckUSDate(p_objFormElement, p_strValidationParameters) {
	if (!isUSDate(p_objFormElement.value, p_strValidationParameters) && p_objFormElement.value != '' ) {
		fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be entered in the format mm/dd/yyyy and greater than 01/01/1900.');
		fnVAL_SetValidationState(p_objFormElement, false);
		return false;
	}
	return true;
}
function fnCheckTime(p_objFormElement, p_strValidationParameters) {
	if (p_objFormElement.value) {
		if ( !isTime(p_objFormElement.value, p_strValidationParameters)  && p_objFormElement.value != ''){
			fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' is not a valid time. \nTimes must be in the format h:mm:ss AM/PM\n');
			fnVAL_SetValidationState(p_objFormElement, false);
			return false;
		}
	}
	return true;
}
function fnCheckNumeric(p_objFormElement, p_strValidationParameters) {
	if ( p_strValidationParameters == null || p_strValidationParameters == '' ) {
		if ( !isNumeric(p_objFormElement.value, p_strValidationParameters) && p_objFormElement.value != '' ) {
			fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be a valid number.');
			fnVAL_SetValidationState(p_objFormElement, false);
			blnValidFlag = false;
			return false;
		}
	} else {
		// Validate Parameter = x.d where x is leading digits and d is decimal places.
		var aryTokens = p_strValidationParameters.split('.');
		intLeadingDigits = aryTokens[0];
		intDecimalDigits = aryTokens[1];
		// Build the Regular Expression validation string.
		strValidateRegExpString = '(^-?\\d{1,' + intLeadingDigits + '}$)';
		if (intDecimalDigits > 0) {
			strValidateRegExpString += '|(^-?\\d{0,' + intLeadingDigits + '}\\.\\d{1,' + intDecimalDigits + '}$)';
		}
		if ( validateValue(p_objFormElement.value, strValidateRegExpString) == false && p_objFormElement.value != '' ) {
			fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be a valid number.');
			fnVAL_SetValidationState(p_objFormElement, false);
			blnValidFlag = false;
			return false;
		}
	}
	return true;
}
function fnCheckNumericNotEqualToZero(p_objFormElement, p_strValidationParameters) {
	if (!fnCheckNumeric(p_objFormElement, p_strValidationParameters) && new Number(p_objFormElement.value) != 0 ) {
		fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be a non-zero number.');
		fnVAL_SetValidationState(p_objFormElement, false);
		return false;
	}
	return true;
}
function fnCheckNumericPositive(p_objFormElement, p_strValidationParameters) {
	if (!isPositiveNumeric(p_objFormElement.value, p_strValidationParameters) && p_objFormElement.value != '' ) {
		fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be a positive number.');
		fnVAL_SetValidationState(p_objFormElement, false);
		return false;
	}
	return true;
}
function fnCheckNumericGreaterEqualZero(p_objFormElement, p_strValidationParameters) {
	if (!isGreaterEqualZero(p_objFormElement.value, p_strValidationParameters) && p_objFormElement.value != '' ) {
		fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be a greater than or equal to zero.');
		fnVAL_SetValidationState(p_objFormElement, false);
		return false;
	}
	return true;
}
function fnCheckInteger(p_objFormElement, p_strValidationParameters) {
	if ( !isInteger(p_objFormElement.value, p_strValidationParameters) && p_objFormElement.value != '') {
		fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be a valid integer.');
		fnVAL_SetValidationState(p_objFormElement, false);
		return false;
	}
	return true;
}
function fnCheckIntegerPositive(p_objFormElement, p_strValidationParameters) {
	if ( p_objFormElement.value != '' && (!isInteger(p_objFormElement.value, p_strValidationParameters) || !isPositiveNumeric(p_objFormElement.value, p_strValidationParameters)) ) {
		fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be a positive integer.');
		fnVAL_SetValidationState(p_objFormElement, false);
		return false;
	}
	return true;
}
function fnCheckIntegerGreaterEqualZero(p_objFormElement, p_strValidationParameters) {
	if (p_objFormElement.value != '' && (!isInteger(p_objFormElement.value, p_strValidationParameters) || !isGreaterEqualZero(p_objFormElement.value, p_strValidationParameters)) ) {
		fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be an integer greater than or equal to zero.');
		fnVAL_SetValidationState(p_objFormElement, false);
		return false;
	}
	return true;
}
function fnCheckAlphaOnly(p_objFormElement, p_strValidationParameters) {
	if (!isAllAlpha(p_objFormElement.value, p_strValidationParameters) && p_objFormElement.value != '') {
		fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must only contain letters (a-z or A-Z).');
		fnVAL_SetValidationState(p_objFormElement, false);
		return false;
	}
	return true;
}
function fnCheckAlphaNumericOnly(p_objFormElement, p_strValidationParameters) {
	if (!isAllAlphaNumeric(p_objFormElement.value, p_strValidationParameters) && p_objFormElement.value != '') {
		fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must only contain letters (a-z or A-Z) or numbers (0-9).');
		fnVAL_SetValidationState(p_objFormElement, false);
		return false;
	}
	return true;
}
function fnCheckEmail(p_objFormElement, p_strValidationParameters) {
	if (p_objFormElement.value) {
		if ( !isEmail(p_objFormElement.value, p_strValidationParameters) && p_objFormElement.value != '' ) {
			fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be a valid email.');
			fnVAL_SetValidationState(p_objFormElement, false);
			return false;
		}
	}
	return true;
}
function fnCheckURL(p_objFormElement, p_strValidationParameters) {
	if (p_objFormElement.value) {
		if ( !isUrl(p_objFormElement.value, p_strValidationParameters) && p_objFormElement.value != '' ) {
			fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be a valid web address beginning in \'http://\' or \'https://\'.');
			fnVAL_SetValidationState(p_objFormElement, false);
			return false;
		}
	}
	return true;
}
function fnCheckPhoneNumber(p_objFormElement, p_strValidationParameters) {
	if (p_objFormElement.value) {
		if ( !isUSPhone(p_objFormElement.value, p_strValidationParameters) && p_objFormElement.value != '--' && p_objFormElement.value != '') {
			if (p_objFormElement.value == '000-000-0000')
				fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' cannot be 000-000-0000.');
			else  
				fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be entered in the format 999-999-9999.');
			fnVAL_SetValidationState(p_objFormElement, false);
			return false;
		} else if (p_objFormElement.value.substring(0,1) == '0' || p_objFormElement.value.substring(0,1) == '1' ) {
			fnVAL_AddPromptLine('Area codes cannot begin with the numbers 0 or 1.');
			fnVAL_SetValidationState(p_objFormElement, false);
			return false;
		}
	}
	return true;
}
function fnCheckSSN(p_objFormElement, p_strValidationParameters) {
	if (p_objFormElement.value) {
		if ( !isSSN(p_objFormElement.value, p_strValidationParameters) && p_objFormElement.value != '--' && p_objFormElement.value != '') {
			if (p_objFormElement.value == '000-00-0000') {
				fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' cannot be 000-00-0000.');
			} else {
				fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be entered in the format 999-99-9999.');
			}
			fnVAL_SetValidationState(p_objFormElement, false);
			return false;
		}
	}
	return true;
}
function fnCheckZip(p_objFormElement, p_strValidationParameters) {
	if (p_objFormElement.value) {
		if ( !isUSZip(p_objFormElement.value, p_strValidationParameters) && p_objFormElement.value != '' ) {
			fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be a valid zip code format.');
			fnVAL_SetValidationState(p_objFormElement, false);
			return false;
		}
	}
	return true;
}
function fnCheckZipCalifornia(p_objFormElement, p_strValidationParameters) {
	if (p_objFormElement.value) {
		if ( !isUSZip(p_objFormElement.value, p_strValidationParameters) && p_objFormElement.value != '' ) {
			fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must be a valid zip code format.');
			fnVAL_SetValidationState(p_objFormElement, false);
			return false;
		} else if (p_objFormElement.value.substring(0, 1) != '9' ) {
			if ( !confirm('The zip code which you entered does not begin with the number 9.\n\nZip code entered: ' + p_objFormElement.value + '\n\nIs this zip code correct?')){
				fnVAL_AddPromptLine('The zip code which you entered does not begin with the number 9.');
				fnVAL_SetValidationState(p_objFormElement, false);
				return false;
			}
		}
	}
	return true;
}
function fnCheckSingleQuote(p_objFormElement, p_strValidationParameters) {
	if ( (p_objFormElement.value) && (p_objFormElement.name != 'ID') ) {
		if ( !validateValue(p_objFormElement.value, '\'') ) {
			fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must not contain single quotes.');
			fnVAL_SetValidationState(p_objFormElement, false);
			return false;
		}
	}
	return true;
}
function fnCheckHTML(p_objFormElement, p_strValidationParameters) {
	theRE = /\<(input|script|meta)/i;
	if (p_objFormElement.value) {
		if (theRE.test(p_objFormElement.value)) {
			fnVAL_AddPromptLine(fnVAL_GetFormElementFriendlyName(p_objFormElement) + ' must not contain any of the following HTML tags.\n\t - <input>\n\t - <script>\n\t - <meta>');
			fnVAL_SetValidationState(p_objFormElement, false);
			return true;
		}
	}
	return false;
}
function fnVAL_AddPromptLine(strPrompt, p_blnFilterDuplicates) {
	// Just append to report	
	var strNextLine = ' - ' + strPrompt + '\n';
	
	if ( p_blnFilterDuplicates == false ){
		m_strValidationPrompt += strNextLine;
	} else {  // Try to avoid adding the same prompt multiple times.
		if ( m_strValidationPrompt.indexOf( strNextLine ) < 0 ) {
			m_strValidationPrompt += strNextLine;
		}
	}
}

function fnVAL_SetValidationState(objFormElement, blnIsValid) {
	// Either show or hide the validation feedback ui element.
	// Get the validation element reference
	var objCurrentValidationElement = fnVAL_GetValidationElement(objFormElement);
	
	// This is optional, so there may be no element
	if ( objCurrentValidationElement && objCurrentValidationElement.style) {
		if ( blnIsValid ) { // For valid items, hide the validation feedback item
			objCurrentValidationElement.style.display = 'none';
		} else { // For invalid items, show the validation feedback item.
			objCurrentValidationElement.style.display = '';
		}
	}
}

function fnVAL_GetValidationElement(objFormElement) {
	var strValidationName = objFormElement.getAttribute('valfeedback');  // See if developer is overriding auto detection
	var strElementNameRoot = '';
	var objValidation = null;

	if ( strValidationName == '' || strValidationName == null) {
		//strElementNameRoot = fnVAL_GetFormElementNameRoot(objFormElement);  // Get root of element.  See function for comments.
		//strValidationName = 'val' + strElementNameRoot;  // Build the associated validation item's name
		objValidation = fnVAL_GetFormElementRelatedItem(objFormElement, 'val');
	}else{
		objValidation = document.getElementById(strValidationName); // Get reference to validation element.
	}

	//var objValidation = document.getElementById(strValidationName); // Get reference to validation element.

	return objValidation;  // This may be null if there is no such element.
}
function fnVAL_GetFormElementRelatedItem(objFormElement, p_strPrefix) {
	var strName = objFormElement.name;
	var objItem = null;

	var intPosition = strName.lastIndexOf(':');
	if ( intPosition >= 0 ) {
		strName = strName.substring(0, intPosition) + '_' + p_strPrefix + strName.substr(intPosition); // + 4);
	}else{
		strName = p_strPrefix + strName; //.substr(3);;
	}
	objItem = document.getElementById(strName);

	return objItem;
}
function fnVAL_GetFormElementNameRoot(objFormElement) {
	// If naming converntions are maintained we can get the label and 
	//  validation ids from the element name then do standard validation
	//  like get the label name that may be set dynamically on the server.
	// Ex:
	// txtFirstName - The element to validate
	// lblFirstName - The label for the element.  Reuse the label for alert prompts.
	// valFirstName - Validation item to show / hide for ui feedback on which fields are wrong.
	var strName = objFormElement.name.substr(3);  // strip off first 3 characters.
	// For asp.net user controls there will be the following pattern: ctlActivity:cboList
	//  The control name precedes the colon and the composite control contained withing the
	//  user control comes after it.  Try to stip off portion after colon.
	
	var intPosition = strName.indexOf(':');
	if ( intPosition >= 0 ) {
		strName = strName.substring(0, intPosition);
	}
	
	return strName;
}

function fnVAL_GetFormElementFriendlyName(objFormElement) {
	var strFriendlyName = objFormElement.getAttribute('friendly');  // See if developer is overriding auto detection
	var strRet = objFormElement.name; // Default to the ugly name of the element.  This will be something like 'txtFirstName'
	
	if ( strFriendlyName == null ){
		// No custom override: find the associated label for this element
		//var strElementNameRoot = fnVAL_GetFormElementNameRoot(objFormElement);  // Get root of element.  See function for comments.
		//var strLabelName = 'lbl' + strElementNameRoot;  // Build the associated label's name
		//var objLabel = document.getElementById(strLabelName); // Get reference to lable element.
		var objLabel = fnVAL_GetFormElementRelatedItem(objFormElement, 'lbl');

		// If label is found, try to get its value.		
		if ( objLabel ) {
			if ( objLabel.innerText ) strRet = objLabel.innerText;
			else if ( objLabel.value ) strRet = objLabel.value;
			
			// Most labels have a colon at the end, strip it off.
			if ( strRet.charAt(strRet.length - 1) == ':' ) strRet = strRet.substr(0, strRet.length - 1);
		}
	} else {
		// Custom attribute override.  Do not attempt auto label detection.
		strRet = strFriendlyName;
	}
		
	return strRet;
}
function fnSetToday() {
	m_datToday = new Date();
    m_datToday.setHours(0);
    m_datToday.setMinutes(0, 0, 0);
}
function fnVAL_GetSelectedRadioIndex(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "fnVAL_GetSelectedRadioIndex" function

function fnVAL_GetSelectedRadioIndexValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = fnVAL_GetSelectedRadioIndex(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "fnVAL_GetSelectedRadioIndexValue" function

function fnInclude(p_blnChecked, p_strContainerID) {
	var objCurrentFormElement;
	var arrElements = null;
	var strValidationString = '';
	
	if ( document.getElementById(p_strContainerID).all )
		arrElements = document.getElementById(p_strContainerID).all;
	else
		arrElements = document.getElementById(p_strContainerID);
		
	for (var i = 0; i < arrElements.length ;i++) { //Iterate through each form element to check for standard validations
		objCurrentFormElement = arrElements[i];
		if (objCurrentFormElement.name && objCurrentFormElement.disabled == false) {
			if (!p_blnChecked) {
				// move V attribute to V_exclude
				strValidationString = objCurrentFormElement.getAttribute('V'); //Grab the validation string if any
				if (strValidationString != null && strValidationString != undefined && strValidationString != '') { //Found a validation string
					objCurrentFormElement.setAttribute('V_exclude', strValidationString, 0);
					objCurrentFormElement.setAttribute('V', '', 0);
				}
			} else {
				// move V_exclude attribute to V
				strValidationString = objCurrentFormElement.getAttribute('V_exclude'); //Grab the validation string if any
				if (strValidationString != null && strValidationString != undefined && strValidationString != '') { //Found a validation string
					objCurrentFormElement.setAttribute('V', strValidationString, 0);
					objCurrentFormElement.setAttribute('V_exclude', '', 0);
				}
			}
		}
	}
}
/*****************************************************************************************************************************************/
/*****************************************************************************************************************************************/
/*****************************************       HELPER FUNCTIONS      *******************************************************************/
/*****************************************************************************************************************************************/
/*****************************************************************************************************************************************/

function rightTrim( strValue ) {
	/************************************************
	DESCRIPTION: Trims trailing whitespace chars.

	PARAMETERS:
	strValue - String to be trimmed.  

	RETURNS:
	Source string with right whitespaces removed.
	*************************************************/
	var objRegExp = /^([\w\W]*)(\b\s*)$/;

	if(objRegExp.test(strValue)) {
		//remove trailing a whitespace characters
		strValue = strValue.replace(objRegExp, '$1');
	}
	return strValue;
}

function leftTrim( strValue ) {
	/************************************************
	DESCRIPTION: Trims leading whitespace chars.

	PARAMETERS:
	strValue - String to be trimmed

	RETURNS:
	Source string with left whitespaces removed.
	*************************************************/
	var objRegExp = /^(\s*)(\b[\w\W]*)$/;

	if(objRegExp.test(strValue)) {
		//remove leading a whitespace characters
		strValue = strValue.replace(objRegExp, '$2');
	}
	return strValue;
}

function trimAll( strValue ) {
	/************************************************
	DESCRIPTION: Removes leading and trailing spaces.

	PARAMETERS: Source string from which spaces will
	be removed;

	RETURNS: Source string with whitespaces removed.
	*************************************************/ 
	var objRegExp = /^(\s*)$/;

	//check for all spaces
	if(objRegExp.test(strValue)) {
		strValue = strValue.replace(objRegExp, '');
		if( strValue.length == 0) return strValue;
	}

	//check for leading & trailing spaces
	objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
	if(objRegExp.test(strValue)) {
		//remove leading and trailing whitespace characters
		strValue = strValue.replace(objRegExp, '$2');
	}
	return strValue;
}

function removeCurrency( strValue ) {
	/************************************************
	DESCRIPTION: Removes currency formatting from 
	source string.

	PARAMETERS: 
	strValue - Source string from which currency formatting
	will be removed;

	RETURNS: Source string with commas removed.
	*************************************************/
	var objRegExp = /\(/;
	var strMinus = '';

	//check if negative
	if(objRegExp.test(strValue)){
		strMinus = '-';
	}

	objRegExp = /\)|\(|[,]/g;
	strValue = strValue.replace(objRegExp, '');
	if(strValue.indexOf('$') >= 0){
		strValue = strValue.substring(1, strValue.length);
	}
	return strMinus + strValue;
}

function addCurrency( strValue ) {
	/************************************************
	DESCRIPTION: Formats a number as currency.

	PARAMETERS: 
	strValue - Source string to be formatted

	REMARKS: Assumes number passed is a valid 
	numeric value in the rounded to 2 decimal 
	places.  If not, returns original value.
	*************************************************/
	var objRegExp = /-?[0-9]+\.[0-9]{2}$/;

	if( objRegExp.test(strValue)) {
		objRegExp.compile('^-');
		strValue = addCommas(strValue);
		if (objRegExp.test(strValue)) strValue = '($' + strValue.replace(objRegExp,'') + ')';
		else strValue = '$' + strValue;
		return  strValue;
	}
	else return strValue;
}

function removeCommas( strValue ) {
	/************************************************
	DESCRIPTION: Removes commas from source string.

	PARAMETERS: 
	strValue - Source string from which commas will 
	be removed;

	RETURNS: Source string with commas removed.
	*************************************************/
	var objRegExp = /,/g; //search for commas globally

	//replace all matches with empty strings
	return strValue.replace(objRegExp,'');
}

function addCommas( strValue ) {
	/************************************************
	DESCRIPTION: Inserts commas into numeric string.

	PARAMETERS: 
	strValue - source string containing commas.

	RETURNS: String modified with comma grouping if
	source was all numeric, otherwise source is 
	returned.

	REMARKS: Used with integers or numbers with
	2 or less decimal places.
	*************************************************/
	var objRegExp  = new RegExp('(-?[0-9]+)([0-9]{3})'); 

	//check for match to search criteria
	while(objRegExp.test(strValue)) {
		//replace original string with first group match, 
		//a comma, then second group match
		strValue = strValue.replace(objRegExp, '$1,$2');
	}
	return strValue;
}

function removeCharacters( strValue, strMatchPattern ) {
	/************************************************
	DESCRIPTION: Removes characters from a source string
	based upon matches of the supplied pattern.

	PARAMETERS: 
	strValue - source string containing number.

	RETURNS: String modified with characters
	matching search pattern removed

	USAGE:  strNoSpaces = removeCharacters( ' sfdf  dfd', '\s*')
	*************************************************/
	var objRegExp =  new RegExp( strMatchPattern, 'gi' );

	//replace passed pattern matches with blanks
	return strValue.replace(objRegExp,'');
}


/*****************************************************************************************************************************************/
/*****************************************************************************************************************************************/
/*****************************************       CHECK FUNCTIONS      *******************************************************************/
/*****************************************************************************************************************************************/
/*****************************************************************************************************************************************/

function validateValue( strValue, strMatchPattern ) {
	/************************************************
	DESCRIPTION: Validates that a string a matches
	a valid regular expression value.

	PARAMETERS:
	strValue - String to be tested for validity
	strMatchPattern - String containing a valid
	regular expression match pattern.

	RETURNS:
	True if valid, otherwise false.
	*************************************************/
	var objRegExp = new RegExp( strMatchPattern);

	//check if string matches pattern
	return objRegExp.test(strValue);
}

function isEmpty( strValue ) {
	/************************************************
	DESCRIPTION: Determines if a string is empty or not

	PARAMETERS:
	strValue - String to be tested

	RETURNS:
	True if empty string, otherwise false.
	*************************************************/
	var strTemp = strValue;
	strTemp = trimAll(strTemp);
	if(strTemp.length > 0) {
		return false;
	}
	return true;
}

function isUSDate( strValue ) {
	/************************************************
	DESCRIPTION: Validates that a string contains only 
	valid dates with 2 digit month, 2 digit day, 
	4 digit year. Date separator can be ., -, or /.
	Uses combination of regular expressions and 
	string parsing to validate date.
	Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy

	PARAMETERS:
	strValue - String to be tested for validity

	RETURNS:
	True if valid, otherwise false.

	REMARKS:
	Avoids some of the limitations of the Date.parse()
	method such as the date separator character.
	*************************************************/
	var objRegExp = /^\d{2}(\-|\/|\.)\d{2}\1\d{4}$/;

	//check to see if in correct format
	if(!objRegExp.test(strValue)) return false; //doesn't match pattern, bad date
	else {
		var arrayDate = strValue.split(RegExp.$1); //split date into month, day, year
		var intDay = parseInt(arrayDate[1],10); 
		var intYear = parseInt(arrayDate[2],10);
		var intMonth = parseInt(arrayDate[0],10);

		//check for valid month
		if(intMonth > 12 || intMonth < 1) {
			return false;
		}

		//create a lookup for months not equal to Feb.
		var arrayLookup = { '01':31, '03':31, '04':30, '05':31, '06':30, '07':31, '08':31, '09':30, '10':31, '11':30, '12':31 };

		//check if month value and day value agree
		if(arrayLookup[arrayDate[0]] != null) {
			if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0 && intYear >= 1900) return true; //found in lookup table, good date
		}

		//check for February
		var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
		if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay != 0 && intYear >= 1900) return true; //Feb. had valid number of days
	}
	return false; //any other values, bad date
}

function isTime ( strValue ) {
	/************************************************
	DESCRIPTION: Validates that a string contains a 
	valid 12 hour time format. Seconds are optional.

	PARAMETERS:
	strValue - String to be tested for validity

	RETURNS:
	True if valid, otherwise false.

	REMARKS: Returns True for time formats such as:
	HH:MM or HH:MM:SS or HH:MM:SS.mmm (where the
	.mmm is milliseconds as used in SQL Server 
	datetime datatype.  Also, the .mmm portion will 
	accept 1 to 3 digits after the period)
	*************************************************/
	var objRegExp = /^([1-9]|1[0-2]):[0-5]\d(:[0-5]\d(\.\d{1,3})?)?$/;

	return objRegExp.test( strValue );
}

function  isNumeric( strValue ) {
	/******************************************************************************
	DESCRIPTION: Validates that a string contains only valid numbers.

	PARAMETERS:
	strValue - String to be tested for validity

	RETURNS:
	True if valid, otherwise false.
	******************************************************************************/
	var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; 

	//check for numeric characters 
	return objRegExp.test(strValue);
}

function isInteger( strValue ) {
	/************************************************
	DESCRIPTION: Validates that a string contains only 
	valid integer number.

	PARAMETERS:
	strValue - String to be tested for validity

	RETURNS:
	True if valid, otherwise false.
	******************************************************************************/
	var objRegExp  = /(^-?\d\d*$)/;

	//check for integer characters
	return objRegExp.test(strValue);
}

function isPositiveNumeric( intValue ) {
	/************************************************
	DESCRIPTION: Validates that a number is always positive
	    
	PARAMETERS:
	strValue - Number to be tested for validity
	   
	RETURNS:
	True if valid, otherwise false.
	******************************************************************************/
	return (parseFloat(intValue) > 0);
}

function isGreaterEqualZero(p_Value) {
	/************************************************
	DESCRIPTION: Validates that a number is equal to or greater than 0
	    
	PARAMETERS:
	strValue - Number to be tested for validity
	   
	RETURNS:
	True if valid, otherwise false.
	******************************************************************************/
	return (parseFloat(p_Value) >= 0);
}

function isAllAlpha( strValue ) {
	/************************************************
	DESCRIPTION: Validates that a string contains only 
	valid alpha characters.

	PARAMETERS:
	strValue - String to be tested for validity

	RETURNS:
	True if valid, otherwise false.
	******************************************************************************/
	var objRegExp  = /(^[a-zA-Z\ ]*$)/;

	//check for integer characters
	return objRegExp.test(strValue);
}

function isAllAlphaNumeric( strValue ) {
	/************************************************
	DESCRIPTION: Validates that a string contains only 
	valid alpha numeric characters.

	PARAMETERS:
	strValue - String to be tested for validity

	RETURNS:
	True if valid, otherwise false.
	******************************************************************************/
	var objRegExp  = /(^[\w\ ]*$)/;

	//check for integer characters
	return objRegExp.test(strValue);
}

function isEmail(strValue) {
	/************************************************
	DESCRIPTION: Validates that a string contains a 
	valid email pattern. 

	PARAMETERS:
	strValue - String to be tested for validity

	RETURNS:
	True if valid, otherwise false.

	REMARKS: Accounts for email with country appended
	does not validate that email contains valid URL
	type (.com, .gov, etc.) and optionally,
	a valid country suffix.  Since email has many
	forms this expression only tests for near valid
	address.  Some additional validation may be
	required.
	*************************************************/
	var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
	//check for valid email
	return objRegExp.test(strValue);
}

function isUrl(strValue) {
	/************************************************
	DESCRIPTION: Validates that a string contains a 
	valid web address url pattern. 

	PARAMETERS:
	strValue - String to be tested for validity

	RETURNS:
	True if valid, otherwise false.

	REMARKS: Just checks to see if the address starts
	with 'http://' or 'https://'

	*************************************************/
	var objRegExp  = /\bhttp[s]?:\/\/.*/i;
	//check for valid url
	return objRegExp.test(strValue);
}

function isUSPhone( strValue ) {
	/************************************************
	DESCRIPTION: Validates that a string contains valid
	US phone pattern. 

	This example below is for the RegExp commented out
	Ex. 999-999-9999

	The one used will only allow
	xxx-xxxx format

	PARAMETERS:
	strValue - String to be tested for validity

	RETURNS:
	True if valid, otherwise false.
	*************************************************/
	var objRegExp  = /^\d{3}\-\d{3}\-\d{4}$/;

	//check for valid us phone with or without space between 
	//area code
	if (strValue == "000-000-0000") return false
	else return objRegExp.test(strValue); 
}

function isSSN( strValue ) {
	/************************************************
	DESCRIPTION: Validates that a string contains a 
	valid social security number. 

	PARAMETERS:
	strValue - String to be tested for validity

	RETURNS:
	True if valid, otherwise false.
	*************************************************/
	var objRegExp  = /^\d{3}\-\d{2}\-\d{4}$/;

	//check for valid SSN
	return objRegExp.test(strValue);
}

function isUSZip( strValue ) {
	/************************************************
	DESCRIPTION: Validates that a string a United
	States zip code in 5 digit format or zip+4
	format. 99999 or 99999-9999

	PARAMETERS:
	strValue - String to be tested for validity

	RETURNS:
	True if valid, otherwise false.

	*************************************************/
	var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;

	//check for valid US Zipcode
	if (strValue == "00000" || strValue == "00000-0000" || strValue == "000000000")
		return false
	else
		return objRegExp.test(strValue);
}

function ExportExcel(p_objElement) {
	var objApp = new ActiveXObject("Excel.Application");
	var objWorkbook = objApp.Workbooks.Add();
	objWorkbook.HTMLProject.HTMLProjectItems(1).Text = p_objElement.innerHTML;
	objWorkbook.HTMLProject.RefreshDocument();
	objApp.Visible = true;
}
function ExportWord(p_objElement) {
	var objApp = new ActiveXObject("Word.Application");
	var objWordDoc = objApp.Documents.Add();
	objWordDoc.HTMLProject.HTMLProjectItems(1).Text = p_objElement.innerHTML;
	objWordDoc.HTMLProject.RefreshDocument();
	objApp.Visible = true;
}