

/*

* Compatibilty for IE

    - at the end of this library are prototypes which add
      IE compatibility for these Array methods: join, push, slice, 
      splice and pop

* Select Box functions

   -select options in the box if their 
    value equals any string in the valuesArray
   selectValues (boxName,valuesArray, formName)
   
   -select options in the box if their 
    Text equals any string in the textsArray
   selectByText (boxName,textsArray, formName)
   
   -
   selectValueOf (boxName, value, formName)
   
   unSelectValueOf (boxName, value, formName)
   
   -moves any value that happens to be selected 
    to the top of the option box
   moveSelectedValuesToTop (boxName, formName)
   
   -adds one option to the select box and then sorts
    it.
   addSelectBoxItem (boxName, value, text, formName)
   
   - removes all the selected options from one
     box and adds them to the other select box
   copySelectedItems (sourceBox, targetBox, formName)
   
   -deletes all selected items from the designated box
   deleteSelectedItems (boxName, formName)
   
   -move all selected items from the source box
    to the destination box
   moveSelectedItems (sourceBoxName, destinationboxName, formName)
   
   -clears all options from a select box, leaving
    it length set to the designated value
   clearSelectBox (boxName, length, formName)  

   -returns the first selected option value
   string = getSelectedValue (boxName, formName)
   
   -returns the first selected option text
   string = getSelectedText (boxName, formName)
   
   -returns an array of all the selected values
   stringArray = getSelectedValues (boxName, formName)
   
   -
   stringArray = getSelectedTexts (boxName, formName)

   -used in conjunction with a preset hash of arrays
    to automatically cascade related options when an 
    option in the source box is cascaded 
    (see Dan Teeter for example code)
    cascadeOptions (sourceBox, targetBox, formName)

   -find the last used index of an option box
   integer = findOptionQty (boxName, formName)
   
   -find the last unused index of an option box
   integer = findNextUnusedOptionIndex (boxName, formName)
   
   -Sorts an option box alphabetically                      
   sortOptionBox(boxName, formName)
   
   -move an option up one slot
    returns false if no option is selected,
    the option value is '' or if
    the upper most option is selected
   moveOptionUp (boxName, formName)
  
   -move an option down one slot
    returns false if no option is selected,
    the option value is '' or if
    the lower most option is selected
   moveOptionDown (boxName, formName)
   
   -returns an array of all values in the
    select box that are not equal to ''
    (regardless of selected options)
   getAllOptionValues(boxName, formName)

* Checkbox functions
   - selects multiple checkboxes with the same name
     if their values match anything in the valuesArray  
   setCheckBoxValues (checkBoxName, valuesArray, formName)

   - sets checked status for multiple checkboxes with the same name
     if their values match anything in the valuesArray
     checked is boolean, true for checked falsed for un-checked
   modifyCheckBoxStates (checkBoxName, valuesArray, checked, formName)
   
    - returns an array containing all the selected
      checkboxes with the specified name  
   getCheckedValues (checkBoxName, formName)

   - returns an bollean if a given value is checked
     for a given checkbox
   isChecked(checkBoxName, value, formName)
   
* Text Field Functions   
   setTextFields (textFieldName, valuesArray, formName)
   
* String functions   
   var justifiedString = justifyString (oldString, desiredLength)

*Form Scanning Functions
    - replace left and right single/double quotes with web friendly versions 
      for all text/texarea fields in a form
    replaceBadChars(formName);
  
*Form validation
  fieldObject['fieldName'] = allowedLength;
  validateForm(fieldObject, formName);  
      
*/




//returns an array of all values in the
//select box that are not equal to ''
//(regardless of selected options)
function getAllOptionValues (boxName, formName) {
  if (formName == null) {
    formName = 0;
  }
  var allValues = new Array();
  for (var x=0; x<document.forms[formName].elements[boxName].options.length; x++) {
    var value = document.forms[formName].elements[boxName].options[x].value;
    if (value != '' && value != null) {
      allValues.push(value);
    }
  }
  return allValues;
}

//move an option up one slot
//returns false if no option is selected,
//the option value is '' or if
//the upper most option is selected
function moveOptionUp (boxName, formName) {
  if (formName == null) {
    formName = 0;
  }
  return moveOption(boxName, 1, formName);
}

