var W=window, D=document, F, E, EvSrc, Gec, Op, Ns, Saf, IE7, Nav, B, Score, popupWin;
//------------

var aQ1Ans=[
	'Very dissatisfied', 'Rather dissatisfied', 'Mixed, about equally satisfied and dissatisfied',
	'Rather satisfied', 'Very satisfied'];

function getbyid(id){return D.getElementById(id);}

function clearScores(){ 
var i;
for(i=1; i<=6; i++) getbyid("ans"+i).style.display='none';
} 


var strScores = new String('');

function getScore(numQues){
	strScores = ''; 
	finalScore = 0; 
	//track to make sure all questions are filled out 
	questionTrack = 0;
	
	//need to loop through all the questions to process their score 
	for(var i=1; i <= numQues; i++){ 
		//then loop through all the choices in each question 
		var whichQues = "ques"+i; 
		for(var j=0; j < document.rForm[whichQues].length; j++){ 
			//now see which choice is selected 
			if(document.rForm[whichQues][j].checked){ 
				if (i >1) {
					finalScore += Number(document.rForm[whichQues][j].value); 
					strScores = strScores + document.rForm[whichQues][j].value;
				} // if condition is added to filter out the first question from being evaluted.
				else {
					//just pre-pend first question value
					strScores = document.rForm[whichQues][j].value-1 + strScores;
				}
				questionTrack +=1; 
			} 
		} 
	} 
	if(questionTrack < 6){ alert ("Please fill out all questions to receive your score."); 
	}
	else{ 
		showPrintableQuiz();
	} 
} 

function showPrintableQuiz() {

popupWin = window.open("ed_quiz_results.html?score=" + strScores ,"ed_quiz_results","status=1,height=590,width=600,scrollbars=1,resizable=yes,toolbar=0")
setTimeout('popupWin.focus()', 100);
}

function OC(e){

EventInit(e);
if (EvSrc.tagName!='INPUT') return;
if (EvSrc.type!='radio') return;

var No, Span, Value;

No=EvSrc.name.substr(4);
if (!(Span=getbyid('ans'+No))) return;
if (No!='1') Value=EvSrc.value;
else Value=aQ1Ans[EvSrc.value-1];

Span.style.display='inline';
SetText(Span, ' = '+Value);
}

function ShowScore(){
var Pos;

Score=W.location.search;
if ((Pos=Score.indexOf('score='))==-1) Score='0';
else{
	Score=Score.substr(Pos+6+1); //+1 skips answer 1 which is not needed
	Score=Score.replace(/([0-9])/g, '$1+')+'0';
	Score=eval(Score);
	}

D.write(Score);
}

function HilightScoreTbl(){
var oTbl=getbyid('ScoreTbl'), aScores=[10, 15, 20, 25], RowNo;

for(RowNo=0; RowNo<aScores.length; RowNo++){
	if (Score<=aScores[RowNo]) break;
	}
oTbl.rows[RowNo+1].className='Hilite';
}

function EventInit(e){
E=(!Gec ? event : e); EvSrc=E[Gec ? 'target' : 'srcElement'];
if (Ns && EvSrc.nodeType==3) EvSrc=EvSrc.parentNode;
}

function InitUA(){

Nav=W.navigator.userAgent; IE7=false; 
Gec=(Nav.indexOf('Gecko')!=-1); Op=(Nav.indexOf('Opera')!=-1);
Ns=(Gec && Nav.indexOf('Netscape')!=-1); Saf=(Gec && Nav.indexOf('Safari/')!=-1);

if (!Gec && !Op){
	Nav.match(/ MSIE (\d+)/);
	if (RegExp.$1>=7) IE7=true;
	}
}

function SetText(o, Txt){o.firstChild.data=Txt;}

//---

InitUA();
D.onclick=OC;

