var timerID = null;
function stopClock()
{
  if (timerID) clearInterval(timerID);
  timerID = null;
}

function startClock()
{
  stopClock();
  showTime();
}

function endOfTime()
{
  elVal = document.question.submit();
  //document.location.href = elVal;
  return;
}

function showTime()
{
  var data;
  var disp="";
  var i;
  data = document.question.timeToGo.value;
  for(i=0;i<data.length;i++) if(data.substring(i,i+1)==":") break;
  mn = 1 * data.substring(0,i);
  sc = 0 + data.substring(i+1,data.length);
  sc--;
  if (sc <= 0)
  { mn--;
    if (mn >= 0) sc = 59;else mn = 0;
  }
  if ( (sc <= 0) && (mn <= 0) )
  {
      stopClock();
      document.question.timeToGoDisp.value = "00:00";
      endOfTime();
      return;
  }
  if (sc <= 0) {sc = 59;}
  if(mn <= 9) disp=" 0"; else disp=" ";
  disp+= mn + ":";
  if(sc<=9) disp+= "0" + sc; else disp+= sc;
  document.question.timeToGo.value = disp;
  document.question.timeToGoDisp.value = disp;
  timerID = setTimeout("showTime()", 1000);
}

function shImgFS()
{
	el1 = document.getElementById('img_fss');
	el2 = document.getElementById('img_fsi');
	el3 = document.getElementById('img_fsmn');
	stl = el1.style.display;
	st2 = el1.style.display;
	st3 = el1.style.display;
	if (stl == 'none') el1.style.display='';
	else el1.style.display = 'none';
	if (st2 == 'none') el2.style.display='';
	else el2.style.display = 'none';
	if (st3 == 'none') el3.style.display='';
	else el3.style.display = 'none';
}

function cImgOS() {
   var win_size_X = 0;
   if (window.innerWidth) {
      win_size_X = window.innerWidth;
   } else if (document.documentElement && document.documentElement.clientWidth) {
      win_size_X = document.documentElement.clientWidth;
   } else if (document.body && document.body.clientWidth) {
      win_size_X = document.body.clientWidth;
   }
	 win_size_X = win_size_X - 196;
   var optimal_w  = (win_size_X > img_w) ? img_w : win_size_X;
   var optimal_h = Math.round(optimal_w*img_h/img_w);
   var imgObj = document.getElementById("img_fsm");
   imgObj.style.width = optimal_w;
   imgObj.style.height = optimal_h;
}

function cImgFS() {
	var imgObj = document.getElementById("img_fsm");
	imgObj.style.width = img_w;
  imgObj.style.height = img_h;
}
