// Copyright 2006 ATAC Corporation
// Copying or distributing contents expressly forbidden.
// ALL RIGHTS RESERVED.

// Organization
var CapName = "TASFAA";
var SmallName = "tasfaa";
// Form document index [ Custom ]
var FormIndex = 0;

//////////////////////   FORM VALIDATION FUNCTION   ///////////////////////

function validatePersonalInfo(form)
{
  return (
    checkString(form.elements["LastName"],sLastName)
  );
}

//////////////////////   FORM STRING DECLARATIONS   ///////////////////////

// s is an abbreviation for "string"
var sLastName = "Last Name";

////////////////////////   TEST VALIDATION PAGE   /////////////////////////

function displayPersonalInfo(form)
{
  var outputPage = "<html>\n<head>\n<title>Results</title>\n</head>\n<body bgcolor=\"#ffffff\">\n\n";
      outputPage += "<h2>Data Entered:</h2>\n\n";

  var sStr = "";
  var outputTable = "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"512\">\n";
      outputTable += "<tr>\n<td>";
      outputTable += "<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" width=\"512\" bgcolor=\"#F7F7F7\">\n";
      outputTable += "<tr>\n<td width=\"250\">";
      outputTable += "<img src=\"/graphics/dot.gif\" width=\"250\" height=\"1\" border=\"0\" alt=\"\">";
      outputTable += "</td>\n<td width=\"250\">";
      outputTable += "<img src=\"/graphics/dot.gif\" width=\"250\" height=\"1\" border=\"0\" alt=\"\">";
      outputTable += "</td>\n</tr>\n\n<tr>\n<td colspan=\"2\">";
      outputTable += "<p>Since this is a validation test, the Submit button or form.submit() function ";
      outputTable += "has been replaced with the following.</p>";
      outputTable += "</td>\n</tr>\n\n";
  var rowCount = 0;
  var rowColor = "";
  var radioButtonName = "";
  var lastRadioButton = "";
  var selectName = "";

  for(i = 0; i < form.elements.length - 2; i++)
  {
    sStr = "s" + form.elements[i].name;
    if (rowCount % 2 == 0) { rowColor = "<tr bgcolor=\"#b0c4de\">"; }
    else { rowColor = "<tr>"; }
    
    if(form.elements[i].type == "radio")
    {
      radioButtonName = form.elements[i].name;
      if (radioButtonName != lastRadioButton)
      {
        outputTable += rowColor + "\n<td valign=\"top\">" + eval(sStr) + "</td>\n<td valign=\"top\">";
        outputTable += getRadioButtonValue(form.elements[radioButtonName]);
        outputTable += "</td>\n</tr>\n\n";
        lastRadioButton = radioButtonName;
        rowCount++;
      }
    }
    else if(form.elements[i].type == "checkbox")
    {
      var checkBoxValue = "";
      if(form.elements[i].checked) { checkBoxValue = form.elements[i].value; }
      outputTable += rowColor + "\n<td valign=\"top\">" + eval(sStr) + "</td>\n<td valign=\"top\">";
      outputTable += checkBoxValue;
      outputTable += "</td>\n</tr>\n\n";
      rowCount++;
    }
    else if(form.elements[i].type == "select-one")
    {
      selectName = form.elements[i].name;
      outputTable += rowColor + "\n<td valign=\"top\">" + eval(sStr) + "</td>\n<td valign=\"top\">";
      outputTable += getSelectedOneValue(form.elements[selectName]);
      outputTable += "</td>\n</tr>\n\n";
      rowCount++;
    }
    else if(form.elements[i].type == "select-multiple")
    {
      selectName = form.elements[i].name;
      outputTable += rowColor + "\n<td valign=\"top\">" + eval(sStr) + "</td>\n<td valign=\"top\">";
      outputTable += getSelectedMultValue(form.elements[selectName]);
      outputTable += "</td>\n</tr>\n\n";
      rowCount++;
    }
    else
    {
      outputTable += rowColor + "\n<td valign=\"top\">" + eval(sStr) + "</td>\n<td valign=\"top\">";
      outputTable += form.elements[i].value;
      outputTable += "</td>\n</tr>\n\n";
      rowCount++;
    }
  }
  outputTable += "</table></td>\n</tr>\n</table>\n\n";
  
  outputPage += outputTable + "</body>\n</html>";
  document.writeln(outputPage);
  document.close();
  return true;
}


////////////////////   CONSTANT STRING DECLARATIONS   /////////////////////

// m is an abbreviation for "missing"
var mPrefix = "You did not enter a value into the ";
var mSuffix = " field. This is a required field.\nPlease enter it.";

// p is an abbreviation for "prompt"
var pEntryPrompt = "Please enter ";
var pStateCode = "a 2 character code (like CA).";
var pZipCode = "a 5 or 9 digit Zip Code (like 12345 or 12345-1234).";
var pPostCode = "a postal code such as a US Zip Code, Canadian Postal Code, etc.";
var pPhone = "a 10 digit phone number (like 415 555 1212).";
var pEmail = "a valid email address (like yourname@someplace.com).";
var pGroup = "form for this group";
var pDay = "a day number between 1 and 31.";
var pMonth = "a month number between 1 and 12.";
var pYear = "a 4 digit year number.";
var pPicName = "a valid graphic filename (like MaryJones.jpg or SamGoodman.gif).";
var pCheckMark = "a checkmark.";
var pRadioButton = "1 selection.";
var pSelectOne = "1 selection.";
var pSelectMultiple = "multiple selections.";
var pSSN = "a 9 digit social security number (like 123 45 6789).";
var pCreditCard = "a valid credit card number.";
var pChoice = "number (1, 2, 3, etc.)";
var pFrmtNumber = "a number only (like 150 or 19.95)";
var pPaymentMethod = "the method of payment (check number, type of credit card, etc.)";