//move an option down one slot
//returns false if no option is selected,
//the option value is '' or if
//the lower most option is selected
function moveOptionDown (boxName, formName) {
  if (formName == null) {
    formName = 0;
  }
  return moveOption(boxName, -1, formName);
}

//move an option up or down
//for up direction = 1
//for down direction = -1
function moveOption (boxName, direction, formName) {
  if (formName == null) {
    formName = 0;
  }
  var selectedIndex = document.forms[formName].elements[boxName].selectedIndex;
  var boxLength = document.forms[formName].elements[boxName].options.length;
  

  //error checking for up direction
  if (direction == 1) {
    if (selectedIndex == -1 || selectedIndex == 0) {
      return false;
    }
  }
  //error checking for down direction
  else if (direction == -1) {
    var boxLength = document.forms[formName].elements[boxName].options.length;
    if (selectedIndex == -1 || selectedIndex == boxLength-1) {
      return false;
    }
  } else {
    alert("moveOption must be called with the select box name\nand the direction (1 for up -1 for down)\nexample: moveOption('selectBoxName', 1) for up");
  }
  
  var value = getSelectedValue(boxName, formName);
  var text = getSelectedText(boxName, formName);  
  if (value == '') {
    return false;
  }

  var swappedValue = document.forms[formName].elements[boxName].options[selectedIndex - direction].value;
  var swappedText = document.forms[formName].elements[boxName].options[selectedIndex - direction].text;
  document.forms[formName].elements[boxName].options[selectedIndex - direction].value = value;
  document.forms[formName].elements[boxName].options[selectedIndex - direction].text = text;
  
  document.forms[formName].elements[boxName].options[selectedIndex].value = swappedValue;
  document.forms[formName].elements[boxName].options[selectedIndex].text = swappedText;

  document.forms[formName].elements[boxName].selectedIndex = document.forms[formName].elements[boxName].selectedIndex - direction;
  return true;    
}

//////////////////////////////////
//Select Fields in a select box based on an array of values
//////////////////////////////////
function selectValues(boxName, valuesArray, formName) {
   modifySelectValues(boxName, valuesArray, true, formName)
}

//////////////////////////////////
//unSelect Fields in a select box based on an array of values
//////////////////////////////////
function unSelectValues(boxName, valuesArray, formName) {
  modifySelectValues(boxName, valuesArray, false, formName)
}

//////////////////////////////////
//Select or un-Select Fields in a select box based on an array of values
//////////////////////////////////
function modifySelectValues(boxName, valuesArray, selectedState, formName) {
  if (formName == null) {
    formName = 0;
  }
  var modifiedValues = 0;
  for (var x=0; x<document.forms[formName].elements[boxName].length; x++) {
    for (var y=0; y<valuesArray.length; y++) {
      if (document.forms[formName].elements[boxName].options[x].value == valuesArray[y]) {
        document.forms[formName].elements[boxName].options[x].selected=selectedState;
        modifiedValues++;
        break;
      }
    }
    if (modifiedValues == valuesArray.length) {break;}
  }
}

//////////////////////////////////#
//Select Fields in a select box based on an array of text
//////////////////////////////////
function selectByText(boxName,valuesArray, formName) {
  if (formName == null) {
    formName = 0;
  }
  for (var x=0; x<document.forms[formName].elements[boxName].length; x++) {
    for (var y=0; y<valuesArray.length; y++) {
      if (document.forms[formName].elements[boxName].options[x].text == valuesArray[y]) {
        document.forms[formName].elements[boxName].options[x].selected=true;
      }
    }
  }
}


function deleteSelectedItems(boxName, formName) {
  if (formName == null) {
    formName = 0;
  }

  for (var x=0; x<document.forms[formName].elements[boxName].length; x++) {
    if (document.forms[formName].elements[boxName].options[x].selected) {
      document.forms[formName].elements[boxName].options[x] = null;
      x--;
    }
  }
}

function selectValueOf (boxName, value, formName) {
  if (formName == null) {
    formName = 0;
  }

  for (var x=0; x<document.forms[formName].elements[boxName].length; x++) {
    if (document.forms[formName].elements[boxName].options[x].value == value) {
      document.forms[formName].elements[boxName].options[x].selected = true;
      break;
    }
  }

}


