/* File: seismic results.js
 * This script processes the questions about seismic waves 
 * from seismic/index.htm*/
 
//Functions
function setValue(num, value){
    q[num-1] = value; //questions start at #1
    return true;
}
function validate(){
    for(i=0; i < num_questions; i++){		
	if(q[i] == 0){
	    alert('You didn\'t answer all the questions, answer question '+(i+1));	    
	    document.location.hash = 'question'+(i+1); //Jump to the question
	    return false;
	}
    }
    /*if(document.QUESTIONS.q9.value == ""){
	alert('You didn\'t enter an answer for question 9');
	document.QUESTIONS.q9.focus();
	return false;
    }
    if(document.QUESTIONS.name.value == ""){
	alert('Enter your name.');
	document.QUESTIONS.name.focus();
	return false;
    }*/
    checkResults();
    return true;
}
function checkResults(){
    for(i=0; i < 6; i++){
	if(q[i] == ans[i])
	    check[i] = 1;				
    }
    var res_win = window.open('results.html', 'Results', 'resizable,menubar,scrollbars');
    res_win.document.open();   
    res_win.document.writeln('<html><head><title>Seismic Waves - Question Results</title></head><body>');
    res_win.document.write('<h4>Results for Seismic Waves Questions</h4><p>');
    res_win.document.write('<TABLE border=1><TR><TD>');
    res_win.document.write('<b>Question</b></TD><TD><b>Your answer</b></TD><TD><b>Correct Answer<b></TD></TR>');
    for(i=0; i < 6; i++){
		res_win.document.write('<TR ALIGN=CENTER><TD>('+(i+1)+')</TD><TD>'+q[i]+'</TD>');
		if(!check[i])
	    	res_win.document.write('<TD>'+ans[i]+'</TD><TD align=left>'+msg[i]+'</TD></TR>');
		else
	    	res_win.document.write('<TD>-ok-</TD></TR>');
    }
    /*res_win.document.write('<TR><TD align="center">(9)<TD colspan=3><em>Is there a correlation between moonrise'+
			   ' and high tide?</em></TD></TR><TD></TD><TD colspan=3>&nbsp;&nbsp;&nbsp;&nbsp;'+
			   document.QUESTIONS.q9.value+'</TD></TR>');*/
    res_win.document.write('</TABLE></body></html>');
    res_win.document.close();
    document.QUESTIONS.submit_b.disabled = true; //Don't want them changing their answers and resubmitting?
}

//Vars
var num_questions = 6;
var q = new Array(0,0,0,0,0,0);
var check = new Array(0,0,0,0,0,0);
var ans = new Array('A','A','A','B','B','B');
var msg = new Array('Dots that move further apart are expanding, not compressing.',
		    'Sound waves compress air molecules.  Light waves don\'t.',
		    'Revisit the Mighty Wave Maker if you need to.  With P waves you make the dots move left and right.  The direction of travel is right, so it is NOT at a 90 degree angle.',
		    'Revisit the Mighty Wave Maker.  Make the dots move up and down.  The direction of wave travel is to the right.  What do you see - distortion of the rectanglar shape or large changes in distance like you did when making P waves?',
		    'The movement is at 90 degree angles.',
		    'When you are hiking, do you have more energy when you start the hike?  When are you the fastest at climbing, at the beginning or end of the hike?  Your speed definitely does not stay constant.  Wave speed does not stay constant either.  Without replenishing energy, and with humans that means food and water, energy and speed reduces.  Waves are  no different.');
