var Current = new Array(20)
var flag = false
var cnt = 0
var total = 0
var scr = 0

CheckSelection()

function CheckSelection()
  {  	
    for (Count=0;Count<20;Count++)
    {
      Found=false
      var rndValue = get_random()
      var j=0
      for (j=0;j<Current.length;j++)
      {
	    if (Current[j] == rndValue)
        {
          Found=true
          break
        }
      }
      if (Found)
      {
        Count--
      } else {
        Current[Count]=rndValue
      }
    }
  }
  
  function get_random()
  {
    var ranNum = Math.floor((61)*Math.random()) + 40;
	return ranNum
  }
  
total = 0
scr = 0 
function showNext()
{
	document.worksheet.total.value = total
	document.worksheet.score.value = scr
	if(total == 20)
	{
		showResult()
		document.worksheet.amyanswer.readOnly = true
		flag = true
	}
	if((cnt < Current.length) && (total < 20))
	{
		document.worksheet.amyanswer.value = "";
		document.worksheet.ans.value = "";
		document.worksheet.sol.value = "";
		document.worksheet.nxt.value = "";
		document.worksheet.anumone.value = Aplh1(Current[cnt])
		cnt++
		total = total + 1
		document.worksheet.total.value = total
		document.worksheet.amyanswer.readOnly = false
		flag = false
		document.worksheet.amyanswer.focus()
	}
}

function checkanswer()
{
	var realanswer
	var youranswer
	
	if(flag == false)
	{
		onenum = document.worksheet.anumone.value
		realanswer = Current[cnt - 1]
		youranswer = document.worksheet.amyanswer.value

		if((youranswer == realanswer) && (youranswer != ""))
		{
			scr = Number(scr) + 1;
			document.worksheet.score.value = scr
			document.worksheet.sol.style.color = "#C9E6FF"
			document.worksheet.sol.value = "Correct Answer !"
		}
		else
		{
			document.worksheet.sol.style.color = "D0FDD0"
			document.worksheet.sol.value = "Oops, Incorrect Answer !"
			showanswer()
		}
		document.worksheet.nxt.value = "Click Next To Proceed Further";
	  	document.worksheet.amyanswer.readOnly = true
		flag = true
	}
}

function showanswer()
{
	var realanswer
	var onenum
	if(flag == false)
	{
		onenum = document.worksheet.anumone.value
		realanswer = Current[cnt - 1]
		document.worksheet.ans.value = "The Correct Answer Is " + realanswer
		document.worksheet.nxt.value = "Click Next To Proceed Further";
		document.worksheet.amyanswer.readOnly = true
		flag = true
	}
}

function showResult()
{
	var result = 100 * (scr / total)
	document.worksheet.ans.value = ""
	document.worksheet.nxt.value = ""
	document.worksheet.sol.value = ""
	document.worksheet.sol.style.color = "#E0FCB0"
	document.worksheet.sol.value = "Yo !! Home work completed"
	if(result >= 36)
	{
		document.getElementById('img1').innerHTML = '<img src="../../images/great.gif" border="0" width="115" height="83">'
		document.worksheet.ans.style.color = "#FFD78B"
		document.worksheet.ans.value = "You were awesome, great job!"
	}
	else
	{
		document.getElementById('img1').innerHTML = '<img src="../../images/good.gif" border="0" width="115" height="83">'
		document.worksheet.ans.style.color = "#FFD78B"
		document.worksheet.ans.value = "You can do much better !"
	}
}

function Aplh1(i){
var rom = "";
var num = i;

/*while (num - 100000 >= 0){
rom += "c";
num -= 100000;
}
while (num - 90000 >= 0){
rom += "xc";
num -= 90000;
}
while (num - 50000 >= 0){
rom += "l";
num -= 50000;
}
while (num - 40000 >= 0){
rom += "xl";
num -= 40000;
}
while (num - 10000 >= 0){
rom += "x";
num -= 10000;
}
while (num - 9000 >= 0){
rom += "Mx";
num -= 9000;
}
while (num - 5000 >= 0){
rom += "v";
num -= 5000;
}
while (num - 4000 >= 0){
rom += "Mv";
num -= 4000;
}
while (num - 1000 >= 0){
rom += "M";
num -= 1000;
}
while (num - 900 >= 0){
rom += "CM";
num -= 900;
}
while (num - 500 >= 0){
rom += "D";
num -= 500;
}
while (num - 400 >= 0){
rom += "CD";
num -= 400;
}*/
while (num - 100 >= 0){
rom += "C";
num -= 100;
}
while (num - 90 >= 0){
rom += "XC";
num -= 90;
}
while (num - 50 >= 0){
rom += "L";
num -= 50;
}
while (num - 40 >= 0){
rom += "XL";
num -= 40;
}
while (num - 10 >= 0){
rom += "X";
num -= 10;
}
while (num - 9 >= 0){
rom += "IX";
num -= 9;
}
while (num - 5 >= 0){
rom += "V";
num -= 5;
}
while (num - 4 >= 0){
rom += "IV";
num -= 4;
}
while (num - 1 >= 0){
rom += "I";
num -= 1;
}
return (rom);
}

function Caps(ctrl,e)
{
	key = e.keyCode
	if(ctrl.readOnly == false)
	{
		if((key >= 65) && (key <= 90))
		{
			var character = String.fromCharCode(e.keyCode);
			ctrl.value += character
		}
		/*else
		{
			ctrl.value = ""
		}*/
	}
}
