var no = 0; 	/* 現在No. */
var maxNo = 0;	/* 問題数 */

/* start or next 処理 */
function startQA(max) {

	/* 答えを選ばずにnextボタンを押しても無効 */
	if ((no != 0) && (no <= maxNo) && (document.qForm.CorrectA.value == "")) {
		document.qForm.msgs.src = "./img/warning.gif";
		return;
	}
	maxNo = max;
	clearBtn();
	no = no + 1;
	if (no <= maxNo) {
		document.qForm.Qno.src = "./img/" + no + ".gif";
		setQuestion(no);
	}
	else {
		document.qForm.Qno.src = "./img/finish.gif";
		document.qForm.question.value = "Thank you for your challenge !";
		//alert("finished");
	}
}
/* 質問表示 */
function setQuestion(n) {

	document.qForm.question.value = dataDB[n][0];
	document.qForm.a1.value = dataDB[n][1];
	document.qForm.a2.value = dataDB[n][2];
	document.qForm.a3.value = dataDB[n][3];
}
/* 答え合わせ */
function checkAnswer(a) {
var ra;

	document.qForm.msgs.src = "./img/space.gif";
/* いきなり check ボタンを押された時、または
 * 問題が終了しているのに check ボタンを押された時
 */
	if ((no == 0) || (no > maxNo)) {
		clearBtn();
		return;
	}
	ra = dataDB[no][4]; /* 正解No. */
	if (ra == a) {
		document.qForm.result.src = "./img/ok.gif";
	} else {
		document.qForm.result.src = "./img/ng.gif";
	}

	document.qForm.CorrectA.value = "A" + ra + ". " + dataDB[no][ra];
	document.qForm.description.value = dataDB[no][5];
	if (no == maxNo) {
		document.qForm.exec.value = "Finish";
	} else {
		document.qForm.exec.value = "Next";
	}
}
/* エリアクリア */
function clearBtn() {
var i;

	//document.qForm.Qno.src = "./img/space.gif";
	document.qForm.question.value = "";
	document.qForm.a1.value = "";
	document.qForm.a2.value = "";
	document.qForm.a3.value = "";
	for (i=0; i < document.qForm.sel.length; i++) {
		document.qForm.sel[i].checked = false;
	}
	document.qForm.CorrectA.value = "";
	document.qForm.description.value = "";
	document.qForm.result.src = "./img/space.gif";
}

