

function tokenize(str) {
  var j = str.split(':');
  return j;
}

function formReset(tform) {
  tform.reset();
}

function getTotals(tform) {
  var total = {a:0, b:0, c:0, answers:0};
  var qs = ['q1', 'q2', 'q3','q4', 'q5','q6','q7','q8','q9','q10'];
  var answerArray = [];
  for (i=0; i<qs.length; i++) {
    currSelection = tform.elements[qs[i]];
      for(j=0; j<currSelection.length; j++) {
       if (currSelection[j].checked) {
         total.answers += 1;
         // tokenize string and add values to each one
         answerArray = tokenize(currSelection[j].value);
         for(k=0; k<answerArray.length; k++) {
           switch (answerArray[k]) {
             case 'a':
             total.a += 1;
             break
             case 'b':
             total.b += 1;
             break
             case 'c':
             total.c += 1;
             break
           } // switch  
         }  // for k
       } // if .checked
      }
    }
    if (total.answers < 10 ) {
      alert("Please answer all questions.");
      
    } else {
      
      //alert ("totals a:" + total.a + '\n' + "b: " + total.b + '\n' + "c: " + total.c + '\n' + "answers: " + total.answers);
      document.getElementById('quizResult').style.display = '';
      document.getElementById(detScore(total)).style.display = '';
      document.getElementById('quizQs').style.display = 'none';
    }
     

}

function detScore(obj) {
  var max = '';
  if (obj.a >= obj.b) {
    // a > b
    if (obj.a >= obj.c) {
      max = 'a'; //a
    } else {
      max = 'c';
    }
  } else {
    // b > a
    if (obj.b >= obj.c) {
      max = 'b';
    } else {
      max = 'c';
    }

  }
  return max;
}