function addSelectBoxItem (boxName, value, text, formName) {
  if (formName == null) {
    formName = 0;
  }
  var nextOption = findOptionQty(boxName, formName) + 1;
  if (document.forms[formName].elements[boxName].length-1 < nextOption) {
    document.forms[formName].elements[boxName].length++;
  }
  document.forms[formName].elements[boxName].options[nextOption].value = value;
  document.forms[formName].elements[boxName].options[nextOption].text = text;
  sortOptionBox(boxName, formName);
}

function getSelectedValue (boxName, formName) {
  if (formName == null) {
    formName = 0;
  }
  return document.forms[formName].elements[boxName].options[document.forms[formName].elements[boxName].selectedIndex].value;
}

function getSelectedText (boxName, formName) {
  if (formName == null) {
    formName = 0;
  }
  return document.forms[formName].elements[boxName].options[document.forms[formName].elements[boxName].selectedIndex].text;
}


function getSelectedValues (boxName, formName) {
  if (formName == null) {
    formName = 0;
  }
  var options = new Array();
  var options = document.forms[formName].elements[boxName].options;
  var values = new Array();
  for (var x=0; x<options.length; x++) {
    if (options[x].selected) {
      values.push(options[x].value);
    }
  }
  return values;
}


function getSelectedTexts (boxName, formName) {
  if (formName == null) {
    formName = 0;
  }
  var options = new Array();
  var options = document.forms[formName].elements[boxName].options;
  var texts = new Array();
  for (var x=0; x<options.length; x++) {
    if (options[x].selected) {
      texts.push(options[x].text);
    }
  }
  return texts;
}

////////////////////////////////////////////   
//Move Information from one select box to another
//
////////////////////////////////////////////
function moveSelectedItems (sourceBox, targetBox, formName) {
  if (formName == null) {
    formName = 0;
  }
  copySelectedItems (sourceBox, targetBox, formName);
  deleteSelectedItems(sourceBox, formName);
}

////////////////////////////////////////////   
//Copy Information from one select box to another
//
////////////////////////////////////////////
function copySelectedItems (sourceBox, targetBox, formName) {
  if (formName == null) {
    formName = 0;
  }
  var sourceValues = getSelectedValues(sourceBox, formName);
  var sourceTexts = getSelectedTexts(sourceBox, formName);

  var nextOption = findOptionQty(targetBox, formName) + 1;

  document.forms[formName].elements[targetBox].options.length = nextOption+sourceValues.length+1;
  for (x=0; x<sourceValues.length; x++) {
    //if (document.forms[formName].elements[targetBox].options[nextOption+x] == null) {
      //document.forms[formName].elements[targetBox].length++;
    //}
    document.forms[formName].elements[targetBox].options[nextOption+x].value = sourceValues[x];
    document.forms[formName].elements[targetBox].options[nextOption+x].text = sourceTexts[x];
  }
 
  sortOptionBox(targetBox, formName);
}


////////////////////////////////////////////   
//Cascade options from one select box to another
//given a object with a key that points to
//an array
//example: obj["key"] = new Array('text one|value1', 'text two|value2', 'text three|value3');
//if sourceBox has the value "key" selected,
//targetbox will have be filled with one, two, three
////////////////////////////////////////////
function cascadeOptions (sourceBox, targetBox, formName) {
  if (formName == null) {
    formName = 0;
  }
  if (formName == null) {
    formName = 0;
  }
  clearSelectBox(targetBox, 0, formName);

  var key = getSelectedValue(sourceBox, formName);

  var targetBoxArray = new Array();

  targetBoxArray = eval(sourceBox + '["' + key + '"]');

  if (targetBoxArray == null) {
    return false;
  }

  document.forms[formName].elements[targetBox].length = targetBoxArray.length;
  
  for (var x=0; x<targetBoxArray.length; x++) {
    var optionParts = targetBoxArray[x].split('|');
    if (optionParts[1] == null) {
      optionParts[1] = optionParts[0];
    }
    document.forms[formName].elements[targetBox].options[x] = new Option(optionParts[0], optionParts[1]);
  }
  
  
}

////////////////////////////////////////////   
//Return the index of the last option 
//in the select box that has a non-null value
////////////////////////////////////////////
function findOptionQty (boxName, formName) {
  if (formName == null) {
    formName = 0;
  }
  var optionQty = document.forms[formName].elements[boxName].options.length;
  
  //new version counts down from the end of the options
  //figure out how many items have been added already
  var i = optionQty
    for (i=optionQty-1; i>=0; i--) {
    if (document.forms[formName].elements[boxName].options[i].value == null || document.forms[formName].elements[boxName].options[i].value.length == 0) {
      continue;
     }//if
     else {break;}
  }//for
  
  return i;
}//findOptionQty

