

    var a = Math.ceil(Math.random() * 10);
    var b = Math.ceil(Math.random() * 10);       
    var c = a + b;

    function DrawBotBoot()
    {
        document.write("What is "+ a + " + " + b +"? ");
        document.write("<input id='BotBootInput' type='text' maxlength='2' size='2'/>");
    }    
    function ValidBotBoot(){
        var d = document.getElementById('BotBootInput').value;
        if (d == c) return true;        
        return false;
        
    }

var error = "";
var valid = true;
var errorCount = 0;

var imageNames = ""; // list of images that have become 'arrows'

var digitsInZIPCode = 5;
var digitsInAcctNum = 8;
var maxErrors = 5;

var mPrefix = "Please enter a value into the ";
var mSuffix = " field.";

var iZIPCode = "ZIP CODE must be a 5 digit U.S. ZIP Code (like 07451).";

var iAcctNum = "An Account number needs to have 8 digits with no dashes - (like 12345678).";
var iEmail = "E-MAIL must be a valid e-mail address (like info@ridgewoodsymphony.org).";
var iDatePrefix = "The Day, Month, and Year for ";
var iDateSuffix = " do not form a valid date.";


function checkString (theField, theFieldName)
{
  if (isWhitespace(theField.value))
  {
    addError(mPrefix + theFieldName + mSuffix,theField.name + 'Img');
  }
}

// ZIP Code must be numeric and have a length equal to five

function checkZIPCode (theField, theFieldName)
{
s = theField;  // original function used 's'
  var zc = stripWhitespace(s.value);
  if (checkZIPCode.arguments.length == 1)
  {
    if (!(isInteger(zc)) || !(zc.length == digitsInZIPCode))
    {
      addError(iZIPCode, theField.name + 'Img');
    }
  }
  else
  {
    if (!(isInteger(zc, checkZIPCode.arguments[1])) || (!(zc.length == digitsInZIPCode) && !(zc.length == "0")))
    {
      addError(iZIPCode, theField.name + 'Img');
    }
  }
}

// Account Number must be numeric and have a length equal to eight 

function checkAcctNum (theField, theFieldName)
{
s = theField;  // original function used 's'
  var zc = stripWhitespace(s.value);
  if (checkAcctNum.arguments.length == 1)
  {
    if (!(isInteger(zc)) || !(zc.length == digitsInAcctNum))
    {
      addError(iAcctNum, theField.name + 'Img');
    }
  }
  else
  {
    if (!(isInteger(zc, checkAcctNum.arguments[1])) || (!(zc.length == digitsInAcctNum) && !(zc.length == "0")))
    {
      addError(iAcctNum, theField.name + 'Img');
    }
  }
}

// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required

function checkEmail (theField, theFieldName)
{ 
  if (checkEmail.arguments.length == 2) { required = true; } else {required = false; }

  s = theField.value;

  if (isEmpty(s))
  {
    if (required)
    {
      addError(mPrefix + theFieldName + mSuffix, theField.name + 'Img');
      return;
    }
    else
    {
      // The field is not required, empty is OK, just return
      return;
    }
  }
   
  // is s whitespace?
  if (isWhitespace(s))
  {
    if (required)
    {
      addError(mPrefix + theFieldName + mSuffix, theField.name + 'Img');
      return;
    }
    else
    {
      // The field is not required, whitespace is OK, just return
      return;
    }
  }
  
  // Make sure s doesn't equal the value we put as default
  if (s == "username@domain.com")
  {
    addError("E-MAIL address is not valid. 'username@domain.com' is only an example format.", theField.name + 'Img');
    return;
  }
    
  // 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) != "@"))
  {
    addError(iEmail, theField.name + 'Img');
    return;
  }
  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) != "."))
  {
    addError(iEmail, theField.name + 'Img');
    return;
  }
}

// The phone number must be numeric and have length () 3-4.

