questArray = new Array();

//var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
function checkAnswers(beginForm, endForm) {
    function mark_result(res) {
        document.images["checkResult" + endForm].src = "/mod/quiz/pix/" + res + ".gif";
    }
    try {
        flagRightAnswersGlobal = "";

        flagWrongAnswersGlobal = "";

        for (total_number = beginForm; total_number <= endForm; total_number++) {
            flagRightAnswers = "";

            flagWrongAnswers = "";
            currentForm = document.forms["questionform" + total_number]; //document.forms[total_number];
            answersArray = questArray[total_number];//alert(answersArray);
            //TEXT and DEFAULT
            if (!currentForm.answer0.type || currentForm.answer0.type == "text") {
                for (i in answersArray) {
                    if (answersArray[i].toLowerCase() == trim(currentForm.answer0.value.toLowerCase()) ) {
                        mark_result("right");
                        return;
                    }
                }
                currentForm.answer0.value=answersArray[0];
                mark_result("wrong");
                return;
            }
            //MATCH
            if(currentForm.answer0.type == "hidden") {
                for (i in answersArray) {
                    if (currentForm["answer" + i ].parentNode.nextSibling.nextSibling.childNodes[0].value!=answersArray[i]) {
                        mark_result("wrong");
                        return;
                    }
                }
                mark_result("right");
                return;
            }
            //MULTI
            for (i in answersArray) {
                if (currentForm["answer" + i ].checked != answersArray[i]) {
                    flagWrongAnswers = true;
                    flagWrongAnswersGlobal = true;
                } else {
                    if (answersArray[i] == true) {
                        flagRightAnswers = true;
                        flagRightAnswersGlobal = true;
                    }
                }
            }

            flagWrongAnswers == true ?wr="_":wr="";
            for (i in answersArray) {
                current_image_id = document.images["ans" + total_number + "_" + i];

                if (answersArray[i] == true) {
                    if (currentForm["answer" + i].type == "checkbox") {
                        current_image_id.src = "/mod/quiz/pix/raven"+wr+".gif";
                    }
                    if (currentForm["answer" + i].type == "radio") {
                        current_image_id.src = "/mod/quiz/pix/rraven"+wr+".gif";
                    }
                } else {
                    if (currentForm["answer" + i].type == "checkbox") {
                        current_image_id.src = "/mod/quiz/pix/none"+wr+".gif";
                    }
                    if (currentForm["answer" + i].type == "radio") {
                        current_image_id.src = "/mod/quiz/pix/rnone"+wr+".gif";
                    }
                }
            }
        }
        if (flagWrongAnswersGlobal == true) {
            if (flagRightAnswersGlobal == true) {
                mark_result("notright")
            } else {
                mark_result("wrong")
            }
        } else {
            mark_result("right")
        }
    } catch(er) {}
}
