var sIllegal = "^~`|";

function LocalValidText( xoForm, xsField, xbMandatory )
{
	//if( AllFields( false ) == false )
	//	return false;
	
	return ValidText( xoForm, xsField, xbMandatory );
}

function LocalValidPhone( xoForm, xsField, xbMandatory, sCountry, sDescription )
{
	var bNA = ( sCountry == "CA" || sCountry == "US" );
	
	if( bNA )
	{
		return ValidPhone( xoForm, xsField, xbMandatory, bNA, sDescription );
	}
	else
	{
		return ValidText( xoForm, xsField, xbMandatory );
	}
}

function CheckChar( sFieldName, sLabelName )
{
	var sString = sLabelName + " contains illegal characters. i.e " + sIllegal;
	
	if( CharacterSearch( sFieldName ) == true )
	{
		alert( sString );
		return true;
	}
	else
	{
		return false;
	}
}

function o_DropDownCheck( xoForm, xsField, xsMessage )
{
	var nIndex = xoForm.selectedIndex;
	var nLength = xoForm.length;
	
	if( nLength > 1 )
	{
		AlternateMandatory( ( nIndex > 0 ), xsField, xsMessage );
	}
}

function o_SAU( xiuProposal )
{
	var sURL = "Notes.aspx?id=" + xiuProposal + "&n=4";
	
	var sReturn = window.showModalDialog( sURL );
}
function CheckDate( sValue )
{
	//var sStart = "" + document.form2.sF2DateStart.value;
	//var sEnd = "" + document.form2.sF2DateEnd.value;
	
	if( sValue == "" || sValue == "undefined" )
	{
		return true;
	}
	else
	{
		var sValid = VerifyDate( sValue, sDateFormat.toLowerCase() );
	
		if( sValid == null )
		{
			alert( "Date must be in the format " + sDateFormat.toUpperCase() + "." );
			return false;
		}
		/*if( sStart == "" || sEnd == "" )
		{
			return true;
		}
		var bOK = ( sStart != "" && sEnd != "" );
		AlternateMandatory( bOK, "sF2Date", "You must fill in both dates." );
		return bOK;
		*/
		return true;
	}
}

function o_Trim(sValue) {
    sValue = "" + sValue;

    if( sValue.length > 0 )    
	    sValue = sValue.replace( /^\s*|\s*$/g, "" );
	
	return sValue;
}

function o_DisableEnterKey()
{
	if( window.event.keyCode == 13 )
		window.event.keyCode = 0;
}

function o_ShowHide( oTarget, sValue )
{
	var target = document.getElementById( oTarget );
	
	target.style.display = sValue;
}

// CharacterSearch()
// Verifies that the variable string passed in matches one of the verification
// characters supplied.
//
//	xsCharactersToCheck		the Characters to Check
//	xsValidation			the concatenated string of all possible matches
//							- no seperators are required, simply string all possible
//							  matches together into one string.
// 
// RETURNS
//		FALSE
//			- If the variable string does not match any of the validation
//				patterns supplied in the validation string.
//
//		TRUE
//			- If the variable string matches the verification.
//
// CREATION
//		AUTHOR:	Tracy Norrie
//		DATE:	February 27, 2001
//
function CharacterSearch( xsValidation  )
{
	var bReturn = false;
	//var xsCharactersToCheck = "!#$%^&*+=~`/?':;}{][<>\"";
	var xsCharactersToCheck = sIllegal;
	
	for( var nLoop = 0; nLoop < xsValidation.length; nLoop++ )
	{
		var sChar = xsValidation.charAt( nLoop );
				
		for( var nTextLoop = 0; nTextLoop < xsCharactersToCheck.length; nTextLoop++ )
		{
			if( xsCharactersToCheck.charAt( nTextLoop ) == sChar )
				bReturn = true;
		}
	}
		
	// If we've made it here, there are no illegal characters

	return bReturn;

} // [Function CharacterSearch]


// Normalizes the Canadian Postal Code Supplied.
//
//	xsPostalCode		the Canadian Postal Code to Normalize
// 
// RETURNS
//		""
//			- If the (Space Stripped) Postal Code Supplied is not 6 Characters
//
//		sTempPC
//			- The Normalized Postal Code, from the One Supplied. 
//
// CREATION
//		AUTHOR:	Brent Walker
//		DATE:	February 08, 2001
//

function ICNormalize_CanadianPostalCode ( xsPostalCode )
{

	var sTempPC;		// Modify a Copy of the string passed in
	var sFirstHalf;		// Temp First Half of Postal Code
	var sSecondHalf;	// Temp Second Half of Postal Code
	
	var sPostalCode = xsPostalCode;
	
	// Strip all spaces from the Postal Code
	
	xsPostalCode = StripAllOccurrences(xsPostalCode," ");
	xsPostalCode = StripAllOccurrences(xsPostalCode,"-");
	
	// If the Postal Code is not the proper length
	
	if (xsPostalCode.length != 6)
	{
		// Return a Blank String
		return sPostalCode;
	}
	
	// Convert the Postal Code to Upper Case

	xsPostalCode = xsPostalCode.toUpperCase();
	
	// Grab the First Half of the Postal Code
	
	sFirstHalf = xsPostalCode.slice(0,3);
	
	// Grab the Second Half of the Postal Code

	sSecondHalf = xsPostalCode.slice(3,6);
	
	// Insert a Space between the two halves
	
	xsPostalCode = sFirstHalf.concat(" ");
	xsPostalCode = xsPostalCode.concat(sSecondHalf);
	
	var sNormPIN = "";

	for( var nCount = 0; nCount < 12; nCount++ )
	{
		if( xsPostalCode.charAt( nCount ).toUpperCase() == "O" )
			sNormPIN += "0";
		else
			sNormPIN += xsPostalCode.charAt( nCount ).toUpperCase();
	}

	xsPostalCode = sNormPIN;
	
	// Return the Normalized Postal Code
	
	return xsPostalCode;

} // [Function ICNormalize_CanadianPostalCode]