function checkPhoneNumber (areaCode, phoneNumberThree, phoneNumberFour, extension, type, theField)
{
  if (isEmpty(areaCode.value) || areaCode.value.length != 3 || !(isInteger(areaCode.value)) || isEmpty(phoneNumberThree.value) || phoneNumberThree.value.length != 3 || !(isInteger(phoneNumberThree.value)) || isEmpty(phoneNumberFour.value) || phoneNumberFour.value.length != 4 || !(isInteger(phoneNumberFour.value)) || (!(isEmpty(extension.value)) && !(isInteger(extension.value))))
  {
    addError(type + " must be numeric and of the format 555-123-4567 [optional] ext.5555", theField.name + 'Img');
  }
}

// SSN must be numeric and have length 3-2-4

function checkSSN (ssnThree, ssnTwo, ssnFour, theField)
{
  if (!(isInteger(ssnThree.value)) || !(isInteger(ssnTwo.value)) || !(isInteger(ssnFour.value)) || !(ssnThree.value.length == 3) || !(ssnTwo.value.length == 2) || !(ssnFour.value.length == 4))
  {
    addError("SSN must be 9 digits, 0-9, and in the format 123-12-1234.", theField.name + 'Img');
  }
}


// Check that yearField.value, monthField.value, and dayField.value 
// form a valid date.
//
// If they don't, labelString (the name of the date, like "Birth Date")
// is displayed to tell the user which date field is invalid.
//

function checkDate (monthField, dayField, yearField, labelString, theField)
{
  if (!isMonth(monthField.value))
  {
    addError(iMonthPrefix + labelString + iMonthSuffix, theField.name + 'Img');
  }
  if (!isDay(dayField.value))
  { 
    addError(iDayPrefix + labelString + iDaySuffix, theField.name + 'Img');
  }
  if (!isYear(yearField.value)) 
  {
    addError(iYearPrefix + labelString + iYearSuffix, theField.name + 'Img');
  }
  if (!isDate (monthField.value, dayField.value, yearField.value))
  {
    addError(iDatePrefix + labelString + iDateSuffix, theField.name + ' Img');
  }
}

// Log an error if there are any spaces in the field value

function checkSpaces(theField, theFieldName)
{
  for(var i = 0; i < theField.value.length; i++)
  {
    if(theField.value.charAt(i) == " ")
    {
      addError(theFieldName + "cannot have spaces.  Please re-enter.", theField.name + 'Img');
      break;
    }
  }
  return;
}

// Strip any spaces from the beginning and end of all text values on the form passed

function stripTextValues(form)
{
  for (var i = 0; i < form.elements.length; i++)
  {
    if (form.elements[i].type == "text")
    {
      stripBegEndSpaces(form.elements[i]);
    }
  }
}

function addError(errorMessage, imgName)
{
  if (!imgName == '') { imageNames+=imgName + ":"; }
  
  if (errorCount < maxErrors)
  {
    error+= errorMessage + "\n";
    valid = false;
    errorCount++;
  }
  else if (errorCount == maxErrors)
  {
    error+= "...more.\n";
    valid = false;
    errorCount++;
  }
  else
  {
    // Do nothing, errorCount is greater than maxErrors to display
  }
}

// Log an error if the date passed is greater than today

function checkDateGreaterThanToday(month, day, year, theFieldName, theField)
{
  today = new Date();

  compareToDate = new Date();

  compareToDate.setDate(day.value);
  compareToDate.setMonth(month.value - 1);
  compareToDate.setYear(year.value);

  if (today.getTime() < compareToDate.getTime())
  {
    addError(theFieldName + " cannot be greater than today.", theField.name + 'Img');
  }
}

/*
  *  Title
  *
  *     common.js
  *
  *  Description
  *
  *     This file provides generic JavaScript functions to be used
  *     in any validation script.
  *
  *  Notes
  *
  *     None
  *
  *  --------------------------------------------------------------
  *
  *  Copyright (c) 1999 AGENCY.COM All Rights Reserved.
  *  This software is the confidential and proprietary information
  *  of AGENCY.COM. ("Confidential Information").  You shall not
  *  disclose such Confidential Information and shall use it only
  *  in accordance with the terms of the license agreement you
  *  entered into with AGENCY.COM
  *
  *  AGENCY.COM MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE 
  *  SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED,
  *  INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-
  *  INFRINGEMENT.  AGENCY.COM SHALL NOT BE LIABLE FOR ANY DAMAGES
  *  SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  *  DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  *  --------------------------------------------------------------
  */
