<?cs include:"util.cs" ?>

<?cs def:print_quiz_title() ?>
  <h3><?cs var:quiz.title ?></h3>
<?cs /def ?>


<?cs def:print_sub_title() ?>
 <h4> 
  <?cs each:myline = quiz.sub_title.line ?>
    <?cs var:myline ?>
  <?cs /each ?>
 </h4>
<?cs /def ?>


<?cs def:print_instructions() ?>
<?cs if:quiz.instruction.line.0 ?>
<hr />
<div class="instructions" >
  <?cs each:myline = quiz.instruction.line ?>
    <?cs var:myline ?><br />
  <?cs /each ?>
</div>
<hr />
<?cs /if ?>
<?cs /def ?>



<?cs def:print_timer() ?>
<div class="center_msg">
  <div><form action="">
   <?cs var:lang.hotpot_exam_present.timer_label ?> <input type="text" name="timer" id="timer" size="8" value="" />
  </form></div> 
</div>
<?cs /def ?>





<?cs def:print_mc(data, number) ?>
<table width="100%"  border="5">
<tr class="table_bg">
   <td>
    <b><?cs var:lang.hotpot_exam_present.question ?><?cs var:number ?>.</b>
     <?cs each:a_line = data.body.line ?>
          <?cs var:a_line ?><br />
     <?cs /each ?>
   <table>
      <?cs each:answer = data.mc ?>
      <tr>
      <td>&nbsp;&nbsp;</td>
      <th align="left"><?cs var:answer.letter ?></td>
      <td><input type="radio" name="<?cs var:answer.name ?>" value="<?cs var:answer.value ?>" /></td>
      <td><?cs var:answer.answer ?></td>
      </tr>
      <?cs /each ?>
   </table>
  </td>
</tr>
</table>
<?cs /def ?>






<?cs def:print_mc_multi(data, number) ?>
<table width="100%"  border="5">
<tr class="table_bg">
   <td>
    <div><b><?cs var:lang.hotpot_exam_present.question ?><?cs var:number ?>.</b>
     <?cs set:line = #0 ?>
     <?cs each:body = data.body.line ?>
      <?cs if:line == #0 ?>
        <?cs var:body ?> 
      <?cs else ?>
        <div><?cs var:body ?></div>
      <?cs /if ?> 
     <?cs set:line = line + #1 ?>
     <?cs /each ?>
    </div><br />
   <table>
      <?cs each:answer = data.mcmulti ?>
      <tr>
      <td>&nbsp;&nbsp;</td>
      <th align="left"><?cs var:answer.letter ?></th>
      <td><input type="checkbox" name="<?cs var:answer.name ?>" value="<?cs var:answer.value ?>" /></td>
      <td><?cs var:answer.answer ?></td>
      </tr>
      <?cs /each ?>
   </table> 
  </td>
</tr>
</table>
<?cs /def ?>

<?cs def:print_short(data, number) ?>
<table width="100%"  border="5">
<tr class="table_bg">
   <td>
    <div><b><?cs var:lang.hotpot_exam_present.question ?><?cs var:number ?>.</b>
     <?cs set:line = #0 ?>
     <?cs each:body = data.body.line ?>
      <?cs if:line == #0 ?>
        <?cs var:body ?> 
      <?cs else ?>
        <div><?cs var:body ?></div>
      <?cs /if ?> 
     <?cs set:line = line + #1 ?>
     <?cs /each ?>
    </div><br />
   <table>
      <tr>
        <th>
        <?cs var:lang.hotpot_exam_present.youranswer_label ?>
        <input type="text" name="<?cs var:data.short[0].name ?>" />
        </th>
      </tr>
   </table> 
  </td>
</tr>
</table>
<?cs /def ?>



<?cs def:insert_javascripts() ?>
<script type="text/javascript">
var	timerID = null;
var	timerRunning = false;
var	startDate;
var	startSecs;

function stopclock()
{
	if(timerRunning)
		clearTimeout(timerID);
       timerRunning = false;
}


function startclock()
 {
	startDate = new Date();
	startSecs = (startDate.getHours()*60*60) + (startDate.getMinutes()*60) + startDate.getSeconds();
	stopclock();
	showtime();
 }


function showtime()
{
  var now = new Date();
  var nowSecs = (now.getHours()*60*60) + (now.getMinutes()*60) + now.getSeconds();
  var elapsedSecs = nowSecs - startSecs;

  var hours = Math.floor( elapsedSecs / 3600 );
  elapsedSecs = elapsedSecs - (hours*3600);

  var minutes = Math.floor( elapsedSecs / 60 );
  elapsedSecs = elapsedSecs - (minutes*60);

  var seconds = elapsedSecs;

  var timeValue = "" + hours;
  timeValue  += ((minutes < 10) ? ":0" : ":") + minutes;
  timeValue  += ((seconds < 10) ? ":0" : ":") + seconds;

  document.getElementById('timer').value = timeValue;
  timerID = setTimeout("showtime()",1000);
  timerRunning = true;
}

function verify()
{
   msg = "<?cs var:lang.hotpot_exam_present.button.confirm ?>";
   return confirm(msg);
}


var aryRequired = new Array();
var intArrayCount = 0;

function defineRequired(strElementName, strDisplayMessage)
  {
     var objRequired = new Object();
     objRequired.ElementName = strElementName;
     objRequired.DisplayMessage = strDisplayMessage;
      aryRequired[intArrayCount] = objRequired;
      intArrayCount++;
  }


