function Question(text,answer) {
 this.text = text;
 this.answer = answer;
}
answers = new Object();
answers["A"] = "Bethesda, MD";
answers["B"] = "Boston, MA";
answers["C"] = "Chicago, IL";
answers["D"] = "Cleveland, OH";
answers["E"] = "Corning, NY";
answers["F"] = "Dallas, TX";
answers["G"] = "Davenport, IA";
answers["H"] = "Denver, CO";
answers["I"] = "Kennebunkport, ME";
answers["J"] = "Las Vegas, NV";
answers["K"] = "Louisville, KY";
answers["L"] = "New Orleans, LA";
answers["M"] = "New York, NY";
answers["N"] = "Orlando, FL";
answers["O"] = "Phoenix, AZ";
answers["P"] = "Raleigh, NC";
answers["Q"] = "San Diego, CA";
answers["R"] = "San Francisco, CA";
answers["S"] = "Seattle, WA";
answers.length = 19;  

questions = new Object();
questions[0] = null; // skip index [0]
questions[1] = new Question("1989","K");
questions[2] = new Question("1990","K");
questions[3] = new Question("1991","K");
questions[4] = new Question("1992","A");
questions[5] = new Question("1993","K");
questions[6] = new Question("1994","R");
questions[7] = new Question("1995","C");
questions[8] = new Question("1996","E");
questions[9] = new Question("1997","S");
questions[10] = new Question("1998","N");
questions[11] = new Question("1999","I");
questions[12] = new Question("2000","G");
questions[13] = new Question("2001","Q");
questions[14] = new Question("2002","L");
questions.length = 14;

quiz_title = "KALEIDOSCOPE QUIZ #1";

maximum_score = 100;
penalty_for_wrong_answer = -100/questions.length;
reveal_correct_answer = false;
messageline="";

// ---------------------------------------------------------------------
function choice() {
 for(n=0;n<answers.length;n++)
  eval("document.matching.answer"+n+".checked = false");
 for(n=1;n<=questions.length;n++) {
  sel = eval("document.matching.choice"+n+".selectedIndex");
  eval("document.matching.answer"+sel+".checked = true");
 }
}
function clearall() {
 document.matching.evaluation.value ="";
 for(n=1;n<=questions.length;n++) {
   sel=eval("document.matching.choice"+n);
   sel.selectedIndex=0; 
 }
 document.resultspic.src="clear.gif"
 document.messagepic.src="clear.gif"
}

function gradeQuiz() {
 wrong = "";
 correct = questions.length;
 score = maximum_score;
 for(n=1;n<=questions.length;n++) {
  sel = eval("document.matching.choice"+n+".selectedIndex");
  if (alpha.charAt(sel) != questions[n].answer) {
   correct -= 1;
   score += penalty_for_wrong_answer;
   wrong += "#"+n+" wrong! "
    +(reveal_correct_answer?"Correct answer is "+questions[n].answer:"")
    +"\r\n";
  }
 }
 
ncorrect=correct/questions.length

if (correct==questions.length) {
  document.resultspic.src="results10.gif";
  document.messagepic.src="complete.gif";
} else if (ncorrect<=.1) {
  document.resultspic.src="clear.gif";
  document.messagepic.src="empty.gif";
} else {
  ncorrect=parseInt(10*ncorrect)
  document.resultspic.src="results"+ncorrect+".gif";
  document.messagepic.src="incomplete.gif";
}

 document.matching.evaluation.value ="You answered " + correct + " of " + questions.length + " correctly.\r\n"+wrong;
}

alpha = " ABCDEFGHIJKLMNOPQRS";

answers_menu = "";
answers_text = "<td nowrap rowspan=" + questions.length + " valign=top>"
+'<font face="Verdana, Arial, Helvetica" size=-1 color="#0000ff">'
+"<table cellpadding=2 cellspacing=0><tr><td><br></td></tr>";

for(n=0;n<answers.length+1;n++) {
 answers_menu += "<option>"+alpha.charAt(n);
}
for(n=1;n<answers.length+1;n++) {
 answers_text += '<tr><td valign="bottom">'
 +'<font face="Verdana, Arial, Helvetica" size=-1 color="#0000ff">'
 +'<b>'+ alpha.charAt(n)+ '. </b></td><td valign="bottom">'
 +'<font face="Verdana, Arial, Helvetica" size=-1 color="#0000ff">'
 +'<b>' + answers[alpha.charAt(n)]+'</b></td></tr>';
}
answers_text += "</table></td>";

document.write(
'<font face="Verdana, Arial, Helvetica" size=+0 color="#000000">'
+'<center><h4>' + quiz_title + '</h4>'
+'<b><font color="#008888">'
+'<font color="#aa00aa" size=+0>TOPIC: </font>LOCATIONS OF PAST BREWSTER SOCIETY CONVENTIONS</font></b><br>'
+"<font size=-2><i>(There's a bit of a trick to this one, don't make me repeat myself)</i></font></center><p>"
+'<font size=-1><i>Directions: Match the <font color="#006666"><b>questions</b></font> on the left with the' 
+'<font color="#0000ff"><b> answers</b></font> on the right. Choose your answer from the '
+'dropdown menus to the left of the questions.  Click the <i>Grade the Quiz</i> button below to see how you did.<br><br></i></font>');

//main table form
document.write('<form name="matching">'
+'<center><table cellpadding=0 cellspacing=0>');

//table of menu/question number/question
document.write('<tr><td valign="top"><table>');

for(n=1;n<=questions.length;n++) {
 document.write('<tr><td align="right" valign="middle" height=30>'
+'<select name="choice'+ n + '" size=1>'+answers_menu+'</select>&nbsp;&nbsp;</td>');
 document.write('<td valign="middle">'
+'<font face="Verdana, Arial, Helvetica" size=-1 color="#006666">'
+ '<b>' + n + '.</b></td>'
+'<td valign="middle">'
+'<font face="Verdana, Arial, Helvetica" size=-1 color="#006666">'
+'<b>' + questions[n].text+'</b></td></tr>');
}
document.write('</table></td>');

//spacer column
document.write('<td rowspan=' + questions.length +' valign="top" width="30"><br></td>');

//answers
document.write(answers_text);

//spacer column
document.write('<td rowspan=' + questions.length +' valign="top" width="30"><br></td>');

//grading and results
document.write('<td rowspan=' + questions.length + ' valign="top"><br>');
document.write('<center><input type=button value="Grade the Quiz" '
+'onClick="gradeQuiz()"><input type=button value="Clear answers" onClick="clearall()">'
+'<br><br><textarea rows=8 cols=40 name="evaluation"></textarea><p>');
document.write('<img src="clear.gif" height=169 width=175 name="resultspic">'
+'<br><img src="clear.gif" height=60 width=250 name="messagepic"></center></td>'
+'</tr>');

//Finish up table
document.write('</table></center></form>');