var required = false;
var notRequired = true;

// whitespace characters
var whitespace = " \t\n\r";
var decimalPointDelimiter = ".";

var daysInMonth = new Array(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;


var iDayPrefix = "The second field in ";
var iDaySuffix = " must be a day number between 1 and 31.";
var iMonthPrefix = "The first field in ";
var iMonthSuffix = " must be a month number between 1 and 12.";
var iYearPrefix = "The third field in ";
var iYearSuffix = " must be a 4 digit year number.";


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

function isInteger (s)
{   
  var i;

  if (isEmpty(s))
  {
    if (isInteger.arguments.length == 1)
    {
      return required;
    }
    else
    {
      return notRequired;
    }
  }

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

// isFloat (STRING s [, BOOLEAN emptyOK])
// 
// True if string s is an unsigned floating point (real) number. 
//
// Also returns true for unsigned integers. If you wish
// to distinguish between integers and floating point numbers,
// first call isInteger, then call isFloat.
//
// Does not accept exponential notation.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isFloat (s)
{   
  var i;
  var seenDecimalPoint = false;

  if (isEmpty(s))
  { 
    if (isFloat.arguments.length == 1)
    {
      return required;
    }
    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;
}

// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{
  return ((c >= "0") && (c <= "9"));
}

// Removes all whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.

function stripWhitespace (s)
{   
  return stripCharsInBag (s, whitespace);
}

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

// isYear (STRING s)
// 
// isYear returns true if string s is a valid 
// Year number.  Must be 4 digits only.
//
//

function isYear (s)
{   
  if (isEmpty(s))
  {
    return false;
  } 
  
  if (!isInteger(s))
  {
    return false;
  }
  return (s.length == 4);
}

// isIntegerInRange (STRING s, INTEGER a, INTEGER b)
// 
// isIntegerInRange returns true if string s is an integer 
// within the range of integer arguments a and b, inclusive.
//

function isIntegerInRange (s, a, b)
{   
  if (isEmpty(s))
  {
    return false;
  }

  // Catch non-integer strings to avoid creating a NaN below,
  // which isn't available on JavaScript 1.0 for Windows.
  if (!isInteger(s))
  {
    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).
  // Commented out next five lines and replaced by fixing parseInt call
  //var c = s.charAt(0);
  //if (c == "0")
  //{
  //  s = s.substring(1);
  //}
  var num = parseInt (s, 10);
  return ((num >= a) && (num <= b));
}

// isMonth (STRING s)
// 
// isMonth returns true if string s is a valid 
// month number between 1 and 12.
//

function isMonth (s)
{  
  if (isEmpty(s))
  {
    return false;
  }
  else
  {
    return isIntegerInRange (s, 1, 12);
  }
}

// isDay (STRING s)
// 
// isDay returns true if string s is a valid 
// day number between 1 and 31.
// 

function isDay (s)
{   
  if (isEmpty(s))
  {
    return false;
  }
  else 
  {   
    return isIntegerInRange (s, 1, 31);
  }
}

// daysInFebruary (INTEGER year)
// 
// Given integer argument year,
// returns number of days in February of that year.

function daysInFebruary (year)
{   
  // February has 29 days in any year evenly divisible by four,
  // EXCEPT for centurial years which are not also divisible by 400.
  return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

// isDate (STRING year, STRING month, STRING day)
//
// isDate returns true if string arguments year, month, and day 
// form a valid date.
// 

function isDate (month, day, year)
{   
  // catch invalid years (not 4-digit) and invalid months and days.
  if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false)))
  {
    return false;
  }

  // Explicitly change type to integer to make code work in both
  // JavaScript 1.1 and JavaScript 1.2.
  var intYear = parseInt(year, 10);
  var intMonth = parseInt(month, 10);
  var intDay = parseInt(day, 10);

  // catch invalid days, except for February
  if (intDay > daysInMonth[intMonth])
  {
    return false; 
  }

  if ((intMonth == 2) && (intDay > daysInFebruary(intYear)))
  {
    return false;
  }

  return true;
}