// i is an abbreviation for "invalid"
var iStateCode = "This field must be a valid two character state abbreviation (like CA for California).\nPlease reenter it.";
var iZipCode = "This field must be a 5 or 9 digit Zip Code (like 12345 or 12345-1234).\nPlease reenter it.";
var iPostCode = "This field must be a US Zip Code, Canadian Postal Code, etc.\nPlease reenter it.";
var iPhone = "This field must be a 10 digit phone number (like 415 555 1212).\nPlease reenter it.";
var iEmail = "This field must be a valid email address (like yourname@someplace.com).\nPlease reenter it.";
var iMonthText = "This field must be a month number between 1 and 12. Please reenter it.";
var iMonthSubmit = "This field must be a month name. Please reenter it.";
var iDay = "This field must be a day number between 1 and 31.\nPlease reenter it.";
var iYear = "This field must be a 4 digit year number.\nPlease reenter it.";
var iDatePrefix = "The Day, Month, and Year for ";
var iDateSuffix = " do not form a valid date.\nPlease reenter them now.";
var iPicName = "This field must have a graphic filename (like MaryJones.jpg or SamGoodman.gif).\nPlease reenter it.";
var iWholeNumber = "This field must contain digits only.\nPlease reenter the number.";
var iFloatNumber = "This field must only contain digits or digits and a decimal point.\nPlease reenter the number.";
var iCheckBoxes = "One, and only one, of the checkboxes in this group must be selected.";
var iSSN = "This field must be a 9 digit social security number (like 123 45 6789).\nPlease reenter it.";
var iCreditCardPrefix = "This is not a valid ";
var iCreditCardSuffix = " credit card number.\nPlease reenter it.";
var iNoDupicates = "This group must not contain any duplicates.\nPlease eliminate all duplicates.";
var iNoMatch = "The data entered twice does not match.\nPlease reenter it.";
var iTooMany = "Too many have been selected in this group.";

// 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 phone numbers
var validPhoneChars = digits + phoneNumberDelimiters;

// U.S. phone numbers have 10 digits.
// They are formatted as 123 456 7890 or (123) 456-7890.
var digitsInPhoneNumber = 10;

// non-digit characters which are allowed in Zip Codes
var ZipCodeDelimiters = "-";

// our preferred delimiter for reformatting Zip Codes
var ZipCodeDelimeter = "-";

// U.S. Zip codes have 5 or 9 digits.
// They are formatted as 12345 or 12345-6789.
var digitsInZipCode1 = 5;
var digitsInZipCode2 = 9;

// characters which are allowed in Social Security Numbers
var validZipCodeChars = digits + ZipCodeDelimiters;

// 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;

// non-digit characters which are allowed in credit card numbers
var creditCardDelimiters = " ";

// Global variable defaultEmptyOK defines default return value
var defaultEmptyOK = false;

// Array Creation Routine for Older Browsers
function makeArray(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.
var StateCodeDelimiter = "|";
var StateCodes = "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|AB|BC|MB|NB|NL|NS|NT|NU|ON|PE|QC|SK|YT";


//////////////////////////   STRING FUNCTIONS   ///////////////////////////

// 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;
  if(isEmpty(s)) { return true; }
  for(i = 0; i < s.length; i++)
  {   
    var c = s.charAt(i);
    if(whitespace.indexOf(c) == -1) { return false; }
  }
  return true;
}

// Removes all characters which appear in string bag from string s.
function stripCharsInBag(s, bag)
{
  var i;
  var returnString = "";
  for(i = 0; i < s.length; i++)
  {   
    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 = "";
  for(i = 0; i < s.length; i++)
  {   
    var c = s.charAt(i);
    if (bag.indexOf(c) != -1) returnString += c;
  }
  return returnString;
}

// Removes all whitespace characters from s.
function stripWhitespace(s)
{
  return stripCharsInBag(s, whitespace);
}

// Returns true if single character c 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.
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).
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));
}


//////////////////////////   INTEGER FUNCTIONS   //////////////////////////

// isInteger (STRING s [, BOOLEAN emptyOK])
function isInteger(s)
{
  var i;
  if(isEmpty(s)) 
  {
    if(isInteger.arguments.length == 1) { return defaultEmptyOK; }
    else { return (isInteger.arguments[1] == true); }
  }
  for(i = 0; i < s.length; i++)
  {   
    var c = s.charAt(i);
    if(!isDigit(c)) { return false; }
  }
  return true;
}

// isSignedInteger (STRING s [, BOOLEAN emptyOK])
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]; }
    if((s.charAt(0) == "-") || (s.charAt(0) == "+")) { startPos = 1; }
    return (isInteger(s.substring(startPos, s.length), secondArg));
  }
}

// isPositiveInteger (STRING s [, BOOLEAN emptyOK])
function isPositiveInteger(s)
{
  if(s == "08") { s = "8"; }
  if(s == "09") { s = "9"; }
  var secondArg = defaultEmptyOK;
  if(isPositiveInteger.arguments.length > 1) { secondArg = isPositiveInteger.arguments[1]; }
  return (isSignedInteger(s, secondArg) && ((isEmpty(s) && secondArg) || (parseInt(s) > 0)));
}

// isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
function isNonnegativeInteger(s)
{
  if(s == "08") { s = "8"; }
  if(s == "09") { s = "9"; }
  var secondArg = defaultEmptyOK;
  if(isNonnegativeInteger.arguments.length > 1) { secondArg = isNonnegativeInteger.arguments[1]; }
  return (isSignedInteger(s, secondArg) && ((isEmpty(s) && secondArg) || (parseInt(s) >= 0)));
}

// isNegativeInteger (STRING s [, BOOLEAN emptyOK])
function isNegativeInteger(s)
{
  if(s == "08") { s = "8"; }
  if(s == "09") { s = "9"; }
  var secondArg = defaultEmptyOK;
  if(isNegativeInteger.arguments.length > 1) { secondArg = isNegativeInteger.arguments[1]; }
  return (isSignedInteger(s, secondArg) && ((isEmpty(s) && secondArg) || (parseInt(s) < 0)));
}

