/*****************************************************************************\
 *                                                                           *
 * Store any errors in js array where index is the id of the form field.     *
 * This will allow us to make DHTML changes to form fields when the errors   *
 * have been attempted to be corrected before form submission.               *
 *                                                                           *
 * 0 = current color                                                         *
 * 1 = new color                                                             *
 * 2 = error message                                                         *
 *                                                                           *
\*****************************************************************************/
$form_errors = new Array();
$global_total_form_validation_errors = 0;

function add_error_data($element_id, $new_color, $error_message)
{
  $form_errors[$element_id] =  new Array();
  $form_errors[$element_id][0] = (document.getElementById($element_id).style.color != '' ? document.getElementById($element_id).style.color : '#000');
  $form_errors[$element_id][1] = $new_color;
  $form_errors[$element_id][2] = $error_message;

  $global_total_form_validation_errors += 1;
}

/*****************************************************************************\
 *                                                                           *
 * Check to see if the current color of the form field description is not the*
 * same as the original color, change it back.                               *
 *                                                                           *
 * Array index key:                                                          *
 *                                                                           *
 * 0 = current color                                                         *
 * 1 = new color                                                             *
 * 2 = error message                                                         *
 *                                                                           *
\*****************************************************************************/

function undo_style_color_change($field_id)
{
// If the $field_id index exists in the $form_errors array and the current
// color is not equal to the original color, change it.
  $field_id_obj = document.getElementById($field_id);

  if ($form_errors[$field_id][0] != null && $form_errors[$field_id][0] != 'undefined' && $form_errors[$field_id][0] != '')
    if ($field_id_obj.style.color != $form_errors[$field_id][0])
      {
// Set color of form field title back to original color.
        $field_id_obj.style.color = $form_errors[$field_id][0];
// Hide the error message for this form field.
//        document.getElementById($field_id+'_error_msg').style.display = 'none';
//        document.getElementById($field_id+'_error_msg').style.list-style-image = 'url("/images/form_error_check.gif")';
        document.getElementById($field_id+'_error_msg').style.listStyleImage = 'url("/images/form_error_check.gif")';

        $global_total_form_validation_errors -= 1;

/*
        if ($global_total_form_validation_errors == 0)
// Hide the error message div for all form errors, since all have been resolved.
          document.getElementById('display_form_errors_wrapper').style.display = 'none';
*/          
      }
}