<!-- 

function baseHREF() {
pathURL = window.location + ''; //little bug with URLs and strings
pathDir = pathURL.lastIndexOf ('/tutorials/', pathURL.length);
pathBase = pathURL.substring (0, pathDir + 1);
return pathBase;
}

var docObj = (is_ie4up)?'document.all.':'document.';
var styObj = (is_ie4up)?'.style':'';

var topObj;
var imgObj;
var iObj;
var qObj;
var rObj;
var kObj;


function define() {
  if (is_nav4) { // Navigator 4.0x
   imgObj = document.response.document;
   topObj = document.intro.document.topics;
   document.height = document.intro.top + document.intro.document.height
   }
  else if (is_ie4up) { // Internet Explorer 4.0x and up
   imgObj = document;
   topObj = document.all.topics;
   }
  else if (is_nav5up) {// the dreaded Navigator 5.0x
   imgObj = document;
   topObj = document.getElementById("topics");
   }
  iObj = eval(docObj + 'intro' + styObj);
  qObj = eval(docObj + 'question' + styObj);
  rObj = eval(docObj + 'response' + styObj);
  kObj = eval(docObj + 'keyboard' + styObj);
}


function browsercheck() {
  if ((is_ie)&&(is_mac)) {
    alert("Sorry...  This quiz doesn't work if you are using IE on a Mac.  You'll need to use Netscape or switch to a PC.");
    return false;
  }
  if (is_nav5up) {
    alert("Sorry... This quiz will not work with Netscape 6, and may not work with Netscape 7. Please try another browser.");
    return false;
  }
  if ((is_ie4up)||(is_nav4up)) {
    setTimeout('populate()',100);
  }
  else {
    alert("Attention:  This quiz has not yet been tested on the browser and computer combination that you are using and errors may occur.  We would appreciate it if you could let us know how it works.");
    populate();
  }
}


var qlength = 5


function populate() {
  questpool = new Array();
  randquest = new Array();
   for (var i=0; i<topObj.length-5; i++) { 
     if (topObj.elements[i].checked) {
       questpool = questpool.concat(eval('Vocab' + i));
       } 
     } 
   if (topObj.count[3].checked) {
     randquest = questpool;
     qlength = questpool.length;
     iObj.visibility = "hidden";
     qObj.visibility = "visible";
     rObj.visibility = "visible";
     kObj.visibility = "visible";
     selectWord();
     return false;
     }
   if (topObj.count[2].checked) {
     qlength = 50;
     }
   if (topObj.count[1].checked) {
     qlength = 25;
     }
   if (topObj.count[0].checked) {
     qlength = 10;
     }
   if (questpool.length<=qlength) {
      alert("The topics you have chosen do not contain enough items to make a full quiz.  Please choose additional topics.");
      return false;
      }
   while (randquest.length<qlength)  {
   var add = Math.floor(Math.random() * questpool.length); 
   var match = 0; 
   for (var i=0; i<randquest.length; i++) { 
      if (randquest[i] != questpool[add]) {      
         continue; 
         } 
      else { 
         match = 1
         break; 
         } 
      } 
   if (match==0) { 
      randquest[randquest.length] = questpool[add];
      } 
    }    
     iObj.visibility = "hidden";
     qObj.visibility = "visible";
     rObj.visibility = "visible";
     kObj.visibility = "visible";
   selectWord();
}


var aleph = 0
var rcount = 0
var wcount = 0
var testx = 0


var wordlist = '<TABLE WIDTH=450 BORDER=0 CELLPADDING=3><TD ALIGN=LEFT VALIGN=TOP WIDTH="40%"><span class="text2"><U>Your word list:</U></span><BR>';


function restart() {
  aleph = 0
  rcount = 0
  wcount = 0
  testx = 0
  //jumble the order in which the terms are presented each time the page is run
	var temp = 0;
	var tempQuest = new Array();	

	var max = qlength
	for (i=0; i<qlength; i++) {
		temp = Math.floor(Math.random()*max);
		tempQuest[i] = randquest[temp];
		for (j=temp; j<=max; j++) {
			randquest[j] = randquest[j+1];
		}

		randquest.length = randquest.length-1;
		max = max-1;
	}
	randquest = tempQuest;
  wordlist = '<TABLE WIDTH=450 BORDER=0 CELLPADDING=3><TR><TD ALIGN=LEFT VALIGN=TOP WIDTH="40%"><span class="text2"><U>Your word list:</U></span><BR>';
  errorslist = '';
     iObj.visibility = "hidden";
     qObj.visibility = "visible";
     rObj.visibility = "visible";
     kObj.visibility = "visible";
   selectWord();
}