////////////////////////////////////////////   
//Return the index of that last used select option
////////////////////////////////////////////
function findNextUnusedOptionIndex (boxName, formName) {
  if (formName == null) {
    formName = 0;
  }
  var optionQty = document.forms[formName].elements[boxName].length;
  var i=0;
  //figure out how many items have been added already
  for (i=0; i<optionQty; i++) {
    if (document.forms[formName].elements[boxName].options[i].value.length == 0) {
      break;
    }//if
    else if (document.forms[formName].elements[boxName].options[i].value == null) {
      break;
    }//if 
    else if (document.forms[formName].elements[boxName].options[i].value == null) {
      break;
    }//if 
  }//for
  return i;
}//findNextUnusedOptionIndex


/////////////////////////////////////////////////
//transfer an item from one select box to another
/////////////////////////////////////////////////
function sortOptionBox(boxName, formName) {
  if (formName == null) {
    formName = 0;
  }

  var options = document.forms[formName].elements[boxName].options;
  var sortArray = new Array();
  var optionQty = findOptionQty(boxName, formName);

  for (var x=0; x<=optionQty; x++) {
    sortArray[x] = new String(options[x].text + "^^^" + options[x].value);
  }
  
  sortArray = sortArray.sort();
      
  for (var x=0; x<=optionQty; x++) {
    var splitArray = new Array();
    splitArray = sortArray[x].split("^^^");
    //(text, value)
    //alert ("options[oldX] for " + oldX + " " + options[oldX].text);
    document.forms[formName].elements[boxName].options[x].text = splitArray[0];
    document.forms[formName].elements[boxName].options[x].value = splitArray[1];
  }
  
}//sortOptionBox

//////////////////////////////////////////////////#
//Clear all the data in a select box
function clearSelectBox(boxName, length, formName) {
  if (formName == null) {
    formName = 0;
  }
  if (length == null) {
    length = 100;
  }
  document.forms[formName].elements[boxName].length=0;
  document.forms[formName].elements[boxName].length=length;
}

///////////////////////////////////////
//Set checkbox values for a given name
///////////////////////////////////////
function modifyCheckBoxStates (checkBoxName, valuesArray, checkedState, formName) {
  if (formName == null) {
    formName = 0;
  }
  var checkBox = document.forms[formName].elements[checkBoxName];

  //case for only one check box
  if (checkBox.length == null && checkBox != null) {
    for (var y=0; y<valuesArray.length; y++) {
      if (checkBox.value == valuesArray[y]) {
        checkBox.checked = checkedState;
      }
    }
  }
  //case for multiple check boxes   
  else {
    for (var x=0; x<checkBox.length; x++) {
      for (var y=0; y<valuesArray.length; y++) {
        if (checkBox[x].value == valuesArray[y]) {
          checkBox[x].checked = checkedState;
        }
      }
    }
  }
}


//////////////////////////////////////
//Set checkbox values for a given name
//////////////////////////////////////
function setCheckBoxValues(checkBoxName, valuesArray, formName) {
  modifyCheckBoxStates (checkBoxName, valuesArray, true, formName);
}

///////////////////////////////////////
//get checkbox values for a given name
//in the form of an array
///////////////////////////////////////
function getCheckedValues(checkBoxName, formName) {
  if (formName == null) {
    formName = 0;
  }
  var checkBox = document.forms[formName].elements[checkBoxName];
  var checkedValues = new Array();   

  for (var x=0; x<checkBox.length; x++) {
    if (checkBox[x].checked == true) {
      checkedValues.push(checkBox[x].value);  
    }

  }
  return checkedValues;
}
//////////////////////////////////////
//Find out if a given checkbox is has
//a given value and is checked
//////////////////////////////////////
function isChecked(checkBoxName, value, formName) {
  if (formName == null) {
    formName = 0;
  }
  var checkBox = document.forms[formName].elements[checkBoxName];

  //case for only one check box
  if (checkBox.length == null && checkBox.checked == true && checkBox.value == value) 
  {return true;}
  else {
    for (var x=0; x<checkBox.length; x++) {
      if (checkBox[x].checked == true && checkBox[x].value == value) {
        return true;
      }
    }
  }
  return false;
}

