var alphabet = '1234';
rett = 'All Questions Answered Correctly - Congratulations!';

function popupMsg(rett) {
  alert(rett);
}

function showQuestion(question,answer,choice1,choice2,choice3,choice4) {
    var output = '<P><font size="2"><strong>Question ' + (numberOfQuestions + 1) + ':</font></strong> ' + question + '<P>';

    for (var i = 3, j = 1; i<showQuestion.arguments.length; i++, j++) {
        output += alphabet.substring(j-1,j) + '. ';
        if (answer == j) output += '<INPUT TYPE="RADIO" NAME="q' + numberOfQuestions + '" VALUE="true">';
        else             output += '<INPUT TYPE="RADIO" NAME="q' + numberOfQuestions + '" VALUE="false">';
        output += ' ' + showQuestion.arguments[i] + '<BR>';
    }
 
    numberOfQuestions++;

    return output;
}

function validateAnswers() {
    var correct = 0, wrong = 0, blank = 0;
    for (var i=0;i<numberOfQuestions;i++) {
        var CA = eval("document.quizForm.q" + i + "[0].checked");
        var CB = eval("document.quizForm.q" + i + "[1].checked");
        var CC = eval("document.quizForm.q" + i + "[2].checked");
        var CD = eval("document.quizForm.q" + i + "[3].checked");
        var AA = eval("document.quizForm.q" + i + "[0].value");
        var AB = eval("document.quizForm.q" + i + "[1].value");
        var AC = eval("document.quizForm.q" + i + "[2].value");
        var AD = eval("document.quizForm.q" + i + "[3].value");

        if (CA == CB == CC == CD) blank++; 
        else
            if ((CA.toString() == AA) && (CB.toString() == AB) && (CC.toString() == AC) && (CD.toString() == AD))
                correct++;
            else wrong++;
    }
    document.quizForm.correct.value = correct;
    document.quizForm.wrong.value = wrong;
    document.quizForm.blank.value = blank;

    if (correct != numberOfQuestions) return false; else popupMsg(rett); return true;
}
var numberOfQuestions = 0;
var o = '<FORM NAME="quizForm" ENCTYPE="text/plain" onSubmit="return validateAnswers()">';

o += showQuestion('How old did Norris say the ice was in which the spacecraft was buried?',2,'','50,000 years at least','100,000 years at least','150,000 years at least','200,000 years at least');
o += showQuestion('When Dr. Blair was imprisoned in the tool shed who did he say should be watched closely?',4,'','Nauls','Garry','Childs','Clark');
o += showQuestion('What can of beer does MacReady get out the fridge then use to break the glass on the alarm?',2,'','Labatts','Budweiser','Schlitz','Heineken');
o += showQuestion('What is the probability that one or more team members may be infected?',3,'','50%','95%','75%','85%');
o += showQuestion('How many of the crew of the U.S. camp had beards?',1,'','5','4','3','6');
o += showQuestion('What is the number on the door of MacReady&#39;s helicopter?',4,'','341','432','436','452');
o += showQuestion('What is the name of the radio operator?',2,'','Nauls','Windows','Childs','Gary');
o += showQuestion('How many crew of the U.S. camp were there?',2,'','11','12','9','8');
o += showQuestion('Who smashes up the helicopter?',3,'','Bennings','Palmer','Dr. Blair','Dr. Copper');
o += showQuestion('What window did MacReady break to get back into the main building after Nauls "cut him loose" in the storm?',1,'','Supply window','Kitchen window','Recreation room window','Toilet window');
o += showQuestion('Why did MacReady & Nauls go to MacReady&#39;s shack?',3,'','It was on fire','They saw someone up there','The lights were on','The door was open');
o += showQuestion('Why couldn&#39;t they fix the generator?',1,'','It was gone','They didn&#39;t have the required parts','It was beyond repair','Those who were left alive didn&#39;t know how to');
o += showQuestion('Who gets shot in the leg by one of the Norwegians?',2,'','Clark','Bennings','Fuchs','Dr. Copper');
o += showQuestion('What number is the Institute Station on the board outside the camp?',2,'','2','4','6','8');
o += showQuestion('Who was Windows trying get a hold of on the radio?',4,'','McMinto','McMillan','McMilligan','McMurdo');
o += showQuestion('Who went to the Norwegian&#39;s camp?',2,'','MacReady & Norris','MacReady & Dr. Copper','MacReady & Dr. Blair','Palmer & Bennings');
o += showQuestion('What is the make of video recorder Palmer & Childs were watching?',3,'','Sony','JVC','Panasonic','Philips');
o += showQuestion('Who is playing pool just before the dog is sent to the kennel?',1,'','Clark & Nauls','Nauls & Garry','Garry & Fuchs','MacReady & Palmer');
o += showQuestion('Who is in the room with Dr. Blair as he is going berserk?',4,'','Palmer','Gary','Dr. Copper','Windows');
o += showQuestion('Who discovered Fuchs&#39; burnt body?',2,'','MacReady','Windows','Dr. Copper','Clark');
o += showQuestion('How many legs did Norris&#39;s head sprout?',2,'','8','6','4','2');
o += showQuestion('Who&#39;s blood reacts badly to the test?',2,'','Gary','Palmer','Childs','Nauls');
o += showQuestion('Which door does Childs go round to when Dr. Blair is going berserk?',1,'','Map room','Recreation room','Hallway','Storage room');
o += showQuestion('Who finds MacReady&#39;s torn clothing in the snow when the lights are out?',4,'','Nauls','Palmer','Bennings','Fuchs');
o += showQuestion('What brand of whisky does MacReady drink?',3,'','Johnnie Walker','Glenfiddich','J&B','Bell&#39;s');

o += '<center>';
o += '<P><INPUT TYPE="SUBMIT" VALUE="Click Here for Score">';
o += ' Correct: <INPUT TYPE="TEXTBOX" NAME="correct" VALUE="" SIZE="2">';
o += ' Wrong: <INPUT TYPE="TEXTBOX" NAME="wrong" VALUE="" SIZE="2">';
o += ' Blank: <INPUT TYPE="TEXTBOX" NAME="blank" VALUE="" SIZE="2" >';
o += '</center>';
o += '</FORM>';

document.write(o);
