function checkFields( theForm, paperTrack ) {
    //alert ('checkFields');

    if ( ! (     ( checkRadioField( theForm.radioComment, 5, 'a rating' ) )
              && ( checkRadioField( theForm.radioRecomm, 4, 'a recommendation' ) ) 
              && ( checkRadioField( theForm.presTypeRevr, 4, 'a presentation type' ) )
              && ( checkRadioField( theForm.radioTrack, 3, 'a track' ) )
              && ( checkRadioField( theForm.invitePublication, 4, 'a decision on submitting a full paper' ) )
              && ( checkRadioField( theForm.interestChairing, 2, 'an answer regarding chairing' ) )
              && ( checkRadioField( theForm.disclosure_know, 2, 'an answer for each disclosure question' ) )
              && ( checkRadioField( theForm.disclosure_friend, 2, 'an answer for each disclosure question' ) )
              && ( checkRadioField( theForm.disclosure_interact, 2, 'an answer for each disclosure question' ) )
              && ( checkRadioField( theForm.disclosure_talked, 2, 'an answer for each disclosure question' ) )
              && ( checkRadioField( theForm.disclosure_reviewed, 2, 'an answer for each disclosure question' ) )
              && ( checkRadioField( theForm.disclosure_collabor, 2, 'an answer for each disclosure question' ) )
              && ( checkRadioField( theForm.disclosure_supervis, 2, 'an answer for each disclosure question' ) )
              && ( checkRadioField( theForm.disclosure_student, 2, 'an answer for each disclosure question' ) )
              && ( checkRadioField( theForm.disclosure_heard, 2, 'an answer for each disclosure question' ) )
              && ( checkRadioField( theForm.disclosure_benefit, 2, 'an answer for each disclosure question' ) )
              && ( checkRadioField( theForm.disclosure_unbiased, 2, 'an answer for each disclosure question' ) )

              && ( checkTextFields( theForm.themeChoice, 'the theme' ) )
              && ( checkTextFields( theForm.commentsCommitee, 'comments for the Scientific Program Committee' ) )
              && ( checkTextFields( theForm.commentsAuthorAbstr, 'comments to improve the abstract' ) )
              && ( checkTextFields( theForm.comments, 'comments on presentation type' ) )

              && (     ( paperTrack != "RESEARCH" )
                    || ( checkTextFields( theForm.commentsAuthorPaper, 'comments concerning the full paper' ) )
                  )
              && (     ( theForm.disclosure_unbiased[0].checked )
                    || ( checkTextFields( theForm.disclosureBiasReason, 'the reason for bias' ) )
                  )

                           ) )  {
        return false;
    } else { 
        return true;
    }
}

function checkRadioField( theRadioField, numb, name ) {
    //alert (theRadioField[0].checked);
    for ( i = 0; i < numb; i++ ) {
    selected = false;
        if ( theRadioField[i].checked ) {
            selected = true;
            break;
        }
    }
    if ( !selected ) {
        alert('Please select ' + name + '.');
        theRadioField[0].focus();
        return false;
    } else {
        return true;
    }
}

function checkTextFields( thetextField, name ) {
    if ( trimit( thetextField.value )  == "" ) {
        alert('Please enter ' + name + '.');
        thetextField.focus();
        return false;
    } else {
        return true;
    }
}

function trimit(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while ( (ch == " ") || (ch == "\r") || (ch == "\n") ) { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

