// VARIABLE DECLARATIONS

var digits = "0123456789";

var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"

var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"


// whitespace characters
var whitespace = " \t\n\r";


// decimal point character differs by language and culture
var decimalPointDelimiter = "."


// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";


// characters which are allowed in US phone numbers
var validUSPhoneChars = digits + phoneNumberDelimiters;


// non-digit characters which are allowed in 
// Social Security Numbers
var SSNDelimiters = "- ";

// characters which are allowed in Social Security Numbers
var validSSNChars = digits + SSNDelimiters;



// U.S. Social Security Numbers have 9 digits.
// They are formatted as 123-45-6789.
var digitsInSocialSecurityNumber = 9;

// U.S. phone numbers have 10 digits.
// They are formatted as 123 456 7890 or (123) 456-7890.
var digitsInUSPhoneNumber = 10;



// non-digit characters which are allowed in ZIP Codes
var ZIPCodeDelimiters = "-";

// our preferred delimiter for reformatting ZIP Codes
var ZIPCodeDelimeter = "-"

// characters which are allowed in Social Security Numbers
var validZIPCodeChars = digits + ZIPCodeDelimiters


// U.S. ZIP codes have 5 or 9 digits.
// They are formatted as 12345 or 12345-6789.
var digitsInZIPCode1 = 5
var digitsInZIPCode2 = 9

//Employee ID 4 digits.
// They are formatted as 1234.
var digitsInEmpId1 = 1

//Voice mail size

var digitsInVoiceMail1 = 4

// non-digit characters which are allowed in credit card numbers
var creditCardDelimiters = " "

//COMET Charge Code digits.
var digitsInChargeCode = 24

// preferred delimeter for reformatting COMET Charge Code
var ChargeCodeDelimiter = "-"

// non-digit preferred delimeter for COMET Charge Code
var ChargeCodeDelimiters = "- ";

// characters which are allowed in Charge Code numbers
var validChargeCodeChars = digits + ChargeCodeDelimiters


// CONSTANT STRING DECLARATIONS
// (grouped for ease of translation and localization)

// m is an abbreviation for "missing"

var mPrefix = "You did not enter a value into the "
var mSuffix = " field. This is a required field. Please enter it now."

// s is an abbreviation for "string"

var sGeneric = "selected"
var sInteger = "Integer"
var sVpRequest = "Requesting VP"
var sUSLastName = "Last Name"
var sUSFirstName = "First Name"
var sEmpId = "Employee ID"
var sDeliveryLastName = "Last Name"
var sDeliveryFirstName = "First Name"
var sWorldLastName = "Family Name"
var sWorldFirstName = "Given Name"
var sTitle = "Title"
var sCompanyName = "Company Name"
var sUSAddress = "Street Address"
var sCity = "City"
var sStateCode = "State Code"
var sWorldState = "State, Province, or Prefecture"
var sEmpResp = "Employee Resp. for Assets"
var sCountry = "Country"
var sZIPCode = "ZIP Code"
var sPhone = "Phone Number"
var sVoiceMail = "Voice Mail Number"
var sFax = "Direct Dial TSC Phone Num."
var sDateOfBirth = "Date of Birth"
var sDateOfChange = "Change Address Date"
var sDateOfRequest = " Date of Request"
var sExpirationDate = "Expiration Date"
var sEmail = "Email"
var sSSN = "Social Security Number"
var sOtherInfo = "Other Information"
var radio_selection1="";
var radio_selection2="";
var radio_selection3="";
var radio_selection4="";
var radio_selection5="";
var radio_selection6="";
var radio_selection7="";
var radio_selection8="";
var radio_selection9="";
var radio_selection10="";
var SocialSecurityNumber="";




// i is an abbreviation for "invalid"

var iFloat = "This field requires a decimal number (like 10.32). Please re-enter it now."
var iInt = "This field must be a valid integer (like 1, 2, or 3). Please re-enter it now."
var iStateCode = "This field must be a valid two character U.S. state abbreviation (like CA for California). Please re-enter it now."
var iEmpId = "This field must be an integer (like 1, 2, 3, etc.). Please re-enter it now."
var iVoiceMail = "This field must be a 4 digit integer (like 1234). Please re-enter it now."
var iZIPCode = "This field must be a 5 or 9 digit U.S. ZIP Code (like 94043). Please re-enter it now."
var iUSPhone = "This field must be a 10 digit U.S. phone number (like 415 555 1212). Please re-enter it now."
var iWorldPhone = "This field must be a valid international phone number. Please re-enter it now."
var iSSN = "This field must be a 9 digit U.S. social security number (like 123 45 6789). Please re-enter it now."
var iEmail = "This field must be a valid email address (like john@techsol.com). Please re-enter it now."
var iCreditCardPrefix = "This is not a valid "
var iCreditCardSuffix = " credit card number. (Click the link on this form to see a list of sample numbers.) Please re-enter it now."
var iDay = "This field must be a day number between 1 and 31.  Please re-enter it now."
var iMonth = "This field must be a month number between 1 and 12.  Please re-enter it now."
var iYear = "This field must be a 2 or 4 digit year number.  Please re-enter it now."
var iDatePrefix = "The Day, Month, and Year for "
var iDateSuffix = " do not form a valid date.  Please re-enter them now."
var iBankABANumber = "Bank ABA/ Transit number is a 9 digit number (like 652308713). Please re-enter it now."
var iChargeCode = "Charge Code number is a 24 digit number (like 002625-234576-098756-019282). Please re-enter it now."