// isNonpositiveInteger (STRING s [, BOOLEAN emptyOK])
function isNonpositiveInteger(s)
{
  if(s == "08") { s = "8"; }
  if(s == "09") { s = "9"; }
  var secondArg = defaultEmptyOK;
  if(isNonpositiveInteger.arguments.length > 1) { secondArg = isNonpositiveInteger.arguments[1]; }
  return (isSignedInteger(s, secondArg) && ((isEmpty(s) && secondArg) || (parseInt(s) <= 0)));
}

// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
function isIntegerInRange(s, a, b)
{
  if(isEmpty(s))
  {
    if(isIntegerInRange.arguments.length == 1) { return defaultEmptyOK; }
    else { return (isIntegerInRange.arguments[1] == true); }
  }
  if(!isInteger(s, false)) { return false; }
  if(s == "08") { s = "8"; }
  if(s == "09") { s = "9"; }
  var num = parseInt (s);
  return ((num >= a) && (num <= b));
}

// isWholeNumber (STRING s [, BOOLEAN emptyOK])
function isWholeNumber(s)
{
  if (isEmpty(s))
  {
    if (isWholeNumber.arguments.length == 1) { return defaultEmptyOK; }
    else { return (isWholeNumber.arguments[1] == true); }
  }
  if (!isNonnegativeInteger(s)) { return false; }
  return true;
}


//////////////////////   FLOATING POINT FUNCTIONS   ///////////////////////

// isFloat (STRING s [, BOOLEAN emptyOK])
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; }
  for(i = 0; i < s.length; i++)
  {   
    var c = s.charAt(i);
    if((c == decimalPointDelimiter) && !seenDecimalPoint) { seenDecimalPoint = true; }
    else if(!isDigit(c)) { return false; }
  }
  return true;
}

// isSignedFloat (STRING s [, BOOLEAN emptyOK])
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]; }
    if((s.charAt(0) == "-") || (s.charAt(0) == "+")) { startPos = 1; }
    return (isFloat(s.substring(startPos, s.length), secondArg));
  }
}


/////////////////   ALPHABETIC, ALPHANUMERIC FUNCTIONS   //////////////////

// isAlphabetic (STRING s [, BOOLEAN emptyOK])
function isAlphabetic(s)
{
  var i;
  if(isEmpty(s)) 
  {
    if(isAlphabetic.arguments.length == 1) { return defaultEmptyOK; }
    else { return (isAlphabetic.arguments[1] == true); }
  }
  for(i = 0; i < s.length; i++)
  {   
    var c = s.charAt(i);
    if(!isLetter(c)) { return false; }
  }
  return true;
}

// isAlphanumeric (STRING s [, BOOLEAN emptyOK])
function isAlphanumeric(s)
{
  var i;
  if (isEmpty(s)) 
  {
    if(isAlphanumeric.arguments.length == 1) { return defaultEmptyOK; }
    else { return (isAlphanumeric.arguments[1] == true); }
  }
  for (i = 0; i < s.length; i++)
  {   
    var c = s.charAt(i);
    if(!(isLetter(c) || isDigit(c))) { return false; }
  }
  return true;
}

////////////////////////   REFORMATING FUNCTIONS   ////////////////////////

// reformat (TARGETSTRING, STRING, INTEGER, STRING, INTEGER ... )       
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;
}

// isSSN (STRING s [, BOOLEAN emptyOK])
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);
}

// isPhoneNumber (STRING s [, BOOLEAN emptyOK])
function isPhoneNumber(s)
{
  if(isEmpty(s))
  {
    if(isPhoneNumber.arguments.length == 1) { return defaultEmptyOK; }
    else { return (isPhoneNumber.arguments[1] == true); }
  }
  return (isInteger(s) && s.length == digitsInPhoneNumber);
}

// isZipCode (STRING s [, BOOLEAN emptyOK])
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)));
}

// isStateCode (STRING s [, BOOLEAN emptyOK])
function isStateCode(s)
{
  if(isEmpty(s))
  {
    if(isStateCode.arguments.length == 1) { return defaultEmptyOK; }
    else { return (isStateCode.arguments[1] == true); }
  }
  return ((StateCodes.indexOf(s) != -1) && (s.indexOf(StateCodeDelimiter) == -1));
}

// isEmail (STRING s [, BOOLEAN emptyOK])
function isEmail(s)
{
  if(isEmpty(s))
  {
    if(isEmail.arguments.length == 1) { return defaultEmptyOK; }
    else { return (isEmail.arguments[1] == true); }
  }
  if(isWhitespace(s)) { return false; }
  var i = 1;
  var sLength = s.length;
  while((i < sLength) && (s.charAt(i) != "@")) { i++; }
  if((i >= sLength) || (s.charAt(i) != "@")) { return false; }
  else { i += 2; }
  while((i < sLength) && (s.charAt(i) != ".")) { i++; }
  if((i >= sLength - 1) || (s.charAt(i) != ".")) { return false; }
  else { return true; }
}

///////////////////////////   DATE FUNCTIONS   ////////////////////////////

// isYear (STRING s [, BOOLEAN emptyOK])
function isYear(s)
{
  if(isEmpty(s))
  {
    if(isYear.arguments.length == 1) { return defaultEmptyOK; }
    else { return (isYear.arguments[1] == true); }
  }
  if(!isNonnegativeInteger(s)) { return false; }
  return ((s.length == 2) || (s.length == 4));
}

// isMonth (STRING s [, BOOLEAN emptyOK])
function isMonth(s)
{
  if(isEmpty(s)) 
  {
    if(isMonth.arguments.length == 1) { return defaultEmptyOK; }
    else { return (isMonth.arguments[1] == true); }
  }
  return (isIntegerInRange(s, 1, 12));
}

// isDay (STRING s [, BOOLEAN emptyOK])
function isDay(s)
{
  if(isEmpty(s))
  {
    if(isDay.arguments.length == 1) { return defaultEmptyOK; }
    else { return (isDay.arguments[1] == true); }
  }
  return (isIntegerInRange(s, 1, 31));
}

