﻿// vi:set ts=2 sw=2 ai ft=javascript ff=dos:
function CheckSelection(buttonid, boxlist)
{
  // Toggles through all of the checkboxes defined in the arrTopics array
  // and updates their value to the checkState input parameter
  var sb = document.getElementById(buttonid);
  if (sb != null)
    sb.disabled = true;
    
  var qb;
  if (boxlist != null)
  {
    for (var i = 0; i < boxlist.length; i++)
    {
      var qb = document.getElementById(boxlist[i]);
      if (qb.checked)
      {
        sb.disabled = false;
        break;
      }
    } 
  }
}

var seconds = 0;
var tf;

function startTimer( time )
{
  if (time != -1) {
    seconds = time;
    history.forward();
    display();
  }
}

function display(  )
{ 
  seconds -= 1 
  if (seconds <= -1)
  {
    seconds += 1 ;
    window.clearTimeout( tf );
    document.getElementById('dq1_btnSkip').click();
  } 
  else
  {
    if (seconds <= 60)
    {
      document.forms[0].txtTimer.value = seconds + " Sec. Remaining For This Question" ;
    }
    else
    {
      min = seconds / 60;
      document.forms[0].txtTimer.value = Math.floor(seconds / 60) + " Min. " +
          seconds % 60 + " Sec. Remaining For This Question";
    }
    tf = setTimeout("display()", 1000);
  } 
}

function CheckAnswer(boxlist)
{
  var qb;
  if (seconds == 0)
  {
    document.forms[0].blnTimedOut.value = 1;
    return true;
  }
  if (boxlist != null)
  {
    for (var i = 0; i < boxlist.length; i++)
    {
      var qb = document.getElementById(boxlist[i]);
      if (qb.checked)
      {
        if (tf != null)
          window.clearTimeout( tf );
        return true;
      }
    } 
  }
  var agree = confirm("Are you sure you want to skip the Question?\n" +
        "If you skip a Question, you will not be able to go " + 
        "back to it.\nTo skip the Question, click 'OK', " + 
				"otherwise click 'Cancel'");
  if (agree)
    return true;
  else
    return false;        
}