// p is an abbreviation for "prompt"

var pEntryPrompt = "Please enter a "
var pStateCode = "2 character code (like CA)."
var pEmpId = "valid integer (like 1234)."
var pZIPCode = "5 or 9 digit U.S. ZIP Code (like 94043)."
var pUSPhone = "10 digit U.S. phone number (like 415 555 1212)."
var pVoiceMail = "4 digit voice mail number (like 1212)."
var pWorldPhone = "international phone number."
var pSSN = "9 digit U.S. social security number (like 123 45 6789)."
var pEmail = "valid email address (like john@techsol.com)."
var pCreditCard = "valid credit card number."
var pDay = "day number between 1 and 31."
var pMonth = "month number between 1 and 12."
var pYear = "2 or 4 digit year number."
var pBankABANumber = "9 digit number (like 652308713)."
var pVpRequest = "Requesting VP's full name."
var pChargeCode = "charge code (like 002625-234576-098756-019282)."

var defaultEmptyOK = false

// Attempting to make this library run on Navigator 2.0,
// so I'm supplying this array creation routine as per
// JavaScript 1.0 documentation.  If you're using 
// Navigator 3.0 or later, you don't need to do this;
// you can use the Array constructor instead.

function makeArray(n) {
//*** BUG: If I put this line in, I get two error messages:
//(1) Window.length can't be set by assignment
//(2) daysInMonth has no property indexed by 4
//If I leave it out, the code works fine.
//   this.length = n;
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}



var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;




// Valid U.S. Postal Codes for states, territories, armed forces, etc.
// See http://www.usps.gov/ncsc/lookups/abbr_state.txt.

var USStateCodeDelimiter = "|";
var USStateCodes = "AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY|AE|AA|AE|AE|AP"

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}



// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}



// Removes all characters which appear in string bag from string s.

function stripCharsInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}



// Removes all characters which do NOT appear in string bag 
// from string s.

function stripCharsNotInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}



// Removes all whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.

function stripWhitespace (s)

{   return stripCharsInBag (s, whitespace)
}




// WORKAROUND FUNCTION FOR NAVIGATOR 2.0.2 COMPATIBILITY.
//
// The below function *should* be unnecessary.  In general,
// avoid using it.  Use the standard method indexOf instead.
//
// However, because of an apparent bug in indexOf on 
// Navigator 2.0.2, the below loop does not work as the
// body of stripInitialWhitespace:
//
// while ((i < s.length) && (whitespace.indexOf(s.charAt(i)) != -1))
//   i++;
//
// ... so we provide this workaround function charInString
// instead.
//
// charInString (CHARACTER c, STRING s)
//
// Returns true if single character c (actually a string)
// is contained within string s.

function charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false
}



// Removes initial (leading) whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.

function stripInitialWhitespace (s)

{   var i = 0;

    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    
    return s.substring (i, s.length);
}


// Returns true if character c is an English letter 
// (A .. Z, a..z).
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}



// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}



// Returns true if character c is a letter or digit.

function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}


function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}


function isSignedInteger (s)

{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}


function isPositiveInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isPositiveInteger.arguments.length > 1)
        secondArg = isPositiveInteger.arguments[1];


    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
}


function isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}

function isNegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNegativeInteger.arguments.length > 1)
        secondArg = isNegativeInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) < 0) ) );
}

function isNonpositiveInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonpositiveInteger.arguments.length > 1)
        secondArg = isNonpositiveInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) <= 0) ) );
}

function isFloat (s)

{   var i;
    var seenDecimalPoint = false;

    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}


function isSignedFloat (s)

{   if (isEmpty(s)) 
       if (isSignedFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedFloat.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedFloat.arguments.length > 1)
            secondArg = isSignedFloat.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isFloat(s.substring(startPos, s.length), secondArg))
    }
}