// daysInFebruary (INTEGER year)
function daysInFebruary(year)
{
  return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

// isDate (STRING year, STRING month, STRING day)
function isDate(year, month, day)
{
  if(!(isYear(year, false) && isMonth(month, false) && isDay(day, false))) { return false; }
  if(year == "08") { year = "8"; }
  if(year == "09") { year = "9"; }
  var intYear = parseInt(year);
  
  if(month == "08") { month = "8"; }
  if(month == "09") { month = "9"; }
  var intMonth = parseInt(month);
  
  if(day == "08") { day = "8"; }
  if(day == "09") { day = "9"; }
  var intDay = parseInt(day);
  
  if(intDay > daysInMonth[intMonth]) { return false; }
  if((intMonth == 2) && (intDay > daysInFebruary(intYear))) { return false; }
  return true;
}


/////////   NOTIFY OF INPUT REQUIREMENTS OR MISTAKES FUNCTIONS   //////////

// Display prompt string s in status bar.
function promptStatusBar(s)
{
  window.status = s;
}

// Display data entry prompt string s in status bar.
function promptEntry(s)
{
  window.status = pEntryPrompt + s;
}

// Notify user that required field, theField, is empty.
function warnEmpty(theField, s)
{
  theField.focus();
  alert(mPrefix + s + mSuffix);
  return false;
}

// Notify user that contents of field theField are invalid.
function warnInvalid(theField, s)
{
  theField.focus();
  theField.select();
  alert(s);
  return false;
}


////////////////////////   CHECK FIELD FUNCTIONS   ////////////////////////

// checkString (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
function checkString(theField, s, emptyOK)
{
  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; }
}

// checkWholeNumber (TEXTFIELD theField [, BOOLEAN emptyOK==false])
function checkWholeNumber(theField, emptyOK)
{
  if(checkWholeNumber.arguments.length == 1) { emptyOK = defaultEmptyOK; }
  if((emptyOK == true) && (isEmpty(theField.value))) { return true; }
  if(!isWholeNumber(theField.value, false)) { return warnInvalid(theField, iWholeNumber); }
  else { return true; }
}

// checkFloatNumber (TEXTFIELD theField [, BOOLEAN emptyOK==false])
function checkFloatNumber(theField, emptyOK)
{
  if(checkFloatNumber.arguments.length == 1) { emptyOK = defaultEmptyOK; }
  if((emptyOK == true) && (isEmpty(theField.value))) { return true; }
  if(!isFloat(theField.value, false)) { return warnInvalid(theField, iFloatNumber); }
  else { return true; }
}

// checkInstitution (TEXTFIELD theNumber, TEXTFIELD theField, string [, BOOLEAN emptyOK==false])
function checkInstitution(theNumber, theField, s, emptyOK)
{
  if(checkInstitution.arguments.length == 3) { emptyOK = defaultEmptyOK; }
  if((emptyOK == true) && (isEmpty(theNumber.value))) { return true; }
  if(!isWholeNumber(theNumber.value, false)) { return warnInvalid(theNumber, iWholeNumber); }
  if(theNumber.value > 0) { return true; }
  if((theNumber.value == 0) && (checkString(theField, s))) { return true; }
}

// checkForLimits (TEXTFIELD theField [, BOOLEAN emptyOK==false])
function checkForLimits(theField, minValue, maxValue, emptyOK)
{
  var fieldName = theField.name;
  var fieldValue = parseInt(theField.value);

  if(checkForLimits.arguments.length == 3) { emptyOK = defaultEmptyOK; }
  if((emptyOK == false) && (theField.value == ""))
  {
    return warnEmpty(theField, eval("s" + fieldName));
  }
  if((fieldValue < minValue) || (fieldValue > maxValue))
  {
    var errorText = "This field must contain a number greater than or equal to " + minValue;
    errorText += " and less than or equal to " + maxValue + ".";

  return warnInvalid(theField, errorText);
  }
  else { return true; }
}

// checkForDuplicates (TEXTFIELD theField [, BOOLEAN emptyOK==false])
function checkForDuplicates(theField, emptyOK)
{
  var fieldName = "";
  var formFieldName = theField.name;
  var groupName = formFieldName.split("_")[0];
  var groupNameLength = groupName.length;
  var tempArray = new Array();
  var count = 0;
  var testValue = "";
  var compareValue = "";
    
  if(checkForDuplicates.arguments.length == 1) { emptyOK = defaultEmptyOK; }
  for(i = 0; i < document.forms[FormIndex].elements.length; i++)
  {
    fieldName = document.forms[FormIndex].elements[i].name;
    if(fieldName.substring(0,groupNameLength) == groupName)
    {
      if((emptyOK == false) && (document.forms[FormIndex].elements[i].value == ""))
      {
        return warnEmpty(document.forms[FormIndex].elements[i], eval("s" + fieldName));
      }
      if(document.forms[FormIndex].elements[i].value)
      {
        tempArray[count] = document.forms[FormIndex].elements[i].value;
        count++;
      }
    }
  }
  tempArray.sort();
  for(i = 0 ; i < tempArray.length; i++)
  {
    testValue = "" + tempArray[i];
    if(testValue == compareValue) { return warnInvalid(theField, iNoDupicates); }
    else { compareValue = testValue; }
  }
  return true;
}
    
// checkStateCode (TEXTFIELD theField [, BOOLEAN emptyOK==false])
function checkStateCode(theField, emptyOK)
{
  var codestring = "";
  if(checkStateCode.arguments.length == 1) { emptyOK = defaultEmptyOK; }
  codestring = theField.value;
  if(codestring.length == 1) { return warnInvalid(theField, iStateCode); }
  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)); }
}

// checkZipCode (TEXTFIELD theField [, BOOLEAN emptyOK==false])
function checkZipCode(theField, emptyOK)
{
  if(checkZipCode.arguments.length == 1) { emptyOK = defaultEmptyOK; }
  if((emptyOK == true) && (isEmpty(theField.value))) { return true; }
  else
  {
    var normalizedZip = stripCharsInBag(theField.value, ZipCodeDelimiters);
    if(!isZipCode(normalizedZip, false)) { return warnInvalid(theField, iZipCode); }
    else 
    {
      theField.value = reformatZipCode(normalizedZip);
      return true;
    }
  }
}