// Validates the normalized Canadian Postal Code Supplied.
//
//	sNormPostalCode		the Canadian Postal Code to Validate
//						* MUST BE NORMALIZED ALREADY
// 
// RETURNS
//		FALSE
//			- If the Postal Code Supplied is not 7 Characters
//			- If the Postal Code Supplied does not match the Validation
//				string of LNL NLN 
//			- If Characters 0, 2 or 6 are not valid Canada Post Letters.
//
//		TRUE
//			- If the Postal Code Supplied is VALID
//
// CREATION
//		AUTHOR:	Brent Walker
//		DATE:	February 08, 2001
//
//	MODIFICATION
//		AUTHOR:	Brent Walker
//		DATE:	February 13-14, 2001
//

function ICValidate_CanadianPostalCode ( sNormPostalCode )
{

	// Definition of Constants
	var sInvalidFirstCharacters = "DFIOQUWZ"	// Invalid Characters for the first Character
	var sInvalidCharacters = "DFIOQU";			// Invalid Characters for the third and fifth characters
	var nPCLength = sNormPostalCode.length;		// Length of the Postal Code String
	
	var bPCPatternValid;		// Boolean for determining if Postal Code is Valid
	var bInvalidChar;			// Boolean return value from function ConfirmCharacterString
	
	// Check to see if Postal Code is the Proper Length
	
	if (nPCLength == 7)
	{
	
		// Check to see if the Pattern Matches a Canadian Postal Code
		
		bPCPatternValid = AlphaNumericCheck( sNormPostalCode, "LNL#NLN", "*** ***" )
	
		if (bPCPatternValid == true)
		{
				
			// Verify the 1st character is valid
			
			sVarChar = sNormPostalCode.charAt(0);
			
			bInvalidChar = ConfirmCharacterString( sVarChar, sInvalidFirstCharacters );
				
			if( bInvalidChar )
			{
				return false;
			}
				
			
			// Verify the 3rd character is valid
			
			sVarChar = sNormPostalCode.charAt(2);
			
			bInvalidChar = ConfirmCharacterString( sVarChar, sInvalidCharacters );
				
			if( bInvalidChar )
			{
				return false;
			}
			
			// Verify the 5th character is valid
			
			sVarChar = sNormPostalCode.charAt(5);
			
			bInvalidChar = ConfirmCharacterString( sVarChar, sInvalidCharacters );
				
			if( bInvalidChar )
			{
				return false;
			}
			
		} // [If Pattern Matches]
		
		return bPCPatternValid;
		
	} // [If Length is Seven]
	
	return false;
	
} // [Function ICValidate_CanadianPostalCode]


// Removes any and all characters occurring in the string passed in, 
//	that are the same as the character to strip.
//		(leading, in between, trailing)
//
//	xsStringIn		The string to have all spaces removed.
//	sCharToStrip	The Character to remove from the String
// 
// RETURNS
//		sTempString
//			- The String Passed in, stripped of the supplied character.
//
// CREATION
//		AUTHOR:	Brent Walker
//		DATE:	February 08, 2001

//
function StripAllOccurrences ( xsStringIn, sCharToStrip )
{

	var nStringLength;		// length of the String
	var sVarChar;			// Current Character
	var sFirstPart;			// Part of String Previous to the found Space
	var sSecondPart;		// Part of String Trailing the found space
	var nIndex = 0;			// Used to Index the String
	
	nStringLength = xsStringIn.length;
	
	// Loop through string until you get to the end
	
	while ( nIndex <= nStringLength )
	{
		
		sVarChar = xsStringIn.charAt(nIndex);
		
		// If current character matches the character to strip

		if ( sVarChar == sCharToStrip )
		{ 		
			
			// Grab String before Character to be stripped
			
			sFirstPart = xsStringIn.slice(0, nIndex);
			
			// Grab the String after Character to be stripped
			
			sSecondPart = xsStringIn.slice(nIndex+1, nStringLength);
			
			// Put the two string parts back together
			
			xsStringIn = sFirstPart.concat(sSecondPart);
			
			// Update Indexes
			
			nIndex = nIndex - 1;
			nStringLength = nStringLength - 1;
		
		} // [if Character to Strip Found] 
		
		// Update Index
		
		nIndex ++;
			
	} // [while not at end of string]
	
	return xsStringIn;
	
} // End Function StripAllOccurances


function CalculateAge( nDay, nMonth, nYear, day, month, year )
{

	var age;

	if ( month < nMonth )
	{
	  age = year - nYear - 1;
	}
	else if ( month > nMonth ){
	  age = year - nYear;
	}
	else if ( month == nMonth ){
	  if ( day < nDay ){
	    age = year - nYear - 1;
	  }
	  else if ( day > nDay ){
	    age = year - nYear;
	  }
	  else if ( day == nDay ){
	    age = year - nYear;
	  }
	}

	if( age < 13 ) 
		return false;
	else 
		return true;
}

// Checks to see if the year is a leap year.
//	nYear		the year to check
// returns 	false not a leap year

function isLeapYear( nYear )
{
	if( nYear % 100 == 0 )
	{
		if( nYear % 400 == 0 )
		{ 
			return true; 
		}
	}
	else
	{
		if( ( nYear % 4 ) == 0 )
		{ 
			return true; 
		}
	}

	// If you made it here, it is not a leap year

	return false;

}

