// Script for the Upper Area Rollover (old site)

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

MM_preloadImages('/common/images/headbar_over/prospective.gif','/common/images/headbar_over/current.gif','/common/images/headbar_over/alumni.gif','/common/images/headbar_over/about.gif','/common/images/headbar_over/search.gif');



// Script for the MTECH Assessment
// Made By: Patrick Gormley, Lapeer East High School (patrickg@mail.si.umich.edu)
// Tweaked By: Toshio Mana, Berklee College of Music (tmana@berklee.edu)
//   -- added an offset to account for additional forms
//   -- cleaned up the error message for unanswered questions
//   4/25/2001
	function quiz() {
	var i = 0
	var startAt = 0  // where to start counting from (first form is now nav-form...)
          			 // this is a 0-based index (meaning that the first form is number 0)
          			 // In other words to start on the second form set startAt to 1
                     // -- Toshio Mana 4/25/2001
	var total=20     // number of questions on the test
	//var total=document.forms.length-2 // Total number of questions.  Last form is submit form
	//total -= startAt // subtract the offset
	var ncorrect=0
	var response=new Array(total)	
	var theForms=new Array(total)
	var answer=new Array(total)
		  		  
	//Collect Questions from document
	for (i=0; i<total; i++) {
		theForms[i]=document.forms[i+startAt]
	}
		  
	//Collect responses to questions.
	for (i=0; i<total; i++) {
		response[i]=theForms[i].answer.selectedIndex
	}
	  
	// Collect correct answers from questions.  
	for (i=0; i<total; i++) {
		answer[i]=theForms[i].correct.value
	}
	
	var flag=true	//assume all questions answered
	var unset=new Array
	var u=0
	for (i=0; i<total; i++) {
		if (response[i]==0) {
			unset[u++] = i
			flag=false
		}
	}
   										
	if (flag) { 
		for (i=0; i<total; i++) {
			if (response[i]==answer[i]) ncorrect++
		}
										 
		document.total.score.value = ncorrect
		var per =  Math.round((ncorrect / total) * 100) 
		document.total.percent.value = per 
		document.total.outof.value=total
					 
		for (i=0; i<total; i++) {
			if (response[i]!=answer[i]) {
				theForms[i].check.checked = true
			} else {
				theForms[i].check.checked = false
			}
		}
	} else {
		var errorMsg = ""
		if (unset.length > 1) {
			errorMsg = "There were " + u + " questions unanswered. "
			errorMsg += "Please go back and answer questions: "
		} else {
			errorMsg = "There was 1 question unanswered. "
			errorMsg += "Please go back and answer question "
		}
		for (i=0; i<u-1; i++) {
			var questionNumber = unset[i]
			questionNumber++ // IE usually treats all variables as string I believe
							 // hence I'm using the autoincrement to force integer type.
							 // If I'm wrong, feel free to clean this up.
							 //   --Toshio Mana, 4/25/2001
			errorMsg += questionNumber
			errorMsg += ", "
		}
		var questionNumber = unset[u-1]
		questionNumber++
		if (unset.length > 1) {
			errorMsg += "and "
		}
		errorMsg += questionNumber
		alert(errorMsg + " ")
	}
				 
	}