function getRandom() {
  return Math.random()
  }
    
function selectWord() {
  var gimel = "answer"
  var dalet = "answer"
  if (rcount != 1) {
    gimel = "answers";
  }
  if (wcount !=1) {
    dalet = "answers";
  }

window.scroll(0,0);

newPage = '<TABLE WIDTH=570 BORDER=0 CELLPADDING=0><TR><TD ALIGN=CENTER><TABLE BORDER=0 CELLPADDING=7><TR><TD ALIGN=CENTER VALIGN=MIDDLE BGCOLOR="#003E8F" NOWRAP><span class="text1"><font color="#FF9933"><b>Term # ' + (aleph + 1) + '</b></font></span></TD></TR></TABLE></TD></TR></TABLE>';
          
finalPage = '<TABLE WIDTH=570 BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD ALIGN=CENTER VALIGN=MIDDLE COLSPAN=3 CLASS="tan"><HR SIZE=1 NOSHADE><BR></TD></TR><TR><TD WIDTH=10 ALIGN=LEFT VALIGN=TOP BGCOLOR=#003E8F><img src="../images/ul.gif" width="10" height="10" border="0"></TD><TD ALIGN=CENTER CLASS="text2" BGCOLOR=#003E8F><img src="../images/dot_clear.gif" width="550" height="3" border="0"><BR><FONT COLOR=#FF9933><B>Results</B></FONT><BR><img src="../images/dot_clear.gif" width="550" height="3" border="0"></TD><TD WIDTH=10 ALIGN=RIGHT VALIGN=TOP BGCOLOR=#003E8F><img src="../images/ur.gif" width="10" height="10" border="0"></TD></TR><TR><TD BGCOLOR="#EEEEEE" ALIGN=LEFT VALIGN=TOP CLASS="text3">&nbsp;</TD><TD COLSPAN=2 BGCOLOR=#FFFFFF ALIGN=CENTER VALIGN=MIDDLE><P>&nbsp;</P><div class="text2"><P><B>For the ' + aleph + ' words in this quiz, you gave ' + rcount + ' correct ' + gimel + ', and ' + wcount + ' wrong ' + dalet +'.</B></P></div>';

if (aleph !=0) {
  if (testx==0) {
    wordlist = wordlist + '<span class="text2">- <FONT COLOR=RED>' + Answer1[randquest[aleph-1]] + '</FONT></span><BR>';
    }
  else {
    wordlist = wordlist + '<span class="text2">- ' + Answer1[randquest[aleph-1]] + '</span><BR>';
    }
}
          
if (aleph <= qlength-1) {
  if (is_ie4up) {
    document.all.question.innerHTML = newPage;
    document.all.quizword.src = '../H2Ewords/' + prefix + '-' + randquest[aleph] + '.gif'
    document.all.quizform.elements[0].focus();
    document.all.quizform.elements[0].value="";
    }
  if (is_nav4) {
    document.question.document.write(newPage);
    document.question.document.close();
    document.response.document.quizword.src = '../H2Ewords/' + prefix + '-' + randquest[aleph] + '.gif'
    document.keyboard.document.forms[0].answer.focus();
    document.keyboard.document.forms[0].answer.value="";
    }
  testx = 0;
  imgOn = new Image();
  imgOn.src = eval("'../H2Ewords/" + prefix + "-" + randquest[aleph+1] + ".GIF'");
  imgOnX = new Image();
  imgOnX.src = eval("'../H2Ewords/" + prefix + "-" + randquest[aleph+1] + "x.GIF'");
  }
else {
   qObj.visibility = "hidden";
   rObj.visibility = "hidden";
   kObj.visibility = "hidden";
   iObj.visibility = "visible";
   finalPage = finalPage + wordlist + '</TD><TD ALIGN=CENTER VALIGN=MIDDLE><span class="text2"><I>Any word that did not receive a correct answer is shown in red.</I></span></TD></TR><TR><TD COLSPAN=2 ALIGN=CENTER VALIGN=MIDDLE><FORM NAME="fcontrols"><INPUT NAME="button1" TYPE="button" VALUE="Repeat This List of Terms" onClick="javascript:parent.restart();">&nbsp;&nbsp;<INPUT NAME="button2" TYPE="button" VALUE="Choose a New List" onClick="javascript:location.reload()"></FORM></TD></TR></TABLE><BR><img src="http://darkwing.uoregon.edu/~ylcflx/Aleph-Bet/cgi-bin/counter.cgi?tutorial=' + tutorialID + '&rcount=' + rcount + '&wcount=' + wcount + '&total=' + aleph + '&random=' + getRandom() + '" width="1" height="1">';
  if (wcount>0) {
      finalPage = finalPage + '<BR><img src="http://darkwing.uoregon.edu/~ylcflx/Aleph-Bet/cgi-bin/H2Emistakes.cgi?tutorial=' + tutorialID + errorslist + '" width="1" height="1">';
      }
   finalPage = finalPage + '</TD></TR><TR><TD ALIGN=LEFT VALIGN=MIDDLE COLSPAN=3 CLASS="tan"><hr size=1><span class="text4">This page is maintained by the <a href="http://babel.uoregon.edu/">Yamada Language Center</a> at the <a href="http://www.uoregon.edu/">University of Oregon</a>.<br>Questions, comments, and suggestions should be addressed to <a href="mailto:ylc@oregon.uoregon.edu">ylc@oregon.uoregon.edu</a><br></span></TD></TR></TABLE>';
   if (is_ie4up) {
      document.all.intro.innerHTML = finalPage;
      document.height = document.all.intro.top + document.all.intro.document.height
      }
   if (is_nav4) {
      document.intro.document.write(finalPage);
      document.intro.document.close();
      document.height = document.intro.top + document.intro.document.height
      }
   }
}