function CheckEMail( sEMail )
{
// Coerce the input to a string value and define specials

	var sInput = sEMail + "";
	var ksInvalid = "()<>@,;:\\\"[].";
	
// Break the string into its component parts

	var asParts = sInput.split( "@" );
		
	if( asParts.length != 2 )
		return true;

// Validate each part

	var nPart;
		
	for( nPart = 0; nPart < 2; nPart++ )
	{
	   // Analyse the part
		
	   var asAtoms = asParts[ nPart ].split( "." );
	   var nLength = 1;

	   if( nPart == 1 )
			nLength++;
				
	   if( asAtoms.length < nLength )
			return true;
				
	   // Check each atom to verify that it is valid
		
	   var nIndex;
			
	   for( nIndex = 0; nIndex < asAtoms.length; nIndex++ )
	   {
			if( asAtoms[ nIndex ].length < 1 )
				return true;
								
			var nScan;
							
			for( nScan = 0; nScan < asAtoms[ nIndex ].length; nScan++ )
			{
				var nChar = asAtoms[ nIndex ].charCodeAt( nScan );
				var sChar = asAtoms[ nIndex ].charAt( nScan );
								
				// Range check first.
												
				if( nChar == NaN || ( nChar < 33 || nChar > 126 ) )
					return true;
									
				// Check for specials.
										
				var nFind;
				nFind = ksInvalid.indexOf( sChar );
									
				if( nFind >= 0 )
					return true;
						
			} // [for] nScan
					
		} // [for] nIndex
			
	} // [for] nParts

// If we reached here, everything is OK

	return false;	
	
}


// Verifies that the Variable String Passed in matches the Verification
// string pattern supplied, as well as matches the Literal String provided.
//
//	sVariable		the string to check
//	sVerification	the string that holds the Verification Pattern
//	sLiteral		the string that has any Characters that are REQUIRED
//
// VARIABLE STRING contains the string to be VALIDATED
//		This string can contain any characters.
//
// VERIFICATION STRING contains only the following characters:
//		(which are defined below in the function)
//		N	-	Represents a Numeric Value is required
//				-> Variable character must be Numeric
//		L	-	Represents a Letter Value is required
//				-> Variable character must be a Letter
//		#	-	Represents a Constant Value is required 
//				-> Variable character must match Literal character
//		*	-	Represents a Wild Card Value is required
//				-> Variable character can be any value
//
// LITERAL STRING can contain any characters:
//		If corresponding character in the Verification String is either
//		N, L or * , character in Literal String should be *.
//		If corresponding character in the Verification String is #,
//		the character in the Literal String is whatever character the
//		Variable String requires in order to be VALID.
// 
// RETURNS
//		FALSE
//			- If Variable String Provided is shorter than Verification
//				String Provided.
//			- If the Literal String Provided is shorter than the 
//				Verification String Provided.
//			- If a Character in the Variable String does not Match the
//				corresponding character in the Verification & Literal
//				strings.
//			- If the Verification String contains an undefined Character
//
//		TRUE
//			- If the Variable String matches the Verification and
//				Literal Strings.
//
// CREATION
//		AUTHOR:	Brent Walker
//		DATE:	February 08, 2001
//
//	MODIFICATION
//		AUTHOR:	Brent Walker
//		DATE:	February 13-14, 2001
//
function AlphaNumericCheck( sVariable, sVerification, sLiteral )
{ 

	// Definition of Constants
	var sNumber = "N"						// Represents Numeric
	var sLetter = "L"						// Represents Letter
	var sConstant = "#"						// Represents Constant
	var sWild = "*"							// Represents Variable
	var nVerLength = sVerification.length;	// Length of the Verification String
	var nVarLength = sVariable.length;		// Length of the Variable String
	var nLitLength = sLiteral.length;		// Length of the Literal String
	var sNumbers = "0123456789";					// Defined numbers
	var sLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";	// Defined letters
	
	// Definition of Variables
	var sVarChar;		// Current Character from the Variable String
	var sVerChar;		// Current Character from the Verification String
	var sLitChar;		// Current Character from the Literal String
	var bFoundChars;	// Boolean used for calling function ConfirmCharacterString
	
	
		
	// Check to make sure all strings are the same length
	
	if( ( nVarLength != nVerLength ) || ( nLitLength != nVerLength ) )
	{
		// Return False, String Lengths are not the same
		
		return false;
	}
	
	// Convert all strings to UpperCase
	
	sVariable = sVariable.toUpperCase();
	sVerification = sVerification.toUpperCase();
	sLiteral = sLiteral.toUpperCase();
	
	for (var nIndex = 0; nIndex < nVerLength; nIndex++)
	{ 
		
		// Get the Current character from the Verification String
		
		sVerChar = sVerification.charAt(nIndex);

		// Check to see what the Verification Character is
		
		if( sVerChar == "N" )
		{

			// Get the Current character from the Variable String
				
			sVarChar = sVariable.charAt(nIndex);
		
			// Check to see if the Variable character is a number
				
			bFoundChars = ConfirmCharacterString( sVarChar, sNumbers );
					
			if( !bFoundChars )
			{
				return false;
			}
				
		}
		else
		{
			if( sVerChar == "L" )
			{
			
				// If the Verification Character is a Letter
			
				// Get the Current character from the Variable String
				
				sVarChar = sVariable.charAt(nIndex);
				
				// Check to see if the Variable character is a number
			
				bFoundChars = ConfirmCharacterString( sVarChar, sLetters );
				
				if( !bFoundChars )
				{
					return false;
				}

			}	    	    
		}    
	} 

	// Return True, Variable String Matches Verification Pattern
	
	return true;
		
} // [Function AlphaNumericCheck]