function isBlank(val){
	if(val==null){return true;}
  for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
 }


function checkForm(objForm)
  {
   if (navigator.userAgent.indexOf("WebTV") == -1)
      {
       for (var i = 0; i < aryRequired.length; i++)
         {
             var blnFail = true; 
             var objElement = eval("objForm." + aryRequired[i].ElementName );
             if (objElement.length && !objElement.type)
                {
                  for (var x = 0; x < objElement.length; x++)
                   {
                     if (objElement[x].checked && objElement[x].value != "") blnFail = false;
                   } 
                 }
             else
                {
                   if (!isBlank(objElement.value))
                      {
                          blnFail = false;
                       }
                 }
            if (blnFail)
              {
                  alert(aryRequired[i].DisplayMessage);
                 if (objElement.length && !objElement.type)
                      objElement[0].focus();
                  else
                      objElement.focus();
                  return false;
              }
         }
      }
    return verify();
  }
 <?cs set:total = quiz_total - #1 ?>
 <?cs loop:x = #0, total, #1 ?>
   <?cs set:q_value = "q" + x ?>
   <?cs set:y = x + #1?>
   <?cs set:msg_value = lang.hotpot_exam_present.noanswer + y  ?>
   defineRequired("<?cs var:q_value ?>", "<?cs var:msg_value ?>");
 <?cs /loop ?>
</script>
<?cs /def ?>






<?cs def:print_questions() ?>
<?cs set:number_question = #1 ?>
<?cs each:this = quiz.ques ?>
  <?cs if:this.type == "mc" ?>
      <?cs call:print_mc(this, number_question) ?>
  <?cs elif:this.type == "mc_multi" ?>
      <?cs call:print_mc_multi(this, number_question) ?>
  <?cs elif:this.type == "short" ?>
      <?cs call:print_short(this, number_question) ?>
  <?cs /if ?>
<?cs set:number_question = number_question + #1 ?>
<?cs /each ?>

<?cs if:access ?>
<div class="center_msg">
 <div>
  <input type="hidden" name="crs" value="<?cs var:crs ?>" />
  <input type="hidden" name="id" value="<?cs var:id ?>" />
  <input type="hidden" name="sender" value="<?cs var:sender ?>" />
  <input type="hidden" name="inf" value="<?cs var:inf ?>" />
  <input type="hidden" name="test" value="<?cs var:test ?>" />
  <input type="hidden" name="loc" value="<?cs var:loc ?>" />
 </div>
  <input type="submit" name="submit" id="submit" value="<?cs var:lang.hotpot_exam_present.button.msg ?>" title="<?cs var:lang.hotpot_exam_present.button.help ?>" />
</div>
<?cs /if ?>

<?cs /def ?>


<?cs def:print_style() ?>
 <style type="text/css">
   body {
      background-color: 
      <?cs if:bg_color ?>
       <?cs var:bg_color ?> 
      <?cs else ?> 
       #FFFFFF 
      <?cs /if ?>;
      color: 
       <?cs if:text_color ?> 
         <?cs var:text_color ?> 
       <?cs else ?> 
         #000000 
      <?cs /if ?>;
     <?cs if:font_face ?>
        font-family:  <?cs var:font_face ?>;
     <?cs /if ?>
      font-size: 12px;   
    }
    h3, h4 {
      <?cs if:quiz.title_color ?>
        color: <?cs var:quiz.title_color ?>;
      <?cs else ?>
        color: #000000;
      <?cs /if ?>
     }
    .table_bg 
     {
        <?cs if:ex_bg_color ?>
          background-color: <?cs var:ex_bg_color ?>;
        <?cs else ?>
          backgroud-color: #FFFFFF;
        <?cs /if ?>
      }
    th, td
    {
      color: <?cs if:text_color ?> <?cs var:text_color ?> <?cs else ?> #000000 <?cs /if ?>;
      font-size: 12px;   
    }
 </style>
<?cs /def ?>




<?cs call:html_heading() ?>
   <head>
      <title><?cs var:course_no ?> <?cs var:lang.hotpot_exam_present.html_title ?></title>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <base href=<?cs var:base_url ?>" />
   <link rel="StyleSheet" href="<?cs var:image_path ?>common.css" type="text/css"  />
   <?cs call:insert_javascripts() ?>
   <?cs call:print_style() ?>
   
</head>

<body onload="startclock()" <?cs if:bg_color ?>style="background-color: <?cs var:bg_color ?>;"<?cs /if ?> >
<?cs call:course_info() ?>
<br />
<br />
<?cs call:print_quiz_title() ?>
<?cs call:print_sub_title() ?>
<?cs call:print_instructions() ?>
<?cs call:print_timer() ?>

<div>
  <?cs if:teacher_test_exam ?>
  <form method="post" name="theform" action="<?cs var:server_name ?>/<?cs var:action ?>" target="test_exam" onsubmit="checkForm(document.theform); window.open('','test_exam','resizable=1,scrollbars=1,width=500,height=600').focus()">
  <?cs else ?> 
  <form method="post" name="theform" action="<?cs var:server_name ?>/<?cs var:action ?>" onsubmit="return checkForm(document.theform)">
  <?cs /if ?>
  <?cs call:print_questions() ?>
</form>
</div>
</body>
</html>
<?cs call:runtime() ?>