// takes Phone, a string of 10 digits and reformats as (123) 456-789
function reformatPhone(Phone)
{
  return (reformat(Phone, "(", 3, ") ", 3, "-", 4));
}

// checkPhone (TEXTFIELD theField [, BOOLEAN emptyOK==false])
function checkPhone(theField, emptyOK)
{
  if(checkPhone.arguments.length == 1) { emptyOK = defaultEmptyOK; }
  if((emptyOK == true) && (isEmpty(theField.value))) { return true; }
  else
  {
    var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters);
    if(!isPhoneNumber(normalizedPhone, false)) { return warnInvalid(theField, iPhone); }
    else 
    {
      theField.value = reformatPhone(normalizedPhone);
      return true;
    }
  }
}

// checkEmail (TEXTFIELD theField [, BOOLEAN emptyOK==false])
function checkEmail(theField, emptyOK)
{
  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; }
}

// takes SSN, a string of 9 digits and reformats as 123-45-6789
function reformatSSN(SSN)
{
  return (reformat(SSN, "", 3, "-", 2, "-", 4));
}

// Check that string theField.value is a valid SSN.
function checkSSN(theField, emptyOK)
{
  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 
    {
      theField.value = reformatSSN(normalizedSSN);
      return true;
    }
  }
}

// Check that string theField.value is a valid Year.
function checkYear(theField, emptyOK)
{
  if(checkYear.arguments.length == 1) { emptyOK = defaultEmptyOK; }
  if(theField.type == "text")
  {
    if((emptyOK == true) && (isEmpty(theField.value))) { return true; }
    if(theField.value.length < 4 ) { return warnInvalid(theField, iYear); }
    if(!isYear(theField.value, false)) { return warnInvalid(theField, iYear); }
    else { return true; }
  }
  else
  {
    if(emptyOK == true) { return true; }
    if(!isYear(theField.options[theField.selectedIndex].value, false))
    {
      alert(iYear);
      theField.focus();
      return false;
    }
    else { return true; }
  }
}

// Check that string theField.value is a valid Month.
function checkMonth(theField, emptyOK)
{
  var iMonth = "";
  if(checkMonth.arguments.length == 1) { emptyOK = defaultEmptyOK; }
  if(theField.type == "text")
  {
    iMonth = iMonthText;
    if((emptyOK == true) && (isEmpty(theField.value))) { return true; }
    if(!isMonth(theField.value, false)) { return warnInvalid(theField, iMonth); }
    else { return true; }
  }
  else
  {
    iMonth = iMonthSubmit;
    if(emptyOK == true) { return true; }
    if(!isMonth(theField.options[theField.selectedIndex].value, false))
    {
      alert(iMonth);
      theField.focus();
      return false;
    }
    else { return true; }
  }
}

// Check that string theField.value is a valid Day.
function checkDay(theField, emptyOK)
{
  if(checkDay.arguments.length == 1) { emptyOK = defaultEmptyOK; }
  if(theField.type == "text")
  {
    if((emptyOK == true) && (isEmpty(theField.value))) { return true; }
    if(!isDay(theField.value, false)) { return warnInvalid(theField, iDay); }
    else { return true; }
  }
  else
  {
    if(emptyOK == true) { return true; }
    if(!isDay(theField.options[theField.selectedIndex].value, false))
    {
      alert(iDay);
      theField.focus();
      return false;
    }
    else { return true; }
  }  
}

// checkDate (yearField, monthField, dayField, STRING labelString [, OKtoOmitDay==false])
function checkDate(yearField, monthField, dayField, labelString, OKtoOmitDay)
{
  var iMonth = "";
  if(monthField.type == "text") { iMonth = iMonthText; }
  else { iMonth = iMonthSubmit; }
  if(checkDate.arguments.length == 4) { OKtoOmitDay = false; }
  if(!isYear(yearField.value)) { return warnInvalid(yearField, iYear); }
  if(!isMonth(monthField.value)) { return warnInvalid(monthField, iMonth); }
  if((OKtoOmitDay == true) && isEmpty(dayField.value)) { return true; }
  else if(!isDay(dayField.value)) { return warnInvalid(dayField, iDay); }
  if(isDate(yearField.value, monthField.value, dayField.value)) { return true; }
  monthField.focus();
  alert(iDatePrefix + labelString + iDateSuffix);
  return false;
}

// checkMissingDate (yearField, monthField, dayField, STRING labelString [, BOOLEAN AllEmptyOK==false])
function checkMissingDate(yearField, monthField, dayField, labelString, AllEmptyOK)
{
  if(checkMissingDate.arguments.length == 4) { AllEmptyOK = defaultEmptyOK; }
  var emptyFlag = 0;
  if(isEmpty(yearField.value)) { emptyFlag++; }
  if(isEmpty(monthField.value)) { emptyFlag++; }
  if(isEmpty(dayField.value)) { emptyFlag++; }
  if((AllEmptyOK == true) && (emptyFlag == 3)) { return true; }
  else if((AllEmptyOK == true) && (emptyFlag == 0)) { return true; }
  else if((AllEmptyOK == false) && (emptyFlag == 0)) { return true; }
  else
  {
    labelString = labelString;
    return warnInvalid(monthField, labelString);
  }
}

// checkMatch (firstField, secondField, STRING s, [, BOOLEAN emptyOK==false])
// check to see if firstField equals secondField
function checkMatch(field1, field2, emptyOK)
{
  if(checkMatch.arguments.length == 2) { emptyOK = defaultEmptyOK; }
  if((emptyOK == true) && (isEmpty(field1.value)) && (isEmpty(field2.value))) { return true; }
  else
  {
    if(field1.value != field2.value) { return warnInvalid(field1, iNoMatch); }
    else { return true; }
  }
}

// checkRadioButton (RADIOBUTTON theField,  STRING s, [, BOOLEAN emptyOK==false])
// check to see if any radio button was selected in group
function checkRadioButton(radio, s, emptyOK)
{
  var flag = 0;
  for(var i = 0; i < radio.length; i++)
  {
    if(radio[i].checked ) { flag = 1; }
  }
  if((emptyOK == true) && (flag == 0)) { return true; }
  else if(flag == 1) { return true; }
  else
  {
    alert(mPrefix + s + mSuffix);
    radio[0].focus();
    return false;
  }
}

