/* 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('Mire el diagrama otra vez.  Usted puede ver diversa cantidades de luz, usted puede ver diversas en el lado de la luna que hace frente a la tierra.',
		    'La Luna Llena occurre cuando vemos un círculo brillante entero.  A y C se aplica a la Luna Nueva',
		    'Cuando la luna está entre la tierra y el sol durante la Luna Nueva, no vemos el lado iluminado de la luna.',
		    'Durante la primero fase y tercero fase de la luna, la luna está en 90 grados en lo referente a la tierra y la mitad de la luna "brilla."',
		    'Mire en la simulación.  Usted verá que la luna está encerando a la derecha y está disminuyendo a la izquierda.',
		    'La luz del sol no cambia.  La luz en las marcas de la atmósfera hace la diferencia.',
		    'Recuerde la tierra está haciendo girar , entonces, la luna aparece igual no importa dónde usted está en la tierra.',
		    'La luna azul es la respuesta derecha.  El río de la luna es una canción, y Moonraker es una película.');

//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>Pregunta</b></TD><TD><b>Su respuesta </b></TD><TD><b>Respuesta correcta<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?
}