function isAlphabetic (s)

{   var i;

    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphabetic character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);

        if (!isLetter(c))
        return false;
    }

    // All characters are letters.
    return true;
}

function isAlphanumeric (s)

{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) {return defaultEmptyOK};
       else return (isAlphanumeric.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    // All characters are numbers or letters.
    return true;
}

// isSSN (STRING s [, BOOLEAN emptyOK])
// 
// isSSN returns true if string s is a valid U.S. Social
// Security Number.  Must be 9 digits.
//
// NOTE: Strip out any delimiters (spaces, hyphens, etc.)
// from string s before calling this function.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isSSN (s)
{   if (isEmpty(s))
	   if (isSSN.arguments.length == 1) return defaultEmptyOK;
       else return (isSSN.arguments[1] == true);
    return (isInteger(s) && s.length == digitsInSocialSecurityNumber)
}

function reformat (s)

{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

function isUSPhoneNumber (s)
{   if (isEmpty(s)) 
       if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isUSPhoneNumber.arguments[1] == true);
    return (isInteger(s) && s.length == digitsInUSPhoneNumber)
}

function isZIPCode (s)
{  if (isEmpty(s)) 
       if (isZIPCode.arguments.length == 1) return defaultEmptyOK;
       else return (isZIPCode.arguments[1] == true);
   return (isInteger(s) && 
            ((s.length == digitsInZIPCode1) ||
             (s.length == digitsInZIPCode2)))
}

function isStateCode(s)
{   if (isEmpty(s)) 
       if (isStateCode.arguments.length == 1) return defaultEmptyOK;
       else return (isStateCode.arguments[1] == true);
    return ( (USStateCodes.indexOf(s) != -1) &&
             (s.indexOf(USStateCodeDelimiter) == -1) )
}


function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;

    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}


/* FUNCTIONS TO NOTIFY USER OF INPUT REQUIREMENTS OR MISTAKES. */


// Display prompt string s in status bar.

function prompt (s)
{   window.status = s
}

// Display data entry prompt string s in status bar.

function promptEntry (s)
{   window.status = pEntryPrompt + s
}

function warnEmpty (theField, s)
{   
	if (typeof(theField) != "undefined")
	{
		theField.focus();
	    alert(mPrefix + s + mSuffix);
	    return false;
	}
}

function warnInvalid (theField, s)
{   
	if (typeof(theField) != "undefined")
	{
		theField.focus();
	    theField.select();
	    alert(s);
	    return false;
	}
}

function checkString (theField, s, emptyOK)
{   
	if (typeof(theField) != "undefined")
	{
		// Next line is needed on NN3 to avoid "undefined is not a number" error
	    // in equality comparison below.
	    if (checkString.arguments.length == 2) 
		{
			emptyOK = defaultEmptyOK;
		}
	    
		if ((emptyOK == true) && (isEmpty(theField.value))) 
		{
			return true;
		}
	    
		if (isWhitespace(theField.value)) 
		{
	       return warnEmpty (theField, s);
		}
	    else
		{
			return true;
		}
	}
}

function checkStateCode (theField, emptyOK)
{   
	if (typeof(theField) != "undefined")
	{
		if (checkStateCode.arguments.length == 1) 
		{
			emptyOK = defaultEmptyOK;
		}
		
	    if ((emptyOK == true) && (isEmpty(theField.value))) 
		{
			return true;
		}
	    else
	    {  
			theField.value = theField.value.toUpperCase();
	        if (!isStateCode(theField.value, false))
			{
	          return warnInvalid (theField, iStateCode);
			}
	       else
		   {
		   	 return true;
			}
	    }
	}
}

// takes ZIPString, a string of 5 or 9 digits;
// if 9 digits, inserts separator hyphen

function reformatZIPCode (ZIPString)
{   if (ZIPString.length == 5) return ZIPString;
    else return (reformat (ZIPString, "", 5, "-", 4));
}

function checkInt (theField, emptyOK)
{  
	if (typeof(theField) != "undefined")
	{
		if (checkInt.arguments.length == 1) 
		{
			emptyOK = defaultEmptyOK;
		}
		
	    if ((emptyOK == true) && (isEmpty(theField.value))) 
		{
			return true;
		}
	    else
	    { 
			var normalizedInt = stripCharsInBag(theField.value, EmpIdDelimiters)
	      	if (!isInteger(normalizedInt, false)) 
			{
	         return warnInvalid (theField, iInt);
			}
	        else
	        {
	  		    return true;
	        }   
	    }
	}
}


function reformatUSPhone (USPhone)
{   return (reformat (USPhone, "(", 3, ") ", 3, "-", 4))
}