// Get checked value from radio button
// button checked on load get value of currently selected button
function getRadioButtonValue(radio)
{
  for (var i = 0; i < radio.length; i++)
  {
    if (radio[i].checked) { break; }
  }
  return radio[i].value;
}

// checkAnyCheckBoxes (CHECKBOX theField,  STRING s, NUMBER num (0,1,2,>2) [, BOOLEAN emptyOK==false])
// num: 0 = independent, 1 = group - only one checked, 2 = group - one or more checked, >2 = no more than this checked
// Any Checkboxes Selected?
function checkAnyCheckBoxes(theField, s, num, emptyOK)
{
  if(checkAnyCheckBoxes.arguments.length == 3) { emptyOK = defaultEmptyOK; }
  var formFieldName = theField.name;
  var flag = 0;
  if(num > 0)
  {
    var groupName = formFieldName.split("_")[0];
    var groupNameLength = groupName.length;
    
    for(i = 0; i < document.forms[FormIndex].elements.length; i++)
    {
      fieldName = document.forms[FormIndex].elements[i].name;
      if(fieldName.substring(0,groupNameLength) == groupName)
      {
        if(document.forms[FormIndex].elements[i].checked) { flag++; }
      }
    }
  }
  else
  {
    if(theField.checked) { flag++; }
  }
  if((emptyOK == true) && (flag == 0)) { return true; }
  else if(flag == 1) { return true; }
  else if((flag > 1) && (num == 1)) { return warnInvalid(theField, iCheckBoxes); }
  else if((flag > 1) && (num == 2) && (flag <= num)) { return true; }
  else if((flag > 1) && (num == 2) && (flag > num)) { return warnInvalid(theField, iTooMany); }
  else if((flag > 1) && (num > 2) && (flag <= num)) { return true; }
  else if((flag > 1) && (num > 2) && (flag > num)) { return warnInvalid(theField, iTooMany); }
  else { return warnEmpty(theField, s); }
}

// CheckPicName
function checkPicName(theField, s, emptyOK)
{
  if(checkPicName.arguments.length == 2) { emptyOK = defaultEmptyOK; }
  if((emptyOK == true) && (isEmpty(theField.value))) { return true; }
  var picStr = theField.value;
  if((picStr.indexOf(".gif") != -1) || (picStr.indexOf(".jpg") != -1)) { return true; }
  else { return warnInvalid(theField, s); }
}

// checkSendPic
function checkSendPic(checkField, theField, s)
{
  var checkFieldValue = getRadioButtonValue(checkField);
  var fileFieldValue = theField.value;
  if((checkFieldValue == "No") && (fileFieldValue == "")) { return true; }
  if((checkFieldValue == "No") && (fileFieldValue != ""))
  {
    var confirmChoice = confirm("You have selected NOT to send the file. Is that OK?");
    if(confirmChoice)
    {
      theField.value = "";
      return true;
    }
    else
    {
      alert("Please select \"YES\" if you wish to send the file.");
      checkField[0].focus();
      return false;
    }
  }
  if(checkFieldValue == "Yes") { return checkPicName(theField, s); }
}

// checkSelect (SELECT theField,  STRING s, [, BOOLEAN emptyOK==false])
// check to see if a selection was made in group
function checkSelect(theField, s, emptyOK)
{
  var flag = 0;
  var result = "";
  for(var i = 0; i < theField.length; i++)
  {
    if(theField.options[i].selected) { flag = 1; }
  }
  if((emptyOK == true) && (flag == 0)) { return true; }
  else if (flag == 1) { return true; }
  else
  {
    alert(mPrefix + s + mSuffix);
    theField.focus();
    return false;
  }
}

// Get selected value from select
// use the selectedIndex property to fill the index value
function getSelectedOneValue(theField)
{
  var result = theField.options[theField.selectedIndex].value;
  return result;
}

// Get selected value(s) from multiple select
// cycle through list to get all selected values
function getSelectedMultValue(theField)
{
  var result = "";
  for (var i = 0; i < theField.length; i++)
  {
    if (theField.options[i].selected) { result += "<br>\n" + theField.options[i].value; }
  }
  result = "Selection(s):" + result;
  return result;
}

// Focus on Next Field
// Used with amount TEXT boxes to prohibit changing values
function focusNextField(theField)
{
  var thisFieldName = theField.name;
  var flag = 0;
  for(i = 0; i < document.forms[FormIndex].elements.length; i++)
  {
    if(document.forms[FormIndex].elements[i].name == thisFieldName)
    {
      flag = i + 1;
    }
  }
  if(flag > 0)
  {
    document.forms[FormIndex].elements[(flag)].focus();
    return true;
  }
  else { return false; }
}

////////////////////////   CREDIT CARD FUNCTIONS   ////////////////////////

// Validate credit card info. Encoding only works on cards with less than 19 digits.
function checkCreditCard(radio, theField)
{
  var cardType = getRadioButtonValue(radio);
  var normalizedCCN = stripCharsInBag(theField.value, creditCardDelimiters);
  if (!isCardMatch(cardType, normalizedCCN)) 
    {
      return warnInvalid(theField, iCreditCardPrefix + cardType + iCreditCardSuffix);
    }
  else 
  {
    theField.value = normalizedCCN;
    return true;
  }
}

// isCreditCard (STRING card number)
function isCreditCard(st)
{
  if(st.length > 19) { return (false); }
  
  sum = 0;
  mul = 1;
  l = st.length;

  for(i = 0; i < l; i++)
  {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if(tproduct >= 10) { sum += (tproduct % 10) + 1; }
    else { sum += tproduct; }
    if(mul == 1) { mul++; }
    else { mul--; }
  }
  if((sum % 10) == 0) { return (true); }
  else { return (false); }
}

// isVisa (STRING card number)
function isVisa(cc)
{
  if(((cc.length == 16) || (cc.length == 13)) && (cc.substring(0,1) == 4))
  {
    return isCreditCard(cc);
  }
  return false;
}
    