//////////////////////////////////
//Set text fields for a given name
//////////////////////////////////
function setTextFields(textFieldName, valuesArray, formName) {
  if (formName == null) {
    formName = 0;
  }
  var textField = document.forms[formName].elements[textFieldName];
  for (var x=0; x<textField.length; x++) {
    if (x<valuesArray.length) {
      textField[x].value = valuesArray[x];
    }
  }
}


////////////////////////
//justify string
///////////////////////
function justifyString (oldString, desiredLength, formName) {
  if (formName == null) {
    formName = 0;
  }
  var oldString = new String(oldString);
  var newString = oldString.substr(0,desiredLength);
  var space = new String(" ");
  newString = newString + space.repeat(desiredLength-newString.length);
  return newString;
}//justifyString


/////////////////////////////////////////
//Moves selected values in the select box to the top of the list
//////////////////////////////////////////
function moveSelectedValuesToTop (boxName, formName) {
  if (formName == null) {
    formName = 0;
  }
  //if no items are selected, do nothing
  if (document.forms[formName].elements[boxName].selectedIndex == -1) {
    return false;
  }

  var boxLength = document.forms[formName].elements[boxName].length;
  var values = getSelectedValues(boxName, formName);
  var texts = getSelectedTexts(boxName, formName);
  deleteSelectedItems(boxName, formName);
  


  //move all select box items up by the number of 
  //option that will be inserted at the top of the option box
  for (var x=boxLength-1; x>values.length-1; x--) {
    document.forms[formName].elements[boxName].options[x] = document.forms[formName].elements[boxName].options[x-values.length];
  }
  
  
  for (var x=0; x<values.length; x++) {
    var thisOption = new Option(texts[x], values[x], false, true);
    document.forms[formName].elements[boxName].options[x] = thisOption;
  }
}

/////////////////////////////////////////
//Returns true or false depending on whether
//a value is found in the select box
//////////////////////////////////////////
function valueExists (boxName, searchValue, formName) {
  if (formName == null) {
    formName = 0;
  }
  var boxLength = document.forms[formName].elements[boxName].length;
  for (var x=0; x<boxLength; x++) {
    if (document.forms[formName].elements[boxName].options[x].value == searchValue) {
      return true;
    }
  }
  return false;
}


//Adding join method if necessary
if (!Array.prototype.join) {
  function _Array_join (joinPattern) {
    var returnString = "";
    if (arguments.length == 0) {
      return returnString;
    }
    for (var a = 0; a < arguments.length-1; a++) {
      returnString = returnString + arguments[a] + joinPattern;
    }
    return(returnString + arguments[arguments.length-1]);  
  }
  Array.prototype.join = _Array_join;
}


//Adding push method if necessary
if (!Array.prototype.push) {
  function _Array_push () {
    for (var a = 0; a < arguments.length; a++) {
      this[this.length] = arguments[a];
    }
    return this.length;
  }
  Array.prototype.push = _Array_push;
}


//Adding slice method if necessary
if (!Array.prototype.slice) {
  function _Array_slice (start, end) {
    for (var a=0; a < end-start; a++) {
      this[a] = arguments[start + a];
    }
    return this;
  }
  Array.prototype.slice = _Array_slice;
}


//Adding pop method if necessary
if (!Array.prototype.pop) {
  function _Array_pop() {
    var lastElement = this[this.length - 1];
    this.length--;
    return lastElement;
  }
  Array.prototype.pop = _Array_pop;
}


//Adding splice method if necessary
if (!Array.prototype.splice) {
  function _Array_Splice(ind,cnt) {
    if (arguments.length == 0) return ind;
    if (typeof ind != "number") ind = 0;
    if (ind < 0) ind = Math.max(0,this.length + ind);
    if (ind > this.length) {
      if (arguments.length > 2) ind = this.length;
      else return [];
    }
    if (arguments.length < 2) cnt = this.length-ind;
    cnt = (typeof cnt == "number") ? Math.max(0,cnt) : 0;
    removeArray = this.slice(ind,ind+cnt);
    endArray = this.slice(ind+cnt);
    this.length = ind;
    for (var i = 2; i < arguments.length; i++) {
      this[this.length] = arguments[i];
    }
    for (var i = 0; i < endArray.length; i++) {
      this[this.length] = endArray[i];
    }
    return removeArray;
  }
  Array.prototype.splice = _Array_Splice;
}