var errorslist = '';


function replace(string,text,by) {
// Replaces text with by in string
   var strLength = string.length, txtLength = text.length;
   if ((strLength == 0) || (txtLength == 0)) return string;

   var i = string.indexOf(text);
   if ((!i) && (text != string.substring(0,txtLength))) return string;
   if (i == -1) return string;

   var newstr = string.substring(0,i) + by;

   if (i+txtLength < strLength)
           newstr += replace(string.substring(i+txtLength,strLength),text,by);

   return newstr;
   }


function test (response) {
   if ((response== Answer1[randquest[aleph]])||(response== Answer2[randquest[aleph]])||(response== Answer3[randquest[aleph]])||(response== Answer4[randquest[aleph]])||(response== Answer5[randquest[aleph]])||(response== Answer6[randquest[aleph]])||(response== Answer7[randquest[aleph]])||(response== Answer8[randquest[aleph]])) {
      alert("Yes!");
      testx = 1;
      rcount++;
      aleph++;
      selectWord();
      return false;
   }
   else {
      alert("Sorry, try again.");
      wcount++;
      response = response.replace(/[^a-zA-Z 0-9?.,!'()]+/g,'(?)');
      errorslist = errorslist + '&' + replace(Answer1[randquest[aleph]],' ','+') + '=' + replace(response,' ','+');
      refresh();
      return false;
   }
}

function giveAnswer () {
   alert('The answer is "' + Answer1[randquest[aleph]] + '"');
   refresh();
}

function showVowels () {
  if (is_ie4up) {
    document.all.quizword.src = baseHREF() + "H2Ewords/" + prefix + "-" + randquest[aleph] + "x.gif";
    document.all.quizform.elements[0].focus();
  }
  if (is_nav4) {
    document.response.document.quizword.src = baseHREF() + "H2Ewords/" + prefix + "-" + randquest[aleph] + "x.gif";
    document.keyboard.document.forms[0].answer.focus();
  }
}

function refresh () {
  if (is_ie4up) {
    document.all.quizform.elements[0].focus();
    document.all.quizform.elements[0].select();
  }
  if (is_nav4) {
    document.keyboard.document.forms[0].answer.focus();
    document.keyboard.document.forms[0].answer.select();
  }
}

// End of script -->
