<!--
/**
 * PURPOSE: Functions and variables specific to the Javascript Evaluation Form application
 * AUTHOR: david@dreamofblue.com
 */

// Global containing names of requirement RADIO buttons.
var radios = new Array( "usability", "accessibility", "reliability", "appearance" );

/**
 * PARAMETERS:
 * ref_form - a reference to the form containing the radio buttons named in RADIOS array
 * RETURNS:
 * int - containing sum of values of all items named in RADIOS
 * EXTERNAL UDF:
 * getRadioValue( form.js )
 */
function getScore( ref_form ){
  var score   = 0;
  var i       = 0;
  var int_len = radios.length;

  for( i = 0; i < int_len; i++ )
    score += parseInt( getRadioValue( ref_form[ radios[ i ] ]) );

  return score;
}

/**
 * Announces which required fields need data, validates email fields returns boolean indicating whether or not to submit.
 *
 * PARAMETERS:
 * ref_form - reference to the form containing fields to validate.
 * RETURNS:
 * boolean - true if evaluation is ready to be submitted, false if not
 * REQUIRES:
 * EXTERNAL UDF:
 * valueIsRequired( form.js )
 * validateEmailFormat( form.js )
 */
function submitEvaluation( ref_form ){

  if( !valueIsRequired( ref_form["evaluator"],"Please enter your name into the Evaluator\'s Name field.") )
    return false;

  if( !valueIsRequired( ref_form["eval_email"],"Please enter your email address into the Evaluator\'s Email field.") )
    return false;

  if( !validateEmailFormat( ref_form.eval_email.value ) )
    if( !confirm( ref_form.eval_email.value + " may not be a valid email address. Press OK to confirm this address or Cancel to correct it.") )
      return false;

  if( !valueIsRequired( ref_form["email"],"Please enter the email address of the application\'s author into the Author\'s Email field.") )
    return false;

  if( !validateEmailFormat( ref_form.email.value ) )
    if( !confirm( ref_form.email.value + " may not be a valid email address. Press OK to confirm this address or Cancel to correct it.") )
      return false;

  if( !valueIsRequired( ref_form["web_app"],"Please enter the name of the application you are evaluating into the Web App field."))
    return false;

  // Re-evaluate the score, just in case the evaluator has changed the value by hand
  ref_form.score.value = getScore( ref_form );
  return true;
}
//-->