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

<?cs def:print_hour() ?>
 <select name="item_due_date_hour" id="item_due_date_hour" title="<?cs var:lang.grade_book_items.hour ?>">
 <?cs loop:x=#1, #12, #1 ?>
      <?cs if:x < #10 ?>
   <option value="<?cs var:x ?>" <?cs if:date_hour == x ?> selected="selected" <?cs /if ?> >0<?cs var:x ?></option>
 <?cs else ?>
   <option value="<?cs var:x ?>" <?cs if:date_hour == x ?> selected="selected" <?cs /if ?>><?cs var:x ?></option>
 <?cs /if ?>
 <?cs /loop ?>
 </select>
<?cs /def ?>


<?cs def:print_minute() ?>
 <select name="item_due_date_min" id="item_due_date_min" title="<?cs var:lang.grade_book_items.min ?>">
   <?cs loop:x=#0, #59, #1 ?>
    <?cs if:x < #10 ?>
   <option value="<?cs var:x ?>" <?cs if:date_minute == x ?> selected="selected" <?cs /if ?>> 0<?cs var:x ?></option>
  <?cs else ?>
   <option value="<?cs var:x ?>" <?cs if:date_minute == x ?> selected="selected" <?cs /if ?>><?cs var:x ?></option>
  <?cs /if ?>
  <?cs /loop ?>
  </select>
<?cs /def ?>

<?cs def:print_ampm() ?>
 <select name="item_due_date_am" id="item_due_date_am" title="<?cs var:lang.grade_book_items.ampm_help ?>">
     <option value="0" <?cs if:date_is_am  ?> selected="selected" <?cs /if ?>><?cs var:lang.grade_book_items.am ?></option>
     <option value="1" <?cs if:!date_is_am  ?> selected="selected" <?cs /if ?>><?cs var:lang.grade_book_items.pm ?></option>
  </select>
<?cs /def ?>

<?cs def:print_date() ?>
<div id="container">
<?cs if:Query.save ?>
  <div style="float:right">
      <a href="javascript:dothis()" title="<?cs var:lang.grade_book_items.closewindow ?>" ><img src="<?cs var:image_path ?>close.gif" /></a>
  </div>
<?cs /if ?>
  <br />
  <br />
  <form method="post" action="grade_book_due_date" onsubmit="return check_date()"> 
  <input type="hidden" name="crs" value="<?cs var:Query.crs ?>" /> 
  <input type="hidden" name="id" value="<?cs var:Query.id ?>" /> 
  <input type="hidden" name="item_id" value="<?cs var:Query.item_id ?>" /> 
  <input type="hidden" name="old_date" id="old_date" value="<?cs var:date_date ?>" /> 
  <input type="hidden" name="old_min" id="old_min" value="<?cs var:date_minute ?>" /> 
  <input type="hidden" name="old_hour" id="old_hour" value="<?cs var:date_hour ?>" /> 
  <?cs if:date_is_am ?>
  <input type="hidden" name="is_am" id="is_am" value="0" /> 
  <?cs else ?>
  <input type="hidden" name="is_am" id="is_am" value="1" /> 
  <?cs /if ?>

  <table width="100%" cellpacing="0" cellpadding="4">
    <tr class="headingcolor">
    <td>
      &nbsp;
    </td>
    </tr>
    <tr>
    <td>
        <?cs var:lang.grade_book_items.due_date ?>:<a href="javascript:openWindow('calendar_pick?textId=item_due_date', 'pickdate')" title="<?cs var:grade_book_items.due_date_help ?>" ><img src="<?cs var:image_path ?>pickdate.jpg" alt="" align="center" /></a>
        <span id="date_error" style="visibility:hidden; color:#f00">*</span> 
      	<input type="text" size="10" name="item_due_date" id="item_due_date" title="<?cs var:lang.grade_book_items.due_date_help ?>" value="<?cs var:date_date ?>" /> 
	<?cs call:print_hour() ?>:<?cs call:print_minute() ?> <?cs call:print_ampm() ?>
   </td>
   </tr>
   <tr class="headingcolor"><td align="center">
   <input type="submit" name="oper" value="<?cs var:lang.grade_book_items.save ?>" title="<?cs var:lang.grade_book_items.save ?>" />

   </td></tr>
   </table>
</div>
<?cs /def ?>


<?cs ###########################
     # HTML starts here
     ###########################
?>
<?cs call:html_heading() ?>
   <head>
      <title><?cs var:course_title ?> <?cs var:lang.grade_configure.scale_heading ?></title>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <meta http-equiv="Cache-Control" content="No-Cache" />
   <meta http-equiv="EXPIRES" content="Mon, 22 Jul 1997 11:12:01 GMT" />
   <meta http-equiv="PRAGMA" content="No-Cache" />

   <link rel="StyleSheet" href="<?cs var:image_path ?>grade_tab_menu.css" type="text/css"  />
   <script type="text/javascript" src="<?cs var:image_path ?>form_validation.js">
   </script>
    <script type="text/javascript">
     function dothis()
    {
      opener.parent.location.reload();
          window.close();
    }

    function openWindow(some_url,winname)
   {
       var new_window = window.open(some_url, winname,'menubar=0,toolbar=0,status=0,scrollbars=yes,resizable=yes,width=300,height=250,screenX=150,screeny=200,left=150,top=200');
       new_window.focus();
   }
   function check_date()
   {
      var date_value = document.getElementById('item_due_date').value;
      if(is_whitespace(date_value))
      {
         var error = document.getElementById('date_error');
	 error.style.visibility = "visible";
         window.alert('<?cs var:lang.grade_book_items.date_error ?>');
	return false;

      }
      else
      {
         var error = document.getElementById('date_error');
	 error.style.visibility = "hidden";

	 var old_date = document.getElementById('old_date').value;
	 var old_hour = document.getElementById('old_hour').value;
	 var old_min = document.getElementById('old_min').value;
	 var old_am = document.getElementById('is_am').value;
         var new_hour = document.getElementById('item_due_date_hour').value;
         var new_min = document.getElementById('item_due_date_min').value;
         var new_am = document.getElementById('item_due_date_am').value;
	 
	 if(old_date != date_value || old_hour != new_hour || old_min != new_min || old_am != new_am)
	 {
	     var confirm = window.confirm('<?cs var:lang.grade_book_items.date_change_confirm ?>');
	     if(confirm)
	       return true;
	     else 
	       return false;
	 }
         else
	 {
	     window.alert('<?cs var:lang.grade_book_items.date_no_change ?>');
	     return false;
	 }	 
      }
       
   }
   </script>

<?cs call:define_body() ?> 
 <?cs call:print_date() ?>
</body>
</html>
<?cs call:runtime() ?>
