﻿// JScript File

function Question(id,text,correct,correct2)
{
    this.Id = id;
    this.Text = text;
    this.Options = new Array(6);
    this.Correct1 = correct;
    this.Correct2 = correct2;
}

function BuildIt(passedArray)
{
    var tmpQuest = new Question(1,"Which <b>one</b> of the following is stated to have been a result of adopting equal opportunities policies?",4,0);
    tmpQuest.Options[0] = "Increase in sales turnover";
    tmpQuest.Options[1] = "A drop in the number of employee tribunal cases";
    tmpQuest.Options[2] = "Greater public demand for the company's services";
    tmpQuest.Options[3] = "Higher profits";
    tmpQuest.Options[4] = "More applicants for advertised job vacancies";
    tmpQuest.Options[5] = "Better awareness of employment law";
    passedArray[0] = tmpQuest;

    var tmpQuest = new Question(2,"Which <b>one</b> of the following <b>cannot</b> be concluded from the passage?",2,0);
    tmpQuest.Options[0] = "Organisations have a responsibility to keep their employees aware of the law regarding discrimination";
    tmpQuest.Options[1] = "Generally speaking, companies are indifferent to issues regarding equal opportunity in the workplace";
    tmpQuest.Options[2] = "Inappropriate action by employees can have legal and financial implications for a company";
    tmpQuest.Options[3] = "Implementation of equal opportunity policies can be advantageous for an employer";
    tmpQuest.Options[4] = "Awareness of relevant legislation can reduce an organisation's exposure to claims of discrimination";
    tmpQuest.Options[5] = "Employment tribunals are entitled to make companies pay damages for breaches of equal opportunity laws";
    passedArray[1] = tmpQuest;

    var tmpQuest = new Question(3,"Which <b>one</b> one of these means the same as the word ”stipulated” as found in the second paragraph?",5,0);
    tmpQuest.Options[0] = "Maximum";
    tmpQuest.Options[1] = "Average";
    tmpQuest.Options[2] = "Usual";
    tmpQuest.Options[3] = "Legitimate";
    tmpQuest.Options[4] = "Defined";
    tmpQuest.Options[5] = "Requested";
    passedArray[2] = tmpQuest;

    var tmpQuest = new Question(4,"Which <b>two</b> of the following are <b>not</b> necessarily implied by the above passage?",2,5);
    tmpQuest.Options[0] = "Employee motivation may be enhanced by the introduction of equal opportunity policies";
    tmpQuest.Options[1] = "The number of discrimination cases before tribunals has decreased during recent years";
    tmpQuest.Options[2] = "Employment tribunals are the appropriate instance before which discrimination cases are heard";
    tmpQuest.Options[3] = "Judgements against a company found guilty of discrimination can be substantial";
    tmpQuest.Options[4] = "Employees can be held directly responsible for any discriminatory actions that they are guilty of";
    tmpQuest.Options[5] = "Awareness of equal opportunity legislation is an important step towards reducing discrimination";
    passedArray[3] = tmpQuest;
}

function rollon(obj)
{
    var backcolor = '#cccccc';
    var textcolor = 'black';
     obj.style.backgroundColor = backcolor;
     obj.style.color = textcolor;
}

function rolloff(obj, idValue)
{
	var ans = document.getElementById('hdnAnswer1');
	var ans2 = document.getElementById('hdnAnswer2');
    var backcolor = 'white';
    var color = 'black';
    if (idValue == ans.value || idValue == ans2.value)
    {
        backcolor = '#0087d8';
        color = 'white';
    }
     obj.style.backgroundColor = backcolor;
     obj.style.color = color;
}