function selectField (theField)
{
  theField.select();
}

// checkRadioButtonChecked
// 
// Checks if a set of radio buttons has a button checked.

function checkRadioButtonChecked (radio)
{
  for (var i=0; i < radio.length; i++)
  {
    if (radio[i].checked == true)
    {
      return true;
    }
  }
  return false;
}

function getRadioButtonValue (radio)
{
  var found = false;

  for (var i=0; i < radio.length; i++)
  {
    if (radio[i].checked == true)
    {
      found = true;
      break;
    }
  }

  if (found)
  {
    return radio[i].value;
  }
  else
  {
    return "";
  }
}

function isRadioButtonOption (radio, value)
{
  for (var i=0; i < radio.length; i++)
  {
    if (radio[i].value == value)
    {
      return true;
    }
  }
  return false;
}

function setRadioButtonChecked (radio, value)
{
  for (var i=0; i < radio.length; i++)
  {
    if (radio[i].value == value)
    {
      radio[i].checked = true;
      return true;
    }
  }
  return false;
}

function clearRadioButton (radio)
{
  for (var i=0; i < radio.length; i++)
  {
    radio[i].checked = false;
  }
  return;
}

function setRadioButtonState (radio, value, enabled)
{
  for (var i=0; i < radio.length; i++)
  {
    if (radio[i].value == value)
    {
      radio[i].disabled = !enabled;
      return true;
    }
  }
  return false;
}

function getSelectValue (select)
{
  return select.options[select.selectedIndex].value;
}

function stripBegEndSpaces(field)
{
  var pos = 0;
  var interString = "";
  var finalString = "";

  while (pos < field.value.length && field.value.charAt(pos) == " ")
  {
      pos++;
  }
  while (pos < field.value.length)
  {
    interString += field.value.charAt(pos);
    pos++;
  }

  var cnt = interString.length - 1;

  while (cnt > 0 && interString.charAt(cnt) == " ")
  {
    cnt--;
  }

  var index = 0;

  while (index <= cnt)
  {
    finalString += interString.charAt(index);
    index++;
  }
  field.value = finalString;
}

function focusField(field,radio,values)
{
  var value=getRadioButtonValue (radio);
  var a = values.split (';');
  for (i = 0; i < a.length; i++)
  {
    if (a[i] == value)
    {
      return false;
    }
  }

  field.blur ();
  return true;
}


// Log an error if there are any = or | chars in the field

function checkBadCharsField(field, fieldName)
{
  for(var i = 0; i < field.value.length; i++)
  {
    if(field.value.charAt(i) == "=")
    {
      addError(fieldName + " cannot have a '=' character.",fieldName + 'Img');
      break;
    }
    if(field.value.charAt(i) == "|")
    {
      addError(fieldName + " cannot have a '|' character.",fieldName + 'Img');
      break;
    }
  }
  return;
}

// Check for = and | characters in all text values on the form passed

function checkBadCharsForm(form)
{
  for (var i = 0; i < form.elements.length; i++)
  {
    if (form.elements[i].type == "text")
    {
      checkBadCharsField(form.elements[i], form.elements[i].name);
    }
  }
}

// control the display and hiding of arrows for required fields

function toggleArrows(state) {
  if (state == 'off') {
  	if (!imageNames=='') {
      arrayOfImages = imageNames.split(':')
      for (var i=0; i < arrayOfImages.length; i++) {
	    if (document[arrayOfImages[i]]) 
          document[arrayOfImages[i]].src= "/images/clearpix.gif"
      }
    }
    imageNames = '';
  } else {
    if (!imageNames=='') {
      arrayOfImages = imageNames.split(':')
      for (var i=0; i < arrayOfImages.length; i++) {
        if (document[arrayOfImages[i]]) 
          document[arrayOfImages[i]].src= "/images/arrow.gif";
      }
    }
  }
}