// Verifies that the Variable String Passed in matches one of the Verification
// string patterns supplied.
//
//	xsCharactersToCheck		the Characters to Check
//	xsValidation			the concatenated string of all possible matches
//							- no seperators are required, simply string all possible
//							  matches together into one string.
// 
// RETURNS
//		FALSE
//			- If verification String length is not a multiple of the
//				Varification String Provided.
//			- if the Variable string does not match any of the validation
//				patterns supplied in the validation string.
//
//		TRUE
//			- If the Variable String matches the Verification and
//				Literal Strings.
//
// CREATION
//		AUTHOR:	Brent Walker
//		DATE:	February 16, 2001
//
function ConfirmCharacterString ( xsCharactersToCheck, xsValidation )
{
	var nCheckLength = xsCharactersToCheck.length;	// Length of the string to check
	var nTotalLength = xsValidation.length;
	var nStartIndex;
	var nEndIndex;
	var sVerification;
	var nDivisible;		// is the length of the possible matches string divisible by length of Characters to Check
	
	nDivisible = (nTotalLength % nCheckLength);
	
	// The Length of Possible Matching Strings must be a multiple of the length of 
	// characters to check.
	
	if( nDivisible != 0 )
	{
		return false;
	}
	
	nStartIndex = 0;
	nEndIndex = nCheckLength;
	
	// Loop through all possible matches and see if they match the Characters to check
	
	while ( nEndIndex <= nTotalLength )
	{
	
		// Grab the next set of possible characters to match
		
		sVerification = xsValidation.slice(nStartIndex, nEndIndex)
		
		if( xsCharactersToCheck == sVerification)
		{
			return true;
		}
		
		// Update indexes
		
		nStartIndex = nEndIndex;
		nEndIndex = nEndIndex + nCheckLength;
	
	}	
	
	return false;
	
} // [Function ConfirmCharacterString]

//////////////////////////////////////////////////////////////////////////////////////////////////
// Validate the user passwords to ensure that they are not sequencial or repetative.
//
// sPassword - 	The string they have entered as a password.
//				This function assumes that the string has already been validated for illegal characters, length etc.
//
// Returns False if sPassword is either sequencial or repetative.		
// Where:
// 		Sequencial meaning that they do not contain either 01234567890 or abcdefghijklmnopqrstuvwxyz or any part thereof
// 		Repetative meaning at least one character in the string is different from the rest.  i.e. 11111 is no good, but 11112 is.
//////////////////////////////////////////////////////////////////////////////////////////////////

