/**
 * Generalized form processing functions to be reused.
 */

function getRadioValue( ref_radio ){
// Returns value of selected RADIO box or null if none selected.
  var int_len = ref_radio.length;
  var i       = 0;

  for( i = 0; i < int_len; i++ )
    if( ref_radio[ i ].checked )
      return ref_radio[ i ].value;

  return null;
}

function valueIsRequired( ref_hasValue, str_message ){
// Test to make sure reference is not null.
  if( !ref_hasValue ) return false;

  if( !ref_hasValue.value ){
    alert( str_message );
    ref_hasValue.focus();
    return false;
  }

  ref_hasValue.value = trim( ref_hasValue.value );
  if( ref_hasValue.value.length == 0 ){
     alert( str_message );
     ref_hasValue.focus();
     return false;
  }
  return true;
}

function trim( str_toTrim ){
// Trims spaces off of strings
  var chr_char  = " ";
  var i         = 0;
  var int_start = 0;
  var int_end   = str_toTrim.length;

  while( str_toTrim.charAt( int_start ) == " " && int_start < int_end )
    int_start++;

  while( str_toTrim.charAt( int_end - 1 ) == " " && int_end > 0 )
    int_end--;

  if( int_start >= int_end ) return "";
  return str_toTrim.substring( int_start, int_end );
}

function validateEmailFormat( str_eddress ){
// Checks whether a string has @ and a valid American Top Level Domain.
  if(  str_eddress.indexOf("@") != -1 &&    // Must have @
     ( str_eddress.indexOf(".com") != -1 || // Must have valid domain
       str_eddress.indexOf(".edu") != -1 ||
       str_eddress.indexOf(".gov") != -1 ||
       str_eddress.indexOf(".mil") != -1 ||
       str_eddress.indexOf(".net") != -1 ||
       str_eddress.indexOf(".org") != -1 ) )
    return true;

  return false;
}