function SetQuestion(questions)
{
    document.getElementById('lblActiveQuestion').innerHTML = "Question " + (CurrentItem + 1) + ":";
    document.getElementById('lblQuestionText').innerHTML = questions[CurrentItem].Text;
    document.getElementById('lblOption1').innerHTML = questions[CurrentItem].Options[0];
    document.getElementById('lblOption2').innerHTML = questions[CurrentItem].Options[1];
    document.getElementById('lblOption3').innerHTML = questions[CurrentItem].Options[2];
    document.getElementById('lblOption4').innerHTML = questions[CurrentItem].Options[3];
    document.getElementById('lblOption5').innerHTML = questions[CurrentItem].Options[4];
    document.getElementById('lblOption6').innerHTML = questions[CurrentItem].Options[5];
    document.getElementById('hdnAnswer1').value = 0;
    document.getElementById('hdnAnswer2').value = 0;
}

function SetVerbalValue(passValue)
{
	var ans = document.getElementById('hdnAnswer1');
	var ans2 = document.getElementById('hdnAnswer2');
    var twoVals = (ItemArray[CurrentItem].Correct2 > 0);
    var empty1 =  (ans.value == 0);
    var empty2 =  (ans2.value == 0);
    var setValue = true;
    if (ans.value == passValue)
    {
        ans.value = '0';
        setit(passValue,0);
        setValue = false;
    }
    if (ans2.value == passValue)
    {
        ans2.value = '0';
        setit(passValue,0);
        setValue = false;
    }
    if (setValue)
    {
        if (twoVals)
        {
            if (empty1)
            {
                ans.value = passValue;
            }
            else
            {
                if (empty2)
                {
                    ans2.value = passValue;
                }
                else
                {
                    setit(ans.value,0);
                    setit(ans2.value,0);
                    ans2.value = '0';
                    ans.value = passValue;
                }
            }
            setit(passValue,1);
        }
        else
        {
            setit(ans.value,0);
            ans.value = passValue;
            setit(passValue,1);
        }
    }
}

function setit(blankPass, action)
{
    var backcolor = 'white';
    var color = 'black';
    if (action == 1)
    {
        backcolor = '#0087d8';
        color = 'white';
    }
    if (blankPass != '0')
    {
    	document.getElementById('tdOption' + blankPass).style.backgroundColor = backcolor;
    	document.getElementById('tdOption' + blankPass).style.color = color;
    }
  
}


function MoveOn(questions)
{
    CurrentItem++;
    if (CurrentItem < 4)
    {
        SetQuestion(questions);
        CancelVerbalValue();
    }
    else
    {
        document.getElementById('questBlock').style.visibility="hidden";
        document.getElementById('questBlock').style.display="none";
        document.getElementById('infoSpan').innerHTML = outText;
        document.getElementById('btnCancel').style.visibility="hidden";
        var btnCont = document.getElementById('btnContinue');
        btnCont.style.visibility="hidden";
        document.getElementById('btnRetry').style.visibility="visible";
    }
}

function DisplayCorrect(questions)
{
        var correct1 = questions[CurrentItem].Correct1;
        var correct2 = questions[CurrentItem].Correct2;
	    var ans1 = document.getElementById('hdnAnswer1').value;
	    var ans2 = document.getElementById('hdnAnswer2').value;
        
        outText +="<B>Question " + (CurrentItem + 1) + ": " + questions[CurrentItem].Text + "</b><br/>";
        if ( (ans1 == correct1 && ans2 == correct2) || (ans2 == correct1 && ans1 == correct2))
        {
            outText += "Correct! The answer";
        }
        else
        {
            outText += "Sorry! The correct answer";
        }
        if (correct2 > 0)
        {
            outText += "s are:<br/>";
        }
        else
        {
              outText += " is:<br/>";
        }
        outText += questions[CurrentItem].Options[correct1 - 1];
        if (correct2 > 0)
        {
            outText += "<br/>" + questions[CurrentItem].Options[correct2 - 1];
        }
        outText+= "<br/><br/>";
        MoveOn(questions)
}

function CancelVerbalValue()
{
	var ans = document.getElementById('hdnAnswer1');
	var ans2 = document.getElementById('hdnAnswer2');
	ans.value = '0';
	ans2.value = '0';
    setit('1',0);
    setit('2',0);
    setit('3',0);
    setit('4',0);
    setit('5',0);
    setit('6',0);
}

function checkKey(el) 
{
	if (event.keyCode==13)
	{
		el.click()
    }
}