function checkUSPhone (theField, emptyOK)
{
	if (typeof(theField) != "undefined")
	{
		if (checkUSPhone.arguments.length == 1) 
		{
			emptyOK = defaultEmptyOK;
		}
		
	    if ((emptyOK == true) && (isEmpty(theField.value))) 
		{
			return true;
		}
	    else
	    {  
			var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
	       	if (!isUSPhoneNumber(normalizedPhone, false)) 
			{
	          return warnInvalid (theField, iUSPhone);
			}
	       else 
	       {  
		   		// if you don't want to reformat as (123) 456-7890, comment next line out
		        theField.value = reformatUSPhone(normalizedPhone)
	    	    return true;
	       }
	    }
	}
}

function checkEmail (theField, emptyOK)
{   
	if (typeof(theField) != "undefined")
	{
		if (checkEmail.arguments.length == 1) 
		{
			emptyOK = defaultEmptyOK;
		}
		
	    if ((emptyOK == true) && (isEmpty(theField.value))) 
		{
			return true;
		}			
	    else if (!isEmail(theField.value, false)) 
		{
	       return warnInvalid (theField, iEmail);
		}
	    else 
		{
			return true;
		}
	}
}

function reformatSSN (SSN)
{   return (reformat (SSN, "", 3, "-", 2, "-", 4))
}

function checkEmpId (theField, emptyOK)
{   
	if (typeof(theField) != "undefined")
	{
		if (checkEmpId.arguments.length == 1) 
		{
			emptyOK = defaultEmptyOK;
		}
		
	    if ((emptyOK == true) && (isEmpty(theField.value))) 
		{
			return true;
		}
	    else
	    { 
			var normalizedEmp = stripCharsInBag(theField.value, EmpIdDelimiters)
	      	if (!isEmpId(normalizedEmp, false)) 
			{
	        	return warnInvalid (theField, iEmpId);
			}
		    else
	      	{
		      return true;
		    }   
	    }
	}
}


function checkSSN (theField, emptyOK)
{  	
	if (typeof(theField) != "undefined")
	{
		if (checkSSN.arguments.length == 1) 
		{	
			emptyOK = defaultEmptyOK;
		}
		
	    if ((emptyOK == true) && (isEmpty(theField.value))) 
		{
			return true;
		}
	    else
	    {  
			var normalizedSSN = stripCharsInBag(theField.value, SSNDelimiters)
	        if (!isSSN(normalizedSSN, false)) 
			{
	        	return warnInvalid (theField, iSSN);
			}
	       	else 
	        {  
				// if you don't want to reformats as 123-456-7890, comment next line out
			    theField.value = reformatSSN(normalizedSSN)
		        return true;
			}
	      }
	  }
  }

// (2) functions below take a single date input

function checkDate(theField, sDateName, emptyOk) {

if (emptyOk == false && theField.value == "")
	{
		alert("\nPlease enter a valid " + sDateName + " date.  (mm/dd/yyyy)");
		theField.focus();
		return false;
	}
else
	{
		if (theField.value != "" && !isDate(theField.value))
			{
				alert("\nPlease enter a valid " + sDateName + " date. (mm/dd/yyyy)");
				theField.select();
				theField.focus();
				return false;
			}
		else 
			{
				return true;
			}
	}		
}

function isDate(dateStr) {

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?

if (matchArray == null) {
return false;
}

month = matchArray[1]; // p@rse date into variables
day = matchArray[3];
year = matchArray[5];

if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}

if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}

if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn`t have 31 days!")
return false;
}

if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day==29 && !isleap)) {
alert("February " + year + " doesn`t have " + day + " days!");
return false;
}
}
return true; // date is valid
}


function checkVisibility(menu)
{
var myindex=document.forms[0].dbcVisibilityBit.selectedIndex	
	
		if(myindex == 0)
			{
			alert("\nPlease choose Home Page Visibility from the drop-down menu.");
			window.document.forms[0].dbcVisibilityBit.focus();
			return false;
			}
		else
			{
			return true;
			}
}


function checkArticleType(menu)

{
var myindex=document.forms[0].dbcArticleType.selectedIndex	
	
		if(myindex == 0)
			{
			alert("\nPlease select an Article Type from the drop-down menu.");
			window.document.forms[0].dbcArticleType.focus();
			return false;
			}
		else
			{
			return true;
			}
}

// Get checked value from radio button.

function getRadioButtonValue (radio)
{   
	if (typeof(theField) != "undefined")
	{
		for (var i = 0; i < radio.length; i++)
	    {   
			if (radio[i].checked) 
			{ 
				break;
			}
	    }
	    return radio[i].value;
	}
}