function popupHelp (content, width, height) {
  helpWindow=window.open('','hWindow','WIDTH=' + width + ',HEIGHT=' + height);
  helpWindow.document.write("<html>\n<head><title>Pop-up Help<\/title><\/head>\n<body bgcolor=white>\n");
  helpWindow.document.write("\n<p>\n" + content + "\n<p>\n");
  helpWindow.document.write("\n</body>\n</html>");
  helpWindow.focus();
}

//replace left and right quotes for all text/texarea fields in a form
function replaceBadChars(formNumber) {

  var findFields = new RegExp("select|text", "i");
  
  var charConv = new Object();
  //offending unicode characters from $MS apps
  //example: ?this? and ?that?
  charConv[8216] = "'"; 
  charConv[8217] = "'";
  charConv[8220] = '"';
  charConv[8221] = '"'; 
  charConv[8482] = '?';//tm
  charConv[8212] = '&#151;';//ascii 151 emdash
  charConv[8211] = '&#150;';//ascii 150 dash

  for (var x=0; x<document.forms[formNumber].elements.length; x++) {

    var elementType = document.forms[formNumber].elements[x].type;

    if (elementType.match(findFields)) {
      
      if (document.forms[formNumber].elements[x] == null || document.forms[formNumber].elements[x].value == null) {
        continue;
      }

      var workingString = document.forms[formNumber].elements[x].value;
      var workingArray = new Array();
      
      for (var y=0; y<workingString.length; y++) {
        var charCode = workingString.charCodeAt(y);
        
        if (charCode > 255 && charConv[charCode] == null) {
          alert('Sorry, a character that looks like this: "' + workingString.substr(y,1) + '" appears on your form.\nThis character will be blanked out.\nTo prevent this problem in the future, notify Dan of this message\nand tell him that the character code is ' + charCode);
          workingArray[y] = ' ';
        }

        else if (charConv[charCode] != null) {
          workingArray[y] = charConv[charCode];
        } else {
          workingArray[y] = workingString.charAt(y);
        }
      }
      document.forms[formNumber].elements[x].value = workingArray.join('');
    }//if
  }//for
}//replaceBadChars

function validateForm(fieldsObject, formName) {
  if (formName == null) {
    formName = 0;
  }
  var errors = new Array();
  var errorObject = new Object();
  
  var findSelect = /select/i;
  var findPreferredName = /PreferredName/;
  
  for (field in fieldsObject) {
    
    //ignore preferred names
    field = new String(field);
    if (field.match(findPreferredName) != null) {continue;}
    
    var value = '';
    if (document.forms[formName].elements[field].type.match(findSelect) != null) {
      value = getSelectedValue(field, formName);
    } else {
      value = document.forms[formName].elements[field].value;
    }
    var fieldName = field;
    //The fields Object can hold preferred names for a field
    //if a preferred name exists, use it
    if (fieldsObject[fieldName + 'PreferredName'] != null) {
      fieldName = fieldsObject[fieldName + 'PreferredName'];
    }
    fieldName = fieldName.replace('_', ' ');
    
    //alert('fieldName:' + fieldName + ' value:(' + value + ')');

    if (value == null || value == '') {
      //alert('found error with ' + fieldName);
      errorObject[fieldName] = null;
      errorObject['hasErrors'] = true;
    }//if
    else if (value.length > fieldsObject[field]) {
      errorObject[fieldName] = fieldsObject[field] + "|" + value.length;
      errorObject['hasErrors'] = true;
    }
  }//for  
  return errorObject;
}

function generateErrorAlert (errorObject) {

  var errorMessage = '';
  for (field in errorObject) {
    if (field == 'hasErrors') {continue;}
    if (errorObject[field] == null) {
      errorMessage = errorMessage + "required field not filled: " + field + "\n";
    } else {
      //alert('field:' + field + ' value:' + errorObject[field] + "\nobj:" + errorObject);
      var fieldSizes = errorObject[field].split("|");
      errorMessage = errorMessage + field + " is too long, you entered " +  fieldSizes[1] + " characters, but only " + fieldSizes[0] + " characters are allowed.\n";
    }
    
  } 
  alert("Sorry, there is a problem with the information entered in the form.\n" + errorMessage);
}

