/* random quiz script
*/

var question = new Array(2);
var ans1 = new Array(2);
var ans2 = new Array(2);
var ans3 = new Array(2);
var ans4 = new Array(2);
var correct = new Array(2);

question[0]="As of Januray 2009, how many different variations of Ipods are there?";
ans1[0]=" Three";
ans2[0]=" Four";
ans3[0]=" Five";
ans4[0]=" Six";
correct[0]=3;

question[1]="As of Januray 2009, how many generations of Ipod Classic are there?";
ans1[1]=" Two";
ans2[1]=" Four";
ans3[1]=" Six";
ans4[1]=" Eight";
correct[1]=3;

question[2]="Where is the most common place to lose a mobile device?";
ans1[2]=" Taxis";
ans2[2]=" Bars";
ans3[2]=" Airport";
ans4[2]=" Toilets";
correct[2]=1;

question[3]="In which country does the number of mobile phones owned outnumber the population?";
ans1[3]=" United States";
ans2[3]=" Luxemburg";
ans3[3]=" Switzerland";
ans4[3]=" London";
correct[3]=2;

question[4]="How many computer viruses are released every month?";
ans1[4]=" 60";
ans2[4]=" 666";
ans3[4]=" 6,000";
ans4[4]=" 6,666";
correct[4]=3;

question[5]="What number should you call if you find yourself out of coverage area and there is an emergency?";
ans1[5]=" 111";
ans2[5]=" 112";
ans3[5]=" 113";
ans4[5]=" 114";
correct[5]=2;

question[6]="Where is the second most common place to lose a mobile device?";
ans1[6]=" Taxis";
ans2[6]=" Bars";
ans3[6]=" AIrports";
ans4[6]=" Toilets";
correct[6]=2;

question[7]="what does the acronym 'PMP' stand for?";
ans1[7]=" Portable Music Player";
ans2[7]=" Pathetic Mini Player";
ans3[7]=" Portable Mini Player";
ans4[7]=" Portable Media Player";
correct[7]=4;

question[8]="The Guinness record holder for 'Fastest Text Message while Skydiving' is a";
ans1[8]=" European";
ans2[8]=" American";
ans3[8]=" Vietnamnese";
ans4[8]=" Singaporean";
correct[8]=4;

question[9]="In the Guinnes Book of World Records 2008, the world's lightest mobile phone belongs to:";
ans1[9]=" Modu mini phone";
ans2[9]=" Apple mini phone";
ans3[9]=" Blackberry mini phone";
ans4[9]=" Samsung mini phone";
correct[9]=1;

question[10]="The first commercially avialable portable computer which debuted in 1981 was called the:";
ans1[10]=" Roland 1";
ans2[10]=" Osborne 1";
ans3[10]=" Dynabook";
ans4[10]=" Renabook";
correct[10]=2;

question[11]="The first mobile computer which looked like a modern laptop and debuted in 1982 was called the:";
ans1[11]=" GRiD Book";
ans2[11]=" GRiD Shell";
ans3[11]=" GRiD Compass";
ans4[11]=" GRiD Laptop";
correct[11]=3;

question[12]="What does the DS in Nintendo DS stand for?";
ans1[12]=" Developers' Screen";
ans2[12]=" Developers' System";
ans3[12]=" Dual System";
ans4[12]=" Dual Security";
correct[12]=2;

question[13]="How much does a Nintendo DS Lite weigh?";
ans1[13]=" 100 to 150 grams";
ans2[13]=" 150 to 200 grams";
ans3[13]=" 200 t0 250 grams";
ans4[13]=" 250 to 300 grams";
correct[13]=3;

question[14]="How many official colours of NDS are there?";
ans1[14]=" 3";
ans2[14]=" 5";
ans3[14]=" 7";
ans4[14]=" 9";
correct[14]=4;

question[15]="How many official colours of PSP are there?";
ans1[15]=" 9";
ans2[15]=" 8";
ans3[15]=" 10";
ans4[15]=" 11";
correct[15]=3;

question[16]="How much does a PSP weigh?";
ans1[16]=" 100 to 150 grams";
ans2[16]=" 150 to 200 grams";
ans3[16]=" 200 t0 250 grams";
ans4[16]=" 250 to 300 grams";
correct[16]=4;

question[17]="Who designed the PSP?";
ans1[17]=" Osaka Matsuhido";
ans2[17]=" Shi Ogasawara";
ans3[17]=" Lee Yamato";
ans4[17]=" Utada Koshibura";
correct[17]=2;


var testIndex, val;

function checkAnswer()
{
	if (val == correct[testIndex])
		alert("Yes! You got the right answer :D");
	else
		alert("Sorry, try again?");
}

function setVal(num)
{
	val = num;
	checkAnswer();
}

function testYourself()
{	
	if (document.getElementById('trivia') && document.createTextNode && document.createElement) {
	testIndex = Math.floor(Math.random() * question.length);
	val = 1;
	
	var container = document.getElementById('trivia');
	while (container.firstChild)
		container.removeChild(container.firstChild);
	var curQn = document.createTextNode(question[testIndex]);
	
	container.appendChild(curQn);
	container.appendChild(document.createElement('br'));
	container.appendChild(document.createElement('br'));
	
	var radiobutton = new Array(4);
	radiobutton[0] = document.createElement('img');
	radiobutton[1] = document.createElement('img');
	radiobutton[2] = document.createElement('img');
	radiobutton[3] = document.createElement('img');
	for (var i=0; i<4; i++)
	{
		radiobutton[i].setAttribute('src', 'images/radiobutton.png');
		radiobutton[i].setAttribute('class', 'smallIcon'); //Firefox
		radiobutton[i].setAttribute('className', 'smallIcon'); //IE
		radiobutton[i].style.display = "inline";
		container.appendChild(radiobutton[i]);
		
		var answer;
		if (i == 0) 
			answer = document.createTextNode(ans1[testIndex]);			
		else if (i == 1)
			answer = document.createTextNode(ans2[testIndex]);
		else if (i == 2)
			answer = document.createTextNode(ans3[testIndex]);
		else
			answer = document.createTextNode(ans4[testIndex]);
		container.appendChild(answer);
		container.appendChild(document.createElement("br"));
		
	}
	container.appendChild(document.createElement("br"));
	
	if (radiobutton[0].addEventListener)
	{
		radiobutton[0].addEventListener("click", function(e){setVal(1);}, false);
		radiobutton[1].addEventListener("click", function(e){setVal(2);}, false);
		radiobutton[2].addEventListener("click", function(e){setVal(3);}, false);
		radiobutton[3].addEventListener("click", function(e){setVal(4);}, false);
	}
	else if (radiobutton[0].attachEvent)
	{
		radiobutton[0].attachEvent('onclick', function(e){setVal(1);});
		radiobutton[1].attachEvent('onclick', function(e){setVal(2);});
		radiobutton[2].attachEvent('onclick', function(e){setVal(3);});
		radiobutton[3].attachEvent('onclick', function(e){setVal(4);});
	}
	}
}

if (window.addEventListener) {
	window.addEventListener('load', testYourself, false);
}
else {
	window.attachEvent('onload', testYourself);
}
