/* File: lunar results.js
 * This script processes the questions about the lunar phases 
 * from lunar_phase_REAL.html*/
var num_questions = 8;
var q = new Array(0,0,0,0,0,0,0,0);
var check = new Array(0,0,0,0,0,0,0,0);
var ans = new Array('B','B','D','C','A','B','B','B');
var msg = new Array('Look at the diagram, you can see different amounts of light on the side of the moon facing the earth.',
		    'Full moon is when we see a whole bright circle, A and C apply to the new moon',
		    'The moon is between the earth and sun during new moon, so we don\'t see the light side of the moon.',
		    'During 3rd and 1st quarter phases the moon is at 90 degrees  and half of the moon "shines."',
		    'Look at the simulation and you will see that the moon is waxing on the right and waning on the left.',
		    'The amount of light from the sun doesn\'t change, the light in the atmosphere makes the difference.',
		    'Remember the earth is spinning so, the moon will look the same from anywhere on earth.',
		    'Blue moon is the right answer, Moon River is a song, and Moonraker is a movie.');

//var flash1=null, flash2=null, flash3=null;

// This goes in the BODY tag of each movie html file: 
//  onUnload="if(opener) opener.closeWin(1);"
/*
function openFlash(num){
    if(num == 1){
	if(!flash1)
	    flash1 = window.open('lunar_phase1_real.html','win1', 'height=480, width=640, resizable');
	else {
	    flash1.focus();
	}
    }
    else if(num == 2){
	if(!flash2)
	    flash2 = window.open('lunar_phase2_real.html','win2', 'height=480, width=640, resizable');
	else
	    flash2.focus();
    }
    else if(num == 3){
	if(!flash3)
	    flash3 = window.open('lunar_phase3_real.html','win3', 'height=480, width=640, resizable');
	else
	    flash3.focus();
    }
}
*/
/*
function closeWin(num){
    if(num == 1){
	if(flash1){
	    //	    alert("Closing window "+num);
	    flash1.close();
	    flash1 = null;
	}
    }
    if(num == 2){
	if(flash2){
	    //	    alert("Closing window "+num);
	    flash2.close();
	    flash2 = null;
	}
    }
    if(num == 3){
	if(flash3){
	    //	    alert("Closing window "+num);
	    flash3.close();
	    flash3 = null;
	}
    }
}
*/
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<8; 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>Lunar Phases - Question Results</title></head><body>');
    res_win.document.write('<h4>Name: '+ document.QUESTIONS.name.value + 
			   '</h4>Results for Lunar Phase Questions<br>');
    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<8; 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?
}
