// Default choices for questions
var questions = Array(0,0);

// DOM IDs of buttons
var buttons = Array(
    Array('no1','yes1'),
    Array('no2','yes2')
);

// Filenames of images
var imageDir = "images/";
var images = Array(
    Array('btn_no.jpg','btn_no_on.jpg'),
    Array('btn_yes.jpg','btn_yes_on.jpg')
); 

// Quiz logic
function updateQuiz(question_id,value) {
    // question_id: array key of the question
    // value: 1 = yes, -1 = no

    // Reset buttons for the question - let people change their mind
    if(questions[question_id] != 0) {
        changeButton(document.getElementById(buttons[question_id][0]), images[0], -1);
        changeButton(document.getElementById(buttons[question_id][1]), images[1], -1);
    }
    // Set the question variable
    questions[question_id] = value;
    // Set the button
    btn = (value == -1) ? 0 : 1;
    changeButton(document.getElementById(buttons[question_id][btn]), images[btn], 1); 
    
    // Make sure all questions answered
    if(questions[0] != 0 && questions[1] != 0) 
    {
        if(questions[0] == 1 && questions[1] == 1) {
            window.location = "continue.html";
        } else {
            window.location = "other.html";
        }
    } 
} 

// Change button state
function changeButton(obj,button,state) {
    // obj: DOM object
    // button: image filename
    // state: 1 = on, -1 = off

    if(state == 1) {
        obj.src = imageDir + button[1];
    } else {
        obj.src = imageDir + button[0];
    }
    return;
}