// isMasterCard (STRING card number)
function isMasterCard(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if((cc.length == 16) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5)))
  {
    return isCreditCard(cc);
  }
  return false;
}

// isAmericanExpress (STRING card number)
function isAmericanExpress(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if((cc.length == 15) && (firstdig == 3) && ((seconddig == 4) || (seconddig == 7)))
  {
    return isCreditCard(cc);
  }
  return false;
}

// isDinersClub (STRING card number)
function isDinersClub(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if((cc.length == 14) && (firstdig == 3) && ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))
  {
    return isCreditCard(cc);
  }
  return false;
}

// isCarteBlanche (STRING card number)
function isCarteBlanche(cc)
{
  return isDinersClub(cc);
}

// isDiscover (STRING card number)
function isDiscover(cc)
{
  first4digs = cc.substring(0,4);
  if((cc.length == 16) && (first4digs == "6011"))
  {
    return isCreditCard(cc);
  }
  return false;
}

// isEnRoute (STRING card number)
function isEnRoute(cc)
{
  first4digs = cc.substring(0,4);
  if((cc.length == 15) && ((first4digs == "2014") || (first4digs == "2149")))
  {
    return isCreditCard(cc);
  }
  return false;
}

// isJCB (STRING card number)
function isJCB(cc)
{
  first4digs = cc.substring(0,4);
  if((cc.length == 16) && ((first4digs == "3088") || (first4digs == "3096") || (first4digs == "3112") ||
       (first4digs == "3158") || (first4digs == "3337") || (first4digs == "3528")))
  {
    return isCreditCard(cc);
  }
  return false;
}

// isAnyCard (STRING card number)
function isAnyCard(cc)
{
  if(!isCreditCard(cc)) { return false; }
  if(!isMasterCard(cc) && !isVisa(cc) && !isAmericanExpress(cc) && !isDinersClub(cc) &&
      !isDiscover(cc) && !isEnRoute(cc) && !isJCB(cc))
  {
    return false;
  }
  return true;
}

// isCardMatch (STRING card type, STRING card number)
function isCardMatch(cardType, cardNumber)
{
  cardType = cardType.toUpperCase();
  var doesMatch = true;
  if((cardType == "VISA") && (!isVisa(cardNumber)))
  {
    doesMatch = false;
  }
  if((cardType == "MASTERCARD") && (!isMasterCard(cardNumber)))
  {
    doesMatch = false;
  }
  if(((cardType == "AMERICANEXPRESS") || (cardType == "AMEX")) && (!isAmericanExpress(cardNumber)))
  {
    doesMatch = false;
  }
  if((cardType == "DISCOVER") && (!isDiscover(cardNumber)))
  {
    doesMatch = false;
  }
  if((cardType == "JCB") && (!isJCB(cardNumber)))
  {
    doesMatch = false;
  }
  if((cardType == "DINERS") && (!isDinersClub(cardNumber)))
  {
    doesMatch = false;
  }
  if((cardType == "CARTEBLANCHE") && (!isCarteBlanche(cardNumber)))
  {
    doesMatch = false;
  }
  if((cardType == "ENROUTE") && (!isEnRoute(cardNumber)))
  {
    doesMatch = false;
  }
  return doesMatch;
}

// the following sub functions are retained for backward compatibility
function IsCC (st)
{
  return isCreditCard(st);
}

function IsVisa (cc)
{
  return isVisa(cc);
}

function IsVISA (cc)
{
  return isVisa(cc);
}

function IsMasterCard (cc)
{
  return isMasterCard(cc);
}

function IsMastercard (cc)
{
  return isMasterCard(cc);
}

function IsMC (cc)
{
  return isMasterCard(cc);
}

function IsAmericanExpress (cc)
{
  return isAmericanExpress(cc);
}

function IsAmEx (cc)
{
  return isAmericanExpress(cc);
}

function IsDinersClub (cc)
{
  return isDinersClub(cc);
}

function IsDC (cc)
{
  return isDinersClub(cc);
}

function IsDiners (cc)
{
  return isDinersClub(cc);
}

function IsCarteBlanche (cc)
{
  return isCarteBlanche(cc);
}

function IsCB (cc)
{
  return isCarteBlanche(cc);
}

function IsDiscover (cc)
{
  return isDiscover(cc);
}

function IsEnRoute (cc)
{
  return isEnRoute(cc);
}

function IsenRoute (cc)
{
  return isEnRoute(cc);
}

function IsJCB (cc)
{
  return isJCB(cc);
}

function IsAnyCard(cc)
{
  return isAnyCard(cc);
}

function IsCardMatch(cardType, cardNumber)
{
  return isCardMatch (cardType, cardNumber);
}


//////////////////////////   CALCULATED FIELDS   //////////////////////////
//  sumAmt (TEXTFIELD theField, NUMBER Amount [, BOOLEAN emptyOK])
function sumAmt(theField, amt, totals)
{
  var thisFieldName = theField.name;
  var groupName = thisFieldName.split("_")[0];
  var itemName = thisFieldName.split("_")[1];
  var group_item_Name = groupName + "_" + itemName;
  var numberItems = 0;
  var totalValue = 0.00;
  if(parseInt(theField.value) > 0)
  {
    numberItems = parseInt(theField.value);
    totalValue = numberItems * amt;
  }
  for(i = 0; i < document.forms[FormIndex].elements.length; i++)
  {
    if(document.forms[FormIndex].elements[i].name == group_item_Name + "_amt")
    {
      document.forms[FormIndex].elements[i].value = moneyFormat(totalValue);
    }
  }
  return subtotalsTotals(groupName);
}

// checkDate (TEXTFIELD checkbox field, STRING amountString [, addTotals==false])
// Enter Amount
function enterAmt(theField, amt, totals)
{
  var thisFieldName = theField.name;
  var flag = 0;
  
  for(i = 0; i < document.forms[FormIndex].elements.length; i++)
  {
    if(document.forms[FormIndex].elements[i].name == thisFieldName)
    {
      flag = i + 1;
    }
  }
    
  if(theField.checked) { document.forms[FormIndex].elements[flag].value = amt; }
  else { document.forms[FormIndex].elements[flag].value = "0"; }

  if(enterAmt.arguments.length == 2) { return true; }
  else { return subtotalsTotals(thisFieldName); }
}

