var pCount=0,sCount=0,iCount=0,bCount=0;

var itemList = new Array("p1","s2","i3","b4","p5","s6","i7","b8","p9","s10","i11","b12","p13","s14","i15","b16","p17","s18","i19","b20","p21","s22","i23","b24","p25","s26","i27","b28");
var	resultSection = "";
var resultHead =  '<h1>Four Families Answer Key</h1><div id="container"><p><b>Personal source.</b> This group of approaches acknowledges the uniqueness of the individual and the importance of structuring meaning and direction at individual levels.</p><br />';
    resultHead += "<p><b>Social interaction.</b> This group of methods aims at building learning communities and purports to develop productive ways of interacting in a democratic setting.</p><br />";
		resultHead += "<p><b>Information processing.</b> This is the largest grouping of approaches aimed at emphasizing ways of learning specific information and of acquiring and organizing data, solving problems, and developing concepts and language.</p><br />";
    resultHead += "<p><b>Behavioral modification.</b> Behavioral techniques are amenable to highly structured outcomes which concentrate on observable objectives such as learning to read, physical skills, and behavioral adaptations.</p><br />";
		resultHead += '<table cellpadding="6px"><tr><td><b>P = Personal Source</b></td><td><b>S = Social Interaction</b></td></tr>';
		resultHead += "<tr><td><b>I = Information Processing</b></td><td><b>B = Behavioral Modification</b></td></tr></table>";
		resultHead += "<p>Obviously, the higher your score, the more comfortable and committed you are, or will be with models and instructional tasks that mirror your preferences.</p>";
		
var resultEnd =  '<p class="center">&lt;--------&nbsp;&nbsp;&nbsp;&nbsp;--------&gt;</p>';
    resultEnd += '<p class="center">&nbsp;0---------------17&nbsp;&nbsp;&nbsp;&nbsp;18---------------35</p>';
		resultEnd += '<p class="center"><b>Low preference</b>&nbsp;&nbsp;&nbsp;----&nbsp;&nbsp;&nbsp;<b>High preference</b></p>';
		resultEnd += "<br /><br /><p>Teachers selecting the <b>S and P</b> families tend to be more flexible in their approach to teaching and their assessments correlate and reflect the same flexibility.</p><br /><br />";
		resultEnd += "<p>You may wish to print or record your results. The back button will take you to a reset version of the quiz.</p><br />";
		resultEnd += '<p class="center"><input type="button" value="Back" onclick="fncReload();" />&nbsp;&nbsp;&nbsp;<input type="button" value="Print" onclick="window.print();" />&nbsp;&nbsp;&nbsp;<input type="button" value="Close" onclick="window.close();" /></p></div>';
		
function fncCheckQuiz(){
  if(fncNullCheck()){
	  fncReturnScore();
	}
}

function fncNullCheck(){
 var	count = 0;
 var  valHolder = document.getElementById(itemList[count]).value;

 while(valHolder != "" && count < itemList.length){
  valHolder = document.getElementById(itemList[count]).value;
	fncGradeQuiz(count,valHolder);
	count++;
 }
 if(valHolder == ""){
   pCount=0;sCount=0;iCount=0;bCount=0;
   alert("You must enter a value for each statement!");
	 return false;	 
 }
 else{
   return true;
 }
}

function fncGradeQuiz(numIndex,statValue){
  category = itemList[numIndex].substr(0,1);
	switch(category){
	 case "p":
	   pCount += parseInt(statValue);
	   break;		 
	 case "s":
	   sCount += parseInt(statValue);
	   break;
	 case "i":
	   iCount += parseInt(statValue);
	   break;		 
	 case "b":
	   bCount += parseInt(statValue);
	   break;
	}
}

function fncReturnScore(){
  fncSetResults();
  document.body.innerHTML = resultHead + resultSection + resultEnd;
}

function fncSetResults(){
  resultSection = '<br /><br /><p class="scores">P<u>&nbsp;&nbsp;&nbsp;<span class="results">' + pCount + '</span>&nbsp;&nbsp;&nbsp;</u>';
	resultSection += 'S<u>&nbsp;&nbsp;&nbsp;<span class="results">' + sCount + '</span>&nbsp;&nbsp;&nbsp;</u>';
	resultSection += 'I<u>&nbsp;&nbsp;&nbsp;<span class="results">' + iCount + '</span>&nbsp;&nbsp;&nbsp;</u>';
	resultSection += 'B<u>&nbsp;&nbsp;&nbsp;<span class="results">' + bCount + '</span>&nbsp;&nbsp;&nbsp;</u></p>';
}

function fncReload(){
  window.location.assign("quiz.htm");
}