<!--
var tm_id = 0;
var tm_s  = null;
var tm_tm = 0;



function updateTm() {
   if(tm_id) {
      clearTimeout(tm_id);
   }

   if(!tm_s)
      tm_s   = new Date();

   var   tDate = new Date();
   var   tDiff = tDate.getTime() - tm_s.getTime();

   tDate.setTime(tDiff);
   var tSecs = tDate.getMinutes() * 60 + tDate.getSeconds();
   showTime(tSecs);
   var fmtsecs = tDate.getSeconds();
   if (fmtsecs < 10) fmtsecs = "0" + fmtsecs;
   tm_tm = tDate.getMinutes() + ":" + fmtsecs;
   if (tSecs >= 120)
   {
       stopTm();
       alert("Sorry! You are timed out");
       submitfrm();
   }

   tm_id = setTimeout("updateTm()", 1000);
}

function startTm() {
   tm_s = null;

   showTime(0);
   tm_s   = new Date();
   tm_id  = setTimeout("updateTm()", 1000);
}

function stopTm() {
   if(tm_id) {
      clearTimeout(tm_id);
      tm_id  = 0;
   }

   tm_s = null;
}

function showTime(secs)
{
   var obj = document.getElementById("tmmm");
   obj.innerHTML = '<div style="height:10px; width:' + secs/120*100 + '%; font-size:1px; background-color:#ff0000"></div>';
}

function showScore(scr)
{
   var obj = document.getElementById("tdscr");
   obj.innerHTML = '<div style="height:10px; width:' + scr/27*100 + '%; font-size:1px; background-color:#00ff00"></div>';
}


function showQ(n)
{
   var obj = document.getElementById("nmrtr");
   if (obj != null)
       obj.innerHTML = narr[n];
   obj = document.getElementById("dnmrtr");
       obj.innerHTML = darr[n];
}

function submitfrm()
{
      f = document.getElementById("stuscr");
      o = f.appendChild(document.createElement('div'));
      o.innerHTML="<input type=hidden name=score value=" + score + ">";
      o = f.appendChild(document.createElement('div'));
      o.innerHTML="<input type=hidden name=name value=\"" + window.parent.document.getElementById("nmplc").innerHTML + "\">";
      o = f.appendChild(document.createElement('div'));
      o.innerHTML="<input type=hidden name=stutm value=" + tm_tm + ">";
      document.dvsblfrm.submit();
}

function chkAns(ans)
{
   if (ans == aarr[qnum])
       score++;
   else
   {
       stopTm();
       astr = " is divisible by ";
       if (aarr[qnum] == "N")
           astr = " is NOT divisible by ";
       alert("Sorry! The number " + narr[qnum] + astr + darr[qnum]);
       submitfrm();
       return;
   }
   showScore(score);
   qnum++;
   if (qnum >= maxnum)
   {
       stopTm();
       submitfrm();
       return;
   }
   
   showQ(qnum);
}

function IsAlphaNum(str) {
  $cstr = new String(str);
  return $cstr.match(/^[a-zA-Z0-9 ]+$/);
}


function setName()
{
  var nm;
  nm = document.dvsblfrm.sname.value;
  if (nm.length > 0)
  {
    if (IsAlphaNum(nm) == null)
    {
      alert("Name should contain only Alpha Numeric characters");
      document.dvsblfrm.sname.focus();
      return false;
    }
    var nm2;
    nm2 = window.parent.document.getElementById("nmplc");
    if (nm2 != null) {nm2.innerHTML=nm;}
  }
  
  return true;
}

function getName()
{        
    var nm2 = window.parent.document.getElementById("nmplc");
    if (nm2 != null) {
      if (nm2.innerHTML != "Name") {
        document.dvsblfrm.sname.value = nm2.innerHTML;
      }
    }
    document.dvsblfrm.sname.focus();
}


//-->