// subtotalsTotals (TEXTFIELD current field name)
function subtotalsTotals(fieldName)
{
// Extract Group Name
  var groupName = fieldName.split("_")[0];
  var groupNameLength = groupName.length;
  var firstSubTotalFlag = 0;
  var subTotal = 0;
  var thisSubTotalFlag = 0;
  var total = 0;
  var totalFlag1 = 0;
  var totalFlag2 = 0;

  for(i = 0; i < document.forms[FormIndex].elements.length; i++)
  {
    fieldName = document.forms[FormIndex].elements[i].name;
    
    search_Number = fieldName.length - 6;
    search_SubTotalAmt = fieldName.length - 11;
    search_TotalAmt = fieldName.length - 8;
    
    if((fieldName.substring(search_SubTotalAmt,fieldName.length) == "SubTotalAmt") && (firstSubTotalFlag == 0))
    {
      firstSubTotalFlag = i;
    }
    if(fieldName == groupName + "_SubTotalAmt") { thisSubTotalFlag = i; }
    if(fieldName == groupName + "_TotalAmt") { totalFlag1 = i; }
    if(fieldName == "TotalAmt") { totalFlag2 = i; }
    if((fieldName.substring(0,groupNameLength) == groupName) && 
        (document.forms[FormIndex].elements[i].type == "text") &&
        (fieldName.substring(search_Number,fieldName.length) != "Number") &&
        (fieldName.substring(search_SubTotalAmt,fieldName.length) != "SubTotalAmt") &&
        (fieldName.substring(search_TotalAmt,fieldName.length) != "TotalAmt"))
    {
      subTotal += parseFloat(document.forms[FormIndex].elements[i].value);
    }
  }
// Set value for Total Field if no SubTotal Field
  if(thisSubTotalFlag == 0)
  {
    document.forms[FormIndex].elements[totalFlag1].value = moneyFormat(subTotal);
    return true;
  }
// Set value for SubTotal and Total Fields
  else
  {
    document.forms[FormIndex].elements[thisSubTotalFlag].value = subTotal;
    for(i = firstSubTotalFlag; i < totalFlag2; i++)
    {
      if(document.forms[FormIndex].elements[i].type == "text")
      {
        total += parseFloat(document.forms[FormIndex].elements[i].value);
      }
    }
    document.forms[FormIndex].elements[totalFlag2].value = moneyFormat(total);
    return true;
  }
}

// moneyFormat (inputNum)
function moneyFormat(inputNum)
{
  var moneyStr = "";
  if(inputNum > 0)
  {
    moneyStr = inputNum * 100 + moneyStr;
    moneyStr = moneyStr.substring(0,(moneyStr.length - 2)) + "." + moneyStr.substring((moneyStr.length - 2),moneyStr.length)
  }
  else { moneyStr = "0.00"; }
  return (moneyStr);
}

/////////////////////   OTHER INDEPENDENT FUNCTIONS   /////////////////////

//*************************************************************************\\
// Popup Window 
var popUpWindow = null;
var popUpURL = "";
var specs = "";
function PopUpWindow(url,w,h,sendData)
{
  popUpURL = "/cgi-sys/cgiwrap/" + SmallName + "/membership/" + url + ".cgi";
  if(PopUpWindow.arguments.length > 3) { popUpURL += sendData; }
  xpos = (screen.availWidth - w) / 2;
  ypos = (screen.availHeight - h) / 2;
// screenX and screenY position the window in Netscape
// left and top position the window in Internet Explorer
  specs = "scrollbars=yes,height=" + h + ",width=" + w + ",screenX=" + xpos + ",left=" + xpos + ",screenY=" + ypos + ",top=" + ypos;
  popUpWindow = window.open(popUpURL,"PopUpWindow",specs);
  if(popUpWindow != null) { popUpWindow.document.close(); }   // close layout stream
}

//*************************************************************************\\
// Auto Tab
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e)
{
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode))
  {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }

  function containsElement(arr, ele)
  {
    var found = false, index = 0;
    while(!found && index < arr.length)
    {
      if(arr[index] == ele) { found = true; }
      else { index++; }
    }
    return found;
  }

  function getIndex(input)
  {
    var index = -1, i = 0, found = false;
    while(i < input.form.length && index == -1)
    {
      if(input.form[i] == input) { index = i; }
      else { i++; }
    }
    return index;
  }
  return true;
}

//*************************************************************************\\
// Vote - Check WriteIn Radio Button
// Used with writein TEXT boxes to ensure radio button is checked
function checkWriteInButton(theField,radio)
{
  var thisFieldName = theField.name;
  var ballot_ID = thisFieldName.split("_")[1];
  var RB_ballot_ID = 0;
  var flag = 0;
  for(var i = 0; i < radio.length; i++)
  {
    if(radio[i].checked )
    {
      flag = 1;
      RB_ballot_ID = radio[i].value;
    }
  }
  if((flag == 1) && (RB_ballot_ID == ballot_ID)) { return true; }
  else
  {
    alert("ATTENTION: In addition to entering a name, you MUST\nclick the Write-In button to submit a Write-In candidate.");
    return false;
  }
}

//*************************************************************************\\
// Vote - Check WriteIn Checkbox
// Used with writein TEXT boxes to ensure checkbox is checked
function checkWriteInBox(theField,checkbox)
{
  var thisFieldName = theField.name;
  var ballot_ID = thisFieldName.split("_")[1];
  var CB_ballot_ID = 0;
  var flag = 0;
  if(checkbox.checked)
  {
    flag = 1;
    CB_ballot_ID = checkbox.value;
  }
  if((flag == 1) && (CB_ballot_ID == ballot_ID)) { return true; }
  else
  {
    alert("ATTENTION: In addition to entering a name, you MUST\ncheck the Write-In box to submit a Write-In candidate.");
    return false;
  }
}