function ValidatePassword( sPassword )
{

	// Return true, unless one of the tests fail.
	
	var bReturn = true;

	// Check the password to ensure it's not repetative.
	// Compare every character to the first character( charAt( 0 ) ), if they are all the same, then by the end, the counter will be the length of the string.

	var nCounter = 0;

	do
	{

	nCounter++;

	}
	while( sPassword.charAt( nCounter ) == sPassword.charAt( 0 ) && nCounter <= sPassword.length );

	if( nCounter == sPassword.length )
	{

		bReturn = false;

	}

	// Check the password to ensure it's not sequencial( 01234567890, or abcdefghijklmnopqrstuvwxyz ).
	// If indexOf returns -1, it means that the substring ( sPassword ) does not exsist within the string being searched.

	if( "01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf( sPassword ) != -1 )
	{

		bReturn = false;

	}

	// Return Function
	
	return bReturn;

}


// Normalizes the North American Phone Number Supplied.
//	(All Phone Numbers Require Area Code)
//	(No Extensions are Allowed)
//
//	sPhoneNumber		the North American Phone Number to Normalize
// 
// RETURNS
//		""
//			- If the Phone Number Supplied is not 10 characters ( after stripping )
//
//		sTempZC
//			- The Normalized Phone Number, from the One Supplied. 
//
// CREATION
//		AUTHOR:	Brent Walker
//		DATE:	February 09, 2001
//

function ICNormalize_NAPhoneNumber ( sPhoneNumber )
{ 

	var sTempPhone;		// Modify a Copy of the string passed in
	var sAreaCode;		// The Area Code of the Phone Number
	var sPrefix;		// The First Part of the Phone Number
	var sSuffix;		// The Second Part of the Phone Number
	
	// Strip all spaces from the Phone Number
	sTempPhone = StripAllOccurrences(sPhoneNumber," ");
	
	// Strip all hyphens from the Phone Number
	sTempPhone = StripAllOccurrences(sTempPhone, "-");
	
	// Strip all Open Parenthesis from the Phone Number
	sTempPhone = StripAllOccurrences(sTempPhone, "(");
	
	// Strip all Open Parenthesis from the Phone Number
	sTempPhone = StripAllOccurrences(sTempPhone, ")");
	
	// Strip all dots from the Phone Number
	sTempPhone = StripAllOccurrences(sTempPhone, ".");
	
	// If the Long Distance Prefix, 1, was included, remove it.
	if (sTempPhone.charAt(0) == "1" )
	{ // Begin First Character is 1
	
		// Remove the Long Distance Prefix
		sTempPhone = sTempPhone.slice(1,sTempPhone.length);
	
	} // End First Character is 1
	
	// If the Phone Number is the Full Length, add formatting
	if (sTempPhone.length == 10)
	{
		// Grab the Area Code of the Phone Number
		sAreaCode = sTempPhone.slice(0,3);
	
		// Grab the Prefix of the Phone Number
		sPrefix = sTempPhone.slice(3,6);
		
		// Grab the Suffix of the Phone Number
		sSuffix = sTempPhone.slice(6,10);
		
		// Insert Formatting
		sTempPhone = "(";
		sTempPhone = sTempPhone.concat(sAreaCode);
		sTempPhone = sTempPhone.concat(") ");
		sTempPhone = sTempPhone.concat(sPrefix);
		sTempPhone = sTempPhone.concat("-");
		sTempPhone = sTempPhone.concat(sSuffix);
		
		// Return the Normalized Zip Code
		return sTempPhone;
	}
	
		// Return a Blank String
		return sPhoneNumber;

} 

// Validates the normalized North American Phone Number Supplied.
//
//	sNormPhoneNumber	the North American Phone Number to Validate
//						* MUST BE NORMALIZED ALREADY
// 
// RETURNS
//		FALSE
//			- If the Phone Number Supplied is not 14 Characters
//			- If the Phone Number Supplied does not match the Validation
//				string of (NNN) NNNNN-NNNN
//
//		TRUE
//			- If the Phone Number Supplied is VALID
//
// CREATION
//		AUTHOR:	Brent Walker
//		DATE:	February 09, 2001
//

function ICValidate_NAPhoneNumber ( sNormPhoneNumber )
{ 

	// All valid North American Area Codes
	var sValidAreaCodes = "201202203204205206207208209210212213214215216217218219224225227228229231234239240" +
						"242246248250251252253254256260262264267268269270276278281283284289300301302303304305306307308309310" + 
						"312313314315316317318319320321323325330331334336337339340341345347351352360361369380385386401402403404" +
						"405406407408409410412413414415416417418419423424425430432434435438440441442443445450456464469470473475478" + 
						"479480484500501502503504505506507508509510512513514515516517518519520530540541" + 
						"551557559561562563564567570571573574575580585586600601602603604605606607608609610612613614615616617618" +
						"619620623626627628630631636641646647649650651657659660661662664667669670671678679682689700701702703704705" +
						"706707708709712713714715716717718719720724727731732734740747752754757758760763764765767770" + 
						"772773775778780781784785786787800801802803804805806807808809810812813814815816817" + 
						"818819828830831832835843845847850856857858859860862863864865866867868869870872876877878880" + 
						"881882888900901902903904905906907908909910912913914915916917918919920925928931" +
						"935936937939940941947949951952954956959970971972973975978979980984985989";

	var bPhonePatternValid;		// Boolean for determining if Zip Code is Valid
	var bAreaCodeValid;
	var nPhoneLength;			// Length of the Zip Code String
	var sAreaCode;				// String that verifies the Area Code is Valid
	
	nPhoneLength = sNormPhoneNumber.length;
	
	// Check to see if the Phone Number is the Proper Length
	if (nPhoneLength == 14)
	{
		
		// Check to see if the Pattern Matches the Full North American Phone Number Pattern
		if( !AlphaNumericCheck( sNormPhoneNumber, "#NNN##NNN#NNNN", "(***) ***-****" ) )
			return false;
		
		sAreaCode = sNormPhoneNumber.slice(1,4);
		
		// Check to see if the Area Code is Valid
							
		//	bAreaCodeValid = ConfirmCharacterString( sAreaCode, sValidAreaCodes );
			
		//	if( bAreaCodeValid )
		//	{
				return true;
		//	}
					
	} // [if Length is 14]
	
	return false;
	
}


// Normalizes the Canadian Postal Code Supplied.
//
//	xsPostalCode		the Canadian Postal Code to Normalize
// 
// RETURNS
//		""
//			- If the (Space Stripped) Postal Code Supplied is not 6 Characters
//
//		sTempPC
//			- The Normalized Postal Code, from the One Supplied. 
//
// CREATION
//		AUTHOR:	Brent Walker
//		DATE:	February 08, 2001
//

function ICNormalize_CanadianPostalCode ( xsPostalCode )
{

	var sTempPC;		// Modify a Copy of the string passed in
	var sFirstHalf;		// Temp First Half of Postal Code
	var sSecondHalf;	// Temp Second Half of Postal Code
	
	var sPostalCode = xsPostalCode;
	
	// Strip all spaces from the Postal Code
	
	xsPostalCode = StripAllOccurrences(xsPostalCode," ");
	xsPostalCode = StripAllOccurrences(xsPostalCode,"-");
	
	// If the Postal Code is not the proper length
	
	if (xsPostalCode.length != 6)
	{
		// Return a Blank String
		return sPostalCode;
	}
	
	// Convert the Postal Code to Upper Case

	xsPostalCode = xsPostalCode.toUpperCase();
	
	// Grab the First Half of the Postal Code
	
	sFirstHalf = xsPostalCode.slice(0,3);
	
	// Grab the Second Half of the Postal Code

	sSecondHalf = xsPostalCode.slice(3,6);
	
	// Insert a Space between the two halves
	
	xsPostalCode = sFirstHalf.concat(" ");
	xsPostalCode = xsPostalCode.concat(sSecondHalf);
	
	var sNormPIN = "";

	for( var nCount = 0; nCount < 12; nCount++ )
	{
		if( xsPostalCode.charAt( nCount ).toUpperCase() == "O" )
			sNormPIN += "0";
		else
			sNormPIN += xsPostalCode.charAt( nCount ).toUpperCase();
	}

	xsPostalCode = sNormPIN;
	
	// Return the Normalized Postal Code
	
	return xsPostalCode;

} // [Function ICNormalize_CanadianPostalCode]


// Validates the normalized Canadian Postal Code Supplied.
//
//	sNormPostalCode		the Canadian Postal Code to Validate
//						* MUST BE NORMALIZED ALREADY
// 
// RETURNS
//		FALSE
//			- If the Postal Code Supplied is not 7 Characters
//			- If the Postal Code Supplied does not match the Validation
//				string of LNL NLN 
//			- If Characters 0, 2 or 6 are not valid Canada Post Letters.
//
//		TRUE
//			- If the Postal Code Supplied is VALID
//
// CREATION
//		AUTHOR:	Brent Walker
//		DATE:	February 08, 2001
//
//	MODIFICATION
//		AUTHOR:	Brent Walker
//		DATE:	February 13-14, 2001
//

function ICValidate_CanadianPostalCode ( sNormPostalCode )
{

	// Definition of Constants
	var sInvalidFirstCharacters = "DFIOQUWZ"	// Invalid Characters for the first Character
	var sInvalidCharacters = "DFIOQU";			// Invalid Characters for the third and fifth characters
	var nPCLength = sNormPostalCode.length;		// Length of the Postal Code String
	
	var bPCPatternValid;		// Boolean for determining if Postal Code is Valid
	var bInvalidChar;			// Boolean return value from function ConfirmCharacterString
	
	// Check to see if Postal Code is the Proper Length
	
	if (nPCLength == 7)
	{
	
		// Check to see if the Pattern Matches a Canadian Postal Code
		
		bPCPatternValid = AlphaNumericCheck( sNormPostalCode, "LNL#NLN", "*** ***" )
	
		if (bPCPatternValid == true)
		{
				
			// Verify the 1st character is valid
			
			sVarChar = sNormPostalCode.charAt(0);
			
			bInvalidChar = ConfirmCharacterString( sVarChar, sInvalidFirstCharacters );
				
			if( bInvalidChar )
			{
				return false;
			}
				
			
			// Verify the 3rd character is valid
			
			sVarChar = sNormPostalCode.charAt(2);
			
			bInvalidChar = ConfirmCharacterString( sVarChar, sInvalidCharacters );
				
			if( bInvalidChar )
			{
				return false;
			}
			
			// Verify the 5th character is valid
			
			sVarChar = sNormPostalCode.charAt(5);
			
			bInvalidChar = ConfirmCharacterString( sVarChar, sInvalidCharacters );
				
			if( bInvalidChar )
			{
				return false;
			}
			
		} // [If Pattern Matches]
		
		return bPCPatternValid;
		
	} // [If Length is Seven]
	
	return false;
	
} // [Function ICValidate_CanadianPostalCode]


// Removes any and all characters occurring in the string passed in, 
//	that are the same as the character to strip.
//		(leading, in between, trailing)
//
//	xsStringIn		The string to have all spaces removed.
//	sCharToStrip	The Character to remove from the String
// 
// RETURNS
//		sTempString
//			- The String Passed in, stripped of the supplied character.
//
// CREATION
//		AUTHOR:	Brent Walker
//		DATE:	February 08, 2001

//
function StripAllOccurrences ( xsStringIn, sCharToStrip )
{

	var nStringLength;		// length of the String
	var sVarChar;			// Current Character
	var sFirstPart;			// Part of String Previous to the found Space
	var sSecondPart;		// Part of String Trailing the found space
	var nIndex = 0;			// Used to Index the String
	
	nStringLength = xsStringIn.length;
	
	// Loop through string until you get to the end
	
	while ( nIndex <= nStringLength )
	{
		
		sVarChar = xsStringIn.charAt(nIndex);
		
		// If current character matches the character to strip

		if ( sVarChar == sCharToStrip )
		{ 		
			
			// Grab String before Character to be stripped
			
			sFirstPart = xsStringIn.slice(0, nIndex);
			
			// Grab the String after Character to be stripped
			
			sSecondPart = xsStringIn.slice(nIndex+1, nStringLength);
			
			// Put the two string parts back together
			
			xsStringIn = sFirstPart.concat(sSecondPart);
			
			// Update Indexes
			
			nIndex = nIndex - 1;
			nStringLength = nStringLength - 1;
		
		} // [if Character to Strip Found] 
		
		// Update Index
		
		nIndex ++;
			
	} // [while not at end of string]
	
	return xsStringIn;
	
} // End Function StripAllOccurances

// Check for a correct birthdate
// Returns true if the birthdate is incorrect

function CheckBirthday( nDay, nMonth, nYear )
{
	// Check if valid day and month values
	
	var dToday = new Date();

	if( nDay < 1 || nDay > 31 || nMonth < 1 || nMonth > 12 || nYear < 1900 || nYear > dToday.getFullYear() )
		return false;

	// Check the day for Apr, Jun, Sep, Nov

	if( ( nMonth == 4 || nMonth == 6 || nMonth == 9 || nMonth == 11 ) && ( nDay > 30 ) ) 
		return false;

	// Check the day for Feb

	if( nMonth == 2 )
	{
		// Check to see if it is leap year

		if( isLeapYear( nYear ) == true )
		{
			// Can go to 29 days

			if( nDay > 29 )
				return false;
		}
		else
		{
			// Can go to 28 days
			
			if( nDay > 28 )
			{
				return false;
			}
		}
	}
		
	// If we've made it here, the birthdate is correct
			
	return true;
}

function CalculateAge( nDay, nMonth, nYear, day, month, year )
{

	var age;

	if ( month < nMonth )
	{
	  age = year - nYear - 1;
	}
	else if ( month > nMonth ){
	  age = year - nYear;
	}
	else if ( month == nMonth ){
	  if ( day < nDay ){
	    age = year - nYear - 1;
	  }
	  else if ( day > nDay ){
	    age = year - nYear;
	  }
	  else if ( day == nDay ){
	    age = year - nYear;
	  }
	}

	if( age < 13 ) 
		return false;
	else 
		return true;
}

// Checks to see if the year is a leap year.
//	nYear		the year to check
// returns 	false not a leap year

function isLeapYear( nYear )
{
	if( nYear % 100 == 0 )
	{
		if( nYear % 400 == 0 )
		{ 
			return true; 
		}
	}
	else
	{
		if( ( nYear % 4 ) == 0 )
		{ 
			return true; 
		}
	}

	// If you made it here, it is not a leap year

	return false;

}


// Verifies that the Variable String Passed in matches the Verification
// string pattern supplied, as well as matches the Literal String provided.
//
//	sVariable		the string to check
//	sVerification	the string that holds the Verification Pattern
//	sLiteral		the string that has any Characters that are REQUIRED
//
// VARIABLE STRING contains the string to be VALIDATED
//		This string can contain any characters.
//
// VERIFICATION STRING contains only the following characters:
//		(which are defined below in the function)
//		N	-	Represents a Numeric Value is required
//				-> Variable character must be Numeric
//		L	-	Represents a Letter Value is required
//				-> Variable character must be a Letter
//		#	-	Represents a Constant Value is required 
//				-> Variable character must match Literal character
//		*	-	Represents a Wild Card Value is required
//				-> Variable character can be any value
//
// LITERAL STRING can contain any characters:
//		If corresponding character in the Verification String is either
//		N, L or * , character in Literal String should be *.
//		If corresponding character in the Verification String is #,
//		the character in the Literal String is whatever character the
//		Variable String requires in order to be VALID.
// 
// RETURNS
//		FALSE
//			- If Variable String Provided is shorter than Verification
//				String Provided.
//			- If the Literal String Provided is shorter than the 
//				Verification String Provided.
//			- If a Character in the Variable String does not Match the
//				corresponding character in the Verification & Literal
//				strings.
//			- If the Verification String contains an undefined Character
//
//		TRUE
//			- If the Variable String matches the Verification and
//				Literal Strings.
//
// CREATION
//		AUTHOR:	Brent Walker
//		DATE:	February 08, 2001
//
//	MODIFICATION
//		AUTHOR:	Brent Walker
//		DATE:	February 13-14, 2001
//
function AlphaNumericCheck( sVariable, sVerification, sLiteral )
{ 

	// Definition of Constants
	var sNumber = "N"						// Represents Numeric
	var sLetter = "L"						// Represents Letter
	var sConstant = "#"						// Represents Constant
	var sWild = "*"							// Represents Variable
	var nVerLength = sVerification.length;	// Length of the Verification String
	var nVarLength = sVariable.length;		// Length of the Variable String
	var nLitLength = sLiteral.length;		// Length of the Literal String
	var sNumbers = "0123456789";					// Defined numbers
	var sLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";	// Defined letters
	
	// Definition of Variables
	var sVarChar;		// Current Character from the Variable String
	var sVerChar;		// Current Character from the Verification String
	var sLitChar;		// Current Character from the Literal String
	var bFoundChars;	// Boolean used for calling function ConfirmCharacterString
	
	
		
	// Check to make sure all strings are the same length
	
	if( ( nVarLength != nVerLength ) || ( nLitLength != nVerLength ) )
	{
		// Return False, String Lengths are not the same
		
		return false;
	}
	
	// Convert all strings to UpperCase
	
	sVariable = sVariable.toUpperCase();
	sVerification = sVerification.toUpperCase();
	sLiteral = sLiteral.toUpperCase();
	
	for (var nIndex = 0; nIndex < nVerLength; nIndex++)
	{ 
		
		// Get the Current character from the Verification String
		
		sVerChar = sVerification.charAt(nIndex);

		// Check to see what the Verification Character is
		
		if( sVerChar == "N" )
		{

			// Get the Current character from the Variable String
				
			sVarChar = sVariable.charAt(nIndex);
		
			// Check to see if the Variable character is a number
				
			bFoundChars = ConfirmCharacterString( sVarChar, sNumbers );
					
			if( !bFoundChars )
			{
				return false;
			}
				
		}
		else
		{
			if( sVerChar == "L" )
			{
			
				// If the Verification Character is a Letter
			
				// Get the Current character from the Variable String
				
				sVarChar = sVariable.charAt(nIndex);
				
				// Check to see if the Variable character is a number
			
				bFoundChars = ConfirmCharacterString( sVarChar, sLetters );
				
				if( !bFoundChars )
				{
					return false;
				}

			}	    	    
		}    
	} 

	// Return True, Variable String Matches Verification Pattern
	
	return true;
		
} // [Function AlphaNumericCheck]


// Verifies that the Variable String Passed in matches one of the Verification
// string patterns supplied.
//
//	xsCharactersToCheck		the Characters to Check
//	xsValidation			the concatenated string of all possible matches
//							- no seperators are required, simply string all possible
//							  matches together into one string.
// 
// RETURNS
//		FALSE
//			- If verification String length is not a multiple of the
//				Varification String Provided.
//			- if the Variable string does not match any of the validation
//				patterns supplied in the validation string.
//
//		TRUE
//			- If the Variable String matches the Verification and
//				Literal Strings.
//
// CREATION
//		AUTHOR:	Brent Walker
//		DATE:	February 16, 2001
//
function ConfirmCharacterString ( xsCharactersToCheck, xsValidation )
{
	var nCheckLength = xsCharactersToCheck.length;	// Length of the string to check
	var nTotalLength = xsValidation.length;
	var nStartIndex;
	var nEndIndex;
	var sVerification;
	var nDivisible;		// is the length of the possible matches string divisible by length of Characters to Check
	
	nDivisible = (nTotalLength % nCheckLength);
	
	// The Length of Possible Matching Strings must be a multiple of the length of 
	// characters to check.
	
	if( nDivisible != 0 )
	{
		return false;
	}
	
	nStartIndex = 0;
	nEndIndex = nCheckLength;
	
	// Loop through all possible matches and see if they match the Characters to check
	
	while ( nEndIndex <= nTotalLength )
	{
	
		// Grab the next set of possible characters to match
		
		sVerification = xsValidation.slice(nStartIndex, nEndIndex)
		
		if( xsCharactersToCheck == sVerification)
		{
			return true;
		}
		
		// Update indexes
		
		nStartIndex = nEndIndex;
		nEndIndex = nEndIndex + nCheckLength;
	
	}	
	
	return false;
	
} // [Function ConfirmCharacterString]

//////////////////////////////////////////////////////////////////////////////////////////////////
// Validate the user passwords to ensure that they are not sequencial or repetative.
//
// sPassword - 	The string they have entered as a password.
//				This function assumes that the string has already been validated for illegal characters, length etc.
//
// Returns False if sPassword is either sequencial or repetative.		
// Where:
// 		Sequencial meaning that they do not contain either 01234567890 or abcdefghijklmnopqrstuvwxyz or any part thereof
// 		Repetative meaning at least one character in the string is different from the rest.  i.e. 11111 is no good, but 11112 is.
//////////////////////////////////////////////////////////////////////////////////////////////////

function ValidatePassword( sPassword )
{

	// Return true, unless one of the tests fail.
	
	var bReturn = true;

	// Check the password to ensure it's not repetative.
	// Compare every character to the first character( charAt( 0 ) ), if they are all the same, then by the end, the counter will be the length of the string.

	var nCounter = 0;

	do
	{

	nCounter++;

	}
	while( sPassword.charAt( nCounter ) == sPassword.charAt( 0 ) && nCounter <= sPassword.length );

	if( nCounter == sPassword.length )
	{

		bReturn = false;

	}

	// Check the password to ensure it's not sequencial( 01234567890, or abcdefghijklmnopqrstuvwxyz ).
	// If indexOf returns -1, it means that the substring ( sPassword ) does not exsist within the string being searched.

	if( "01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf( sPassword ) != -1 )
	{

		bReturn = false;

	}

	// Return Function
	
	return bReturn;

}


// Normalizes the North American Phone Number Supplied.
//	(All Phone Numbers Require Area Code)
//	(No Extensions are Allowed)
//
//	sPhoneNumber		the North American Phone Number to Normalize
// 
// RETURNS
//		""
//			- If the Phone Number Supplied is not 10 characters ( after stripping )
//
//		sTempZC
//			- The Normalized Phone Number, from the One Supplied. 
//
// CREATION
//		AUTHOR:	Brent Walker
//		DATE:	February 09, 2001
//

function ICNormalize_NAPhoneNumber ( sPhoneNumber )
{ 

	var sTempPhone;		// Modify a Copy of the string passed in
	var sAreaCode;		// The Area Code of the Phone Number
	var sPrefix;		// The First Part of the Phone Number
	var sSuffix;		// The Second Part of the Phone Number
	
	// Strip all spaces from the Phone Number
	sTempPhone = StripAllOccurrences(sPhoneNumber," ");
	
	// Strip all hyphens from the Phone Number
	sTempPhone = StripAllOccurrences(sTempPhone, "-");
	
	// Strip all Open Parenthesis from the Phone Number
	sTempPhone = StripAllOccurrences(sTempPhone, "(");
	
	// Strip all Open Parenthesis from the Phone Number
	sTempPhone = StripAllOccurrences(sTempPhone, ")");
	
	// Strip all dots from the Phone Number
	sTempPhone = StripAllOccurrences(sTempPhone, ".");
	
	// If the Long Distance Prefix, 1, was included, remove it.
	if (sTempPhone.charAt(0) == "1" )
	{ // Begin First Character is 1
	
		// Remove the Long Distance Prefix
		sTempPhone = sTempPhone.slice(1,sTempPhone.length);
	
	} // End First Character is 1
	
	// If the Phone Number is the Full Length, add formatting
	if (sTempPhone.length == 10)
	{
		// Grab the Area Code of the Phone Number
		sAreaCode = sTempPhone.slice(0,3);
	
		// Grab the Prefix of the Phone Number
		sPrefix = sTempPhone.slice(3,6);
		
		// Grab the Suffix of the Phone Number
		sSuffix = sTempPhone.slice(6,10);
		
		// Insert Formatting
		sTempPhone = "(";
		sTempPhone = sTempPhone.concat(sAreaCode);
		sTempPhone = sTempPhone.concat(") ");
		sTempPhone = sTempPhone.concat(sPrefix);
		sTempPhone = sTempPhone.concat("-");
		sTempPhone = sTempPhone.concat(sSuffix);
		
		// Return the Normalized Zip Code
		return sTempPhone;
	}
	
		// Return a Blank String
		return sPhoneNumber;

} 

// Validates the normalized North American Phone Number Supplied.
//
//	sNormPhoneNumber	the North American Phone Number to Validate
//						* MUST BE NORMALIZED ALREADY
// 
// RETURNS
//		FALSE
//			- If the Phone Number Supplied is not 14 Characters
//			- If the Phone Number Supplied does not match the Validation
//				string of (NNN) NNNNN-NNNN
//
//		TRUE
//			- If the Phone Number Supplied is VALID
//
// CREATION
//		AUTHOR:	Brent Walker
//		DATE:	February 09, 2001
//

function ICValidate_NAPhoneNumber ( sNormPhoneNumber )
{ 

	// All valid North American Area Codes
	var sValidAreaCodes = "201202203204205206207208209210212213214215216217218219224225227228229231234239240" +
						"242246248250251252253254256260262264267268269270276278281283284289300301302303304305306307308309310" + 
						"312313314315316317318319320321323325330331334336337339340341345347351352360361369380385386401402403404" +
						"405406407408409410412413414415416417418419423424425430432434435438440441442443445450456464469470473475478" + 
						"479480484500501502503504505506507508509510512513514515516517518519520530540541" + 
						"551557559561562563564567570571573574575580585586600601602603604605606607608609610612613614615616617618" +
						"619620623626627628630631636641646647649650651657659660661662664667669670671678679682689700701702703704705" +
						"706707708709712713714715716717718719720724727731732734740747752754757758760763764765767770" + 
						"772773775778780781784785786787800801802803804805806807808809810812813814815816817" + 
						"818819828830831832835843845847850856857858859860862863864865866867868869870872876877878880" + 
						"881882888900901902903904905906907908909910912913914915916917918919920925928931" +
						"935936937939940941947949951952954956959970971972973975978979980984985989";

	var bPhonePatternValid;		// Boolean for determining if Zip Code is Valid
	var bAreaCodeValid;
	var nPhoneLength;			// Length of the Zip Code String
	var sAreaCode;				// String that verifies the Area Code is Valid
	
	nPhoneLength = sNormPhoneNumber.length;
	
	// Check to see if the Phone Number is the Proper Length
	if (nPhoneLength == 14)
	{
		
		// Check to see if the Pattern Matches the Full North American Phone Number Pattern
		if( !AlphaNumericCheck( sNormPhoneNumber, "#NNN##NNN#NNNN", "(***) ***-****" ) )
			return false;
		
		sAreaCode = sNormPhoneNumber.slice(1,4);
		
		// Check to see if the Area Code is Valid
							
		//	bAreaCodeValid = ConfirmCharacterString( sAreaCode, sValidAreaCodes );
			
		//	if( bAreaCodeValid )
		//	{
				return true;
		//	}
					
	} // [if Length is 14]
	
	return false;
	
}

function GetStatus( sStatus, nBit )
{
    var nResult = sStatus.substr( nBit, 1 );
    
    if( nResult == 1 )
        return true;
    else
        return false;
}

function o_TextLimit( sField, sCount )
{
    try
    {
        nLimit = nMaxChar;
        var sValue = sField.value;
       
        if( sValue.length > nLimit )
        {
            sField.value = sField.value.substring( 0, nLimit - 1 );
        }
        else
            sCount.innerText = nLimit - sValue.length;
    }
    catch( e )
    {
        // do nothing
    }
}
