function radioanswer(questNO, selection, total) {
  var x = document.getElementById("selection" + questNO);
  var y = document.getElementById("count");
  if (x.value == 0) {
    y.value++;
    if (y.value == total) document.getElementById("examsubmit").disabled = false;
  }
  x.value = selection;
}

function checkanswer(questNO, selection, total) {
  var x = document.getElementById("selection" + questNO);
  var y = document.getElementById("count");
  var self = document.getElementById(questNO + selection);
  if (self.checked) {
    if (x.value == 0) {
      y.value++;
      if (y.value == total) document.getElementById("examsubmit").disabled = false;
      x.value = selection;
    } else {
      if (x.value.charAt(0) > selection) x.value = selection + "," + x.value;
      else if (x.value.charAt(x.value.length - 1) < selection) x.value += "," + selection;
      else {
        for (i = 0; i < x.value.length; i += 2) {
          if (x.value.charAt(i) > selection) {
            x.value = x.value.substring(0, i) + selection + "," + x.value.substring(i, x.value.length);
            break;
          }
        }
      }
    }
  } else {
    if (x.value == selection) {
      x.value = 0;
      if (y.value == total) document.getElementById("examsubmit").disabled = true;
      y.value--;
    } else {
      for (i = 0; i < x.value.length; i += 2) {
        if (selection == x.value.charAt(i)) {
          if (i == 0) x.value = x.value.substring(2, x.value.length);
          else if (i == x.value.length - 1) x.value = x.value.substring(0, i-1);
          else x.value = x.value.substring(0, i) + x.value.substring(i+2, x.value.length);
          break;
        }
      }
    }
  }
}

function textanswer(questNO, total) {
  var x = document.getElementById("selection" + questNO);
  var y = document.getElementById("count");
  var text = document.getElementById(questNO + "text");
  if (text.value != null) {
    if (x.value == 0) {
      y.value++;
      if (y.value == total) document.getElementById("examsubmit").disabled = false;
    }
    x.value = text.value;
  } else alert("请先在左边文字框内输入您的答案！");
}

function copypass(clipString) {
  window.clipboardData.setData('text', clipString);	
}