/*	~~~ MAIN FUNCTION ~~~
	USED IN:  			User Registration (EnterAccess.cfm) and Admin Add User (Admin/EditUser.cfm) 
	FUNCTION NAME: 		valSSNTaxID()
	AUTHOR: 			DC -- 07.15.02
	VARIABLES:			BothOK -- defines whether both SSN and TaxID can be accepted together.  
	CONDITIONS: 		if one of the following is not satisfied display error and return false
							1. SSN must have 9 total numbers
							2. TaxID must have 9 total numbers
							3. if number entered is integer
							4. if both fields are entered or none is entered
				
*/	
function valSSNTaxID(BothOK)
	{
		var b9NumsSSN = false;
		var b9NumsTaxID = false;
		var bSSNEntered = false;
		var bTaxIDEntered = false;
		var bIsDigit = false;
		var TotalNumDigits = 9;
		var strFullSSN = document.forms[0].SSN1.value + document.forms[0].SSN2.value + document.forms[0].SSN3.value;
		var strFullTaxID = document.forms[0].TaxID1.value + document.forms[0].TaxID2.value;
		
		//POPULATE THE HIDDEN FIELDS
		document.forms[0].strFullSSN.value = strFullSSN;
		document.forms[0].strFullTaxID.value = strFullTaxID;
			
		
		if ((strFullSSN.length == 0) && (strFullTaxID.length == 0)){
			alert("Please enter Social Security or Tax Identification Number."); return false;
		}
		
		// VALIDATE 3 SSN FIELDS (must 9 numbers)
		if (strFullSSN.length > 0){
				if (strFullSSN.length == TotalNumDigits)
						{b9NumsSSN=true; bSSNEntered=true;}
				else {alert("You must enter " + TotalNumDigits + " digits in the Social Security Number."); return false;}
		}
		

		
		// VALIDATE 2 TAXID FIELD (must 9 numbers)
		if (strFullTaxID.length > 0) {
				if (strFullTaxID.length == TotalNumDigits)
						{b9NumsTaxID=true; bTaxIDEntered=true;}
				else {alert("You must enter " + TotalNumDigits + " digits in the Tax ID Number."); return false;}
		}
			
		
		
		
		
		// IF BOTH FIELDS ARE ENTERED (switched on and off by BothOK variable) .... 
		if(!BothOK)
			{
				if ( ((bSSNEntered) && (bTaxIDEntered)) || ((strFullSSN.length > 0) && (strFullTaxID.length > 0)) ) 
				{
					alert("Please enter Social Security or Tax Identification Number.")
					return false;
				}
				// IS INTEGER.....
				// IsInteger() resides in core.js
				if (((bSSNEntered) && isInteger(strFullSSN)) || ((bTaxIDEntered) && isInteger(strFullTaxID)))
				{
					bIsDigit=true;
				}
			}
		else
			{
				// IS INTEGER.....
				if (strFullSSN.length > 0) {
					if (isInteger(strFullSSN)) bIsDigit=true;
					else bIsDigit=false;
				}
				if (strFullTaxID.length > 0) {
					if (isInteger(strFullTaxID)) bIsDigit=true;
					else bIsDigit=false;
				}
			}
		
		
		// IF LESS THAN 9 DIGITS
		//if ((!b9NumsSSN) || (!b9NumsTaxID)) 
		//{alert("You must enter " + TotalNumDigits + " numbers in the Social Security or Tax ID field."); return false;}
		// IF NOT ALL DIGITS
		if (!bIsDigit) {alert("Please enter only numeric values in the Social Security or Tax ID Number."); return false;}
		
		
		return true;
}