﻿// JScript File

function Question(id,text,units,step,minimum,maximum,correct)
{
    this.Id = id;
    this.Text = text;
    this.Units = units;
    this.Step = step;
    this.Minimum = minimum;
    this.Maximum = maximum;
    this.Correct = correct;
}

function BuildIt(passedArray)
{
    var tmpQuest = new Question(1,"In 2006, how many roubles were worth 10 pounds sterling?","Roubles",50,100,1000,500);
    passedArray[0] = tmpQuest;
    var tmpQuest = new Question(2,"In 2001, how much were 1,440 US dollars worth in sterling?","Sterling",50,500,1500,1000);
    passedArray[1] = tmpQuest;
    var tmpQuest = new Question(3,"What were 725 Swedish krona worth in sterling in 2006?","Sterling",0.50,30,70,54.50);
    passedArray[2] = tmpQuest;
    var tmpQuest = new Question(4,"How much stronger was sterling in 2006 than in 2001 in relation to the Japanese yen?","%",1,20,60,33);
    passedArray[3] = tmpQuest;
    var tmpQuest = new Question(5,"How much stronger or weaker was the US dollar in 2006 than in 2001, compared with the Hong Kong dollar?","%",1,-25,25,-6);
    passedArray[4] = tmpQuest;
    var tmpQuest = new Question(6,"If I had exchanged 1,000 euros into roubles in 2001, and exchanged them back into euros in 2006, how much would I have lost?","Euros",5,150,350,235);
    passedArray[5] = tmpQuest;
}

function SetQuestion(questions)
{
    document.getElementById('lblActiveQuestion').innerHTML = "Question " + (CurrentItem + 1) + ":";
    document.getElementById('lblQuestionText').innerHTML = questions[CurrentItem].Text;
    document.getElementById('lblUnits').innerHTML = questions[CurrentItem].Units;
    var dropDown = document.Numericform.ddlPrimary;
    
    for(var i=dropDown.options.length-1;i>=0;i--)
    {
     dropDown.remove(i);
    }
    dropDown.options[dropDown.options.length]=new Option();  
 
    var startVal = questions[CurrentItem].Minimum;
    var endVal = questions[CurrentItem].Maximum;
    var step = questions[CurrentItem].Step;
    for (var i = startVal;i<=endVal;i=i+step)
    {
        dropDown.options[dropDown.options.length]=new Option(i,i);  
    }
    return;
}

function SetSelectedAdaptiveValue()
{
	var lbl = document.getElementById('lblAnswer');
	var ddl = document.getElementById('ddlPrimary');
	var un1 = document.getElementById('lblUnits');
    
    var un1Txt = "";
    var prt1 = ddl.value;
	if (un1 != null && ddl.selectedIndex > 0)
	{
	    un1Txt = " " + un1.innerText + " ";
	}

//    var btnCont = document.getElementById('btnContinue');
//    btnCont.value = "Accept and move on" + String.fromCharCode(10) + String.fromCharCode(13) +"to the next question";
//    btnCont.style.backgroundColor = "#0066cc";
//    btnCont.style.fontWeight = "normal";
    lbl.innerHTML = prt1 + un1Txt;
    return true;
}

function MoveOn(questions)
{
    CurrentItem++;
    if (CurrentItem < 6)
    {
        document.getElementById('lblAnswer').innerHTML = "";
        SetQuestion(questions);
//        var btnCont = document.getElementById('btnContinue');
//        btnCont.value = "Accept and move on" + String.fromCharCode(10) + String.fromCharCode(13) +"to the next question";
    }
    else
    {
        document.getElementById('answerTable').style.visibility = "hidden";
        document.getElementById('answerTable').style.display = "none";
        document.getElementById('infoSpan').innerHTML = outText;
        document.getElementById('btnRetry').style.visibility = "visible";
            
    }

}

function DisplayCorrect(questions)
{
    if (document.getElementById('infoSpan').innerHTML == "")
    {
	    var ddlSelected = document.getElementById('ddlPrimary').value;
        var correct = questions[CurrentItem].Correct;
        var units = questions[CurrentItem].Units;
        
        outText +="<B>Question " + (CurrentItem + 1) + ": " + questions[CurrentItem].Text + "</b><br/>";
        if ( ddlSelected == correct)
        {
            outText+= "Correct! The answer is " + correct + " " + units + "<br/><br/>"
        }
        else
        {
            outText+= "Sorry! The correct answer is " + correct + " " + units + "<br/><br/>";
        }
        MoveOn(questions);
        
//        document.getElementById('infoSpan').innerHTML = outText;
//        var btnCont = document.getElementById('btnContinue');
//        btnCont.value = "Continue" + String.fromCharCode(10) + String.fromCharCode(13) +"to the next question";

    }
    else
    {
        MoveOn(questions)
    }
}