<?cs include:"util.cs" ?>
<?cs include:"grade_book_menu_util.cs" ?>
<?cs set:credit.all = "all" ?>
<?cs set:credit.partial = "partial" ?>
<?cs set:credit.no = "no" ?>
<?cs set:boolean.yes = "yes" ?>
<?cs set:boolean.no = "no" ?>

<?cs def:print_category(cat_id, name) ?>
   <select name="<?cs var:name ?>" id="<?cs var:name ?>" title="<?cs var:lang.grade_book_items.category_help ?>" >
    <option value="-1"><?cs var:lang.grade_book_items.select_a_category ?></option> 
    <?cs each:cc = categories ?>
    <?cs if:cat_id == cc.cat_id ?>
    <option value="<?cs var:cc.cat_id ?>" selected="selected"><?cs var:cc.cat_name ?> (<?cs var:cc.cat_weight ?>%)</option>
    <?cs else ?> 
    <option value="<?cs var:cc.cat_id ?>"><?cs var:cc.cat_name ?> (<?cs var:cc.cat_weight ?>%)</option>
    <?cs /if ?> 
    <?cs /each ?>
   </select> 
<?cs /def ?>

<?cs def:print_extra_credit(value, name) ?>
   <select name="<?cs var:name ?>" id="<?cs var:name ?>" title="<?cs var:lang.grade_book_items.extracredit_help ?>">
     <?cs each:ec = lang.grade_book_items.extra_credit ?>
      <?cs if:value == credit[name(ec)] ?>
        <option value="<?cs var:credit[name(ec)] ?>" selected="selcted"><?cs var:ec ?></option> 
      <?cs else ?>
        <option value="<?cs var:credit[name(ec)] ?>"><?cs var:ec ?></option> 
      <?cs /if ?> 

     <?cs /each ?> 
   </select>

<?cs /def ?>

<?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 ?>">0<?cs var:x ?></option>
 <?cs else ?>
   <option value="<?cs var:x ?>"><?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 ?>"> 0<?cs var:x ?></option>
  <?cs else ?>
   <option value="<?cs var:x ?>" ><?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="1" ><?cs var:lang.grade_book_items.am ?></option>
     <option value="0"><?cs var:lang.grade_book_items.pm ?></option>
  </select>
<?cs /def ?>



<?cs def:print_new_item() ?> 
<div>
   <table cellspacing="0" cellpadding="4" width="100%">
   <tr class="headingcolor">
     <th align="left" colspan="3">
       <?cs var:lang.grade_book_items.new_item ?>
     </td>
   </tr>
   <tr class="evencolor">
      <td><?cs call:insert_help("gradebook_help.html", "ITEMS_Item_name", lang.grade_book_items.help_button_title, "gradebook_help") ?><?cs var:lang.grade_book_items.item_name ?>: 
        <input type="text" name="item_name" id="item_name" maxlength="<?cs var:max_item_len ?>" size="20" title="<?cs var:lang.grade_book_items.item_name_help ?>" /> 
      </td>
      <td>
        <?cs call:insert_help("gradebook_help.html", "ITEMS_Category", lang.grade_book_items.help_button_title, "gradebook_help") ?><?cs var:lang.grade_book_items.category ?>:
        <?cs call:print_category(0, "item_category") ?>
      </td>
      <td>
        <?cs call:insert_help("gradebook_help.html", "ITEMS_Extra_Credit_Item", lang.grade_book_items.help_button_title, "gradebook_help") ?><?cs var:lang.grade_book_items.extracredit ?>:
        <?cs call:print_extra_credit(credit.no, "item_extra_credit") ?>
      </td>
   </tr>
   <tr class="oddcolor">
      <td id="points_method" style="visibility:hidden">
        <?cs call:insert_help("gradebook_help.html", "ITEMS_Grading_method", lang.grade_book_items.help_button_title, "gradebook_help") ?><?cs var:lang.grade_book_items.points ?>:
        <input type="text" size="10" name="item_points" id="item_points" title="<?cs var:lang.grade_book_items.points_help ?>" /> 
      </td>
      <td>
        <?cs call:insert_help("gradebook_help.html", "ITEMS_Grading_method", lang.grade_book_items.help_button_title, "gradebook_help") ?><?cs var:lang.grade_book_items.grade_method ?>:
        <select name="grade_method" id="grade_method" title="<?cs var:lang.grade_book_items.grade_method_help ?>" onchange="javascript:changeGradeMethod()">
         <option value="-1"><?cs var:lang.grade_book_items.select_method ?></option> 
         <option value="points"><?cs var:lang.grade_book_items.points_method ?></option> 
         <option value="letter_grades"><?cs var:lang.grade_book_items.letter_method ?></option> 
	</select>	
      </td>
      <td>
        <?cs call:insert_help("gradebook_help.html", "ITEMS_Date", lang.grade_book_items.help_button_title, "gradebook_help") ?><?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>
        <input type="text" size="10" name="item_due_date" id="item_due_date" title="<?cs var:lang.grade_book_items.due_date_help ?>" /> 
	<?cs call:print_hour() ?>:<?cs call:print_minute() ?> <?cs call:print_ampm() ?>
      </td>
   </tr>
   </table>
   <div id="letter_method" style="display:none">
   <table cellspacing="0" cellpadding="4" width="100%">
   <tr class="headingcolor">
     <th align="left">
        <?cs var:lang.grade_book_items.letter ?>
     </th>
     <th align="left">
        <?cs var:lang.grade_book_items.points ?>
     </th>
    </tr>
    <?cs set:number = #0 ?>
     <?cs each:lg = letter_grades ?>
     <?cs if:number % #2 == #0 ?>
        <tr class="evencolor">
     <?cs else ?>
        <tr class="oddcolor">
     <?cs /if ?>
     
     <td width="15" ><input type="text" maxlength="10" size="10" name="letter_<?cs var:number ?>" id="letter_<?cs var:number ?>" value="<?cs var:lg.name ?>" /></td>
     <td><input type="text" size="10" maxlength="10" name="points_<?cs var:number ?>" id="points_<?cs var:number ?>" value="<?cs var:lg.points ?>" /></td>
   </tr>
    <?cs set:number = number + #1 ?>
   <?cs /each ?>
   <tr><td colspan="2"><input type="hidden" name="number_letters" id="number_letters" value="<?cs var:number ?>" /></td></tr>
   </table> 
   </div>

   <table cellspacing="0" cellpadding="4" width="100%">
   <tr class="headingcolor"><td align="center">
       <input type="button" value="<?cs var:lang.grade_book_items.save ?>" onclick="getNextUrl('grade_book_items?crs=<?cs var:Query.crs ?>&amp;id=<?cs var:Query.id ?>', 'save')" />
       </td>
   </tr> 
   </table>
</div>
<?cs /def ?>

<?cs def:print_heading() ?>
<tr class="headingcolor">
  <th align="left" nowrap="nowrap">
     <?cs var:lang.grade_book_items.item_name ?><?cs call:insert_help("gradebook_help.html", "ITEMS_Item_name", lang.grade_book_items.help_button_title, "gradebook_help") ?>
  </th>
  <th align="left" nowrap="nowrap">
     <?cs var:lang.grade_book_items.category ?><?cs call:insert_help("gradebook_help.html", "ITEMS_Category", lang.grade_book_items.help_button_title, "gradebook_help") ?>
  </th>
  <th align="left" nowrap="nowrap">
     <?cs var:lang.grade_book_items.extracredit ?><?cs call:insert_help("gradebook_help.html", "ITEMS_Extra_Credit_Item", lang.grade_book_items.help_button_title, "gradebook_help") ?>
  </th>
  <th align="left" nowrap="nowrap">
     <?cs var:lang.grade_book_items.points ?><?cs call:insert_help("gradebook_help.html", "ITEMS_Grading_method", lang.grade_book_items.help_button_title, "gradebook_help") ?>
  </th>
  <th align="left" nowrap="nowrap">
     <?cs var:lang.grade_book_items.letter_grade ?><?cs call:insert_help("gradebook_help.html", "ITEMS_Grading_method", lang.grade_book_items.help_button_title, "gradebook_help") ?>
  </th>
  <th align="left" nowrap="nowrap">
     <?cs var:lang.grade_book_items.hide ?><?cs call:insert_help("gradebook_help.html", "ITEMS_Hide", lang.grade_book_items.help_button_title, "gradebook_help") ?>
  </th>
  <th align="left" nowrap="nowrap">
     <?cs var:lang.grade_book_items.due_date ?><?cs call:insert_help("gradebook_help.html", "ITEMS_Date", lang.grade_book_items.help_button_title, "gradebook_help") ?>
  </th>
  <th align="left" nowrap="nowrap">
     <?cs var:lang.grade_book_items.graded ?><?cs call:insert_help("gradebook_help.html", "ITEMS_Graded", lang.grade_book_items.help_button_title, "gradebook_help") ?>
  </th>
  <th align="left" nowrap="nowrap">
     <?cs var:lang.grade_book_items.delete ?><?cs call:insert_help("gradebook_help.html", "ITEMS_Delete", lang.grade_book_items.help_button_title, "gradebook_help") ?>
  </th>
</tr>
</tr>
<?cs /def ?>

<?cs def:print_boolean_select(value, name, help) ?>
 <select name="<?cs var:name ?>" id="<?cs var:name ?>" title="<?cs var:help ?>" >
   <?cs each:bl = lang.grade_book_items.boolean ?>
   <?cs if:boolean[name(bl)] == value ?>
     <option value="<?cs var:boolean[name(bl)] ?>" selected="selected"><?cs var:bl ?></option>
   <?cs else ?>
     <option value="<?cs var:boolean[name(bl)] ?>" ><?cs var:bl ?></option>
   <?cs /if ?>
   <?cs /each ?> 
 </select> 
<?cs /def ?>

<?cs def:print_one_item(one_item, number) ?>
 <?cs if:number % 2 == #0 ?>
  <tr class="evencolor">
 <?cs else ?>
  <tr class="oddcolor">
 <?cs /if ?>
   <td>
   <input type="hidden" name="item_name_old_<?cs var:number ?>" id="item_name_old_<?cs var:number ?>"  value="<?cs var:one_item.item_name ?>" />
   <input type="hidden" name="item_cat_old_<?cs var:number ?>" id="item_cat_old_<?cs var:number ?>" value="<?cs var:one_item.cat_id ?>" />
   <input type="hidden" name="item_date_old_<?cs var:number ?>" id="item_date_old_<?cs var:number ?>" value="<?cs var:one_item.due_date ?>" />
   <input type="hidden" name="item_points_old_<?cs var:number ?>" id="item_points_old_<?cs var:number ?>" <?cs if:one_item.is_letter_grade == "yes" ?> value="" <?cs else ?>value="<?cs var:one_item.item_points ?>"  <?cs /if ?> />
   <input type="hidden" name="item_extra_old_<?cs var:number ?>" id="item_extra_old_<?cs var:number ?>" value="<?cs var:one_item.extra_credit ?>" />
   <input type="hidden" name="item_id_<?cs var:number ?>"  value="<?cs var:one_item.item_id ?>" />
   <input type="hidden" name="item_letter_grades_old_<?cs var:number ?>" id="item_letter_grades_old_<?cs var:number ?>" value="<?cs var:one_item.is_letter_grade ?>" />
   <input type="hidden" name="item_hide_old_<?cs var:number ?>" id="item_hide_old_<?cs var:number ?>" value="<?cs var:one_item.hide ?>" />
   <span id="item_name_error_<?cs var:number ?>" style="visibility:hidden; color:#f00">*</span>
   <input type="text" name="item_name_<?cs var:number ?>" id="item_name_<?cs var:number ?>" value="<?cs var:one_item.item_name ?>" />
   </td>
   <td>
      <?cs set:name = "item_cat_"+number ?>
      <span id="item_cat_error_<?cs var:number ?>" style="visibility:hidden; color:#f00">*</span>
      <?cs call:print_category(one_item.cat_id, name) ?>
   </td>
   <td>
      <?cs set:name = "item_extra_"+number ?>
      <?cs call:print_extra_credit(one_item.extra_credit, name) ?>
   </td>
   <td>
      <?cs if:one_item.is_letter_grade == "no" ?>
      <span id="item_points_error_<?cs var:number ?>" style="visibility:hidden; color:#f00">*</span>
      <input type="text" maxlength="10" size="10" name="item_points_<?cs var:number ?>" id="item_points_<?cs var:number ?>" value="<?cs var:one_item.item_points ?>" />
      <?cs else ?>
        &nbsp;
      <?cs /if ?>	
   </td>
   <td>
      <?cs if:one_item.is_letter_grade == "yes" ?>
      <a href="javascript:openWin('grade_book_letter_grades?crs=<?cs var:Query.crs ?>&id=<?cs var:Query.id ?>&item_id=<?cs var:one_item.item_id ?>', 'letter_grades')" title="<?cs var:lang.grade_book_items.letter_grades_detail_help ?>" ><?cs var:lang.grade_book_items.letter_grades_detail ?></a>
      <?cs else ?>
        &nbsp;
      <?cs /if ?>
   </td>

   <td>
      <?cs set:name = "item_hide_"+number ?>
      <?cs call:print_boolean_select(one_item.hide, name, lang.grade_book_items.hide_help) ?>
   </td>
   <td>
      <a href="javascript:openWin('grade_book_due_date?crs=<?cs var:Query.crs ?>&id=<?cs var:Query.id ?>&item_id=<?cs var:one_item.item_id ?>','date_window')" title="<?cs var:one_item.due_date ?> <?cs if:one_item.due_date_hour < #10 ?>0<?cs /if ?><?cs var:one_item.due_date_hour ?>:<?cs if:one_itme.due_date_minute < #10 ?>0<?cs /if ?><?cs var:one_item.due_date_minute ?> <?cs if:one_item.due_date_is_am ?> <?cs var:lang.grade_book_items.am ?><?cs else ?><?cs var:lang.grade_book_items.pm ?><?cs /if ?>" > <img src="<?cs var:image_path ?>calendar_icon.gif" alt=""></a>
      
   </td>
   <td>
      <?cs if:one_item.grade_entered == "yes" ?>
      <img src="<?cs var:image_path ?>task.gif" alt="" />
      <?cs /if ?>
   </td>
   <td>
      <a href="#" onclick="javascript:getNextUrl('grade_book_items?crs=<?cs var:Query.crs ?>&id=<?cs var:Query.id ?>', 'delete:<?cs var:one_item.item_id ?>'); return false;" title="<?cs var:lang.grade_book_items.delete_item_help ?>" ><img src="<?cs var:image_path ?>delete.gif" alt=""></a>
   </td>
   
 </tr>
<?cs /def ?>

<?cs def:print_items() ?>
<?cs if:items[1].item_id ?>
 <table width="100%" cellpadding="4" cellspacing="0">
 <?cs call:print_heading() ?>
 <?cs set:number = #1 ?>
 <?cs each:one_item = items ?>
     <?cs call:print_one_item(one_item, number) ?>
     <?cs set:number = #1 + number ?>
 <?cs /each ?>

 <tr class="headingcolor">
   <td colspan="9" align="center">
   <input type="button" value="<?cs var:lang.grade_book_items.update ?>" title="<?cs var:lang.grade_book_items.update_help ?>" onclick="getNextUrl('grade_book_items?crs=<?cs var:Query.crs ?>&id=<?cs var:Query.id ?>', 'update')" />
   </td>
 </tr>
 <tr>
   <td colspan="9">
    &nbsp;
   </td>
 </tr>

 </table>
 <?cs /if ?>
<?cs /def ?>

<?cs def:print_member_heading() ?>
<tr class="headingcolor">
  <th align="left">
     <?cs var:lang.grade_book_items.item_name ?>
  </th>
  <th align="left">
     <?cs var:lang.grade_book_items.extracredit ?>
  </th>
  <th align="left">
     <?cs var:lang.grade_book_items.points ?>
  </th>
  <th align="left">
     <?cs var:lang.grade_book_items.letter_grade ?>
  </th>
  <th align="left">
     <?cs var:lang.grade_book_items.due_date ?>
  </th>
  <th align="left">
     <?cs var:lang.grade_book_items.hide ?>
  </th>
  <th align="left">
     <?cs var:lang.grade_book_items.graded ?>
  </th>
 </tr>
 <?cs /def ?>

<?cs def:print_members() ?>
<div id="container">
  <br />
  <br />
    <table width="100%" cellspacing="0" cellpadding="4">
     <?cs call:print_member_heading() ?>
     <?cs set:number = #1 ?>
     <?cs each:one_item = items ?>
      <?cs if:number % 2 == #0 ?>
       <tr class="evencolor">
     <?cs else ?>
     <tr class="oddcolor">
     <?cs /if ?>
       <td><?cs var:one_item.item_name ?></td> 
       <td><?cs var:one_item.extra_credit ?></td> 
       <td><?cs var:one_item.item_points ?></td> 
       <td><?cs var:one_item.is_letter_grade ?></td> 
       <td><?cs var:one_item.due_date ?></td> 
       <td><?cs var:one_item.hide ?></td> 
       <td><?cs var:one_item.grade_entered ?></td> 
     </tr>
     <?cs set:number = #1 + number ?>
     <?cs /each ?>
    </table>
  </div>
<?cs /def ?>

<?cs def:print_content() ?>
<div>
<br />
  <form id="item_form" method="post" action="grade_book_items_save">
  <input type="hidden" name="nextUrl" value="" />
  <input type="hidden" name="save_option" value="" />
  <input type="hidden" name="number_items" id="number_items" value="<?cs var:number_items ?>" />
  <input type="hidden" name="crs" value="<?cs var:Query.crs ?>" />
  <input type="hidden" name="id" value="<?cs var:Query.id ?>" />
  <table width="100%">
   <?cs if:no_category == #1 ?>
   <tr><td><?cs var:lang.grade_book_items.no_category_msg ?></td></tr>
   <?cs else ?> 
   <?cs call:print_items() ?>
   <?cs call:print_new_item() ?> 
   <?cs /if ?>
  </table>
  </form>
</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"  />
   
   <?cs if:!no_category ?>
   <script type="text/javascript" src="<?cs var:image_path ?>form_validation.js">
   </script>

   <script type="text/javascript">

   
   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 openWin(some_url,winname)
   {
       var new_window = window.open(some_url, winname,'menubar=0,toolbar=0,status=0,scrollbars=yes,resizable=yes,width=600,height=400,screenX=150,screeny=200,left=150,top=200');
       new_window.focus();
   }

   function changeGradeMethod()
   {
       var myform = document.getElementById('item_form');
       var index = myform.grade_method.selectedIndex;
       var value = myform.grade_method[index].value;
       var points_id = document.getElementById('points_method');
       var letter_id = document.getElementById('letter_method');

       if(value == "points")
       {
           letter_id.style.display = "none";
	   points_id.style.visibility = "visible";
       } 
       else if(value == "letter_grades")
       {
	   points_id.style.visibility = "hidden";
	   letter_id.style.display = "block";

       }
       else
       {
	   points_id.style.visibility = "hidden";
	   letter_id.style.display = "none";
       }
       
   }

   function check_letter_unique(letters)
   {
        var i, j, len = letters.length;
        for(i =0; i<len; i++)
        {
  	     for(j = 0; j<len; j++)
     	      if( i != j)
     	      {
     		 if( letters[i] == letters[j])
     	           return false;
	      }
	}
       return true;
   }
 
   function newItem()
   {
       var item_name_value = document.getElementById('item_name').value;
       var item_category_value = get_selected_value('item_category');
       var item_extra_value = get_selected_value('item_extra_credit');
       var item_due_date_value = document.getElementById('item_due_date').value;
       var grade_method_value = get_selected_value('grade_method');
       
       if(is_whitespace(item_name_value) || bad_char(item_name_value) == false)
       {
	   window.alert('<?cs var:lang.grade_book_items.invalid_item_name ?>');
	   return 0;
       }
       if(item_category_value == "-1")
       {
	   window.alert('<?cs var:lang.grade_book_items.must_select_a_category ?>');
	   return 0;
       }
       if(is_whitespace(item_due_date_value))
       {
	   window.alert('<?cs var:lang.grade_book_items.due_date_error ?>');
	   return 0;

       }
       if(grade_method_value == "-1")
       {
	   window.alert('<?cs var:lang.grade_book_items.must_select_grade_method ?>');
	   return 0;

       }
       if(grade_method_value == "points")
       {
          var item_points_value = document.getElementById('item_points').value;
	  if(is_whitespace(item_points_value) || is_real(item_points_value) == false)
	  {
	      window.alert('<?cs var:lang.grade_book_items.invalid_item_points ?>');
	      return 0;
	  } 

       }

       else if(grade_method_value == "letter_grades")
       {
	  var letters = new Array();
	  var name;
	  var letter_value;
	  var points_value;
          var number = document.getElementById('number_letters').value;
	  var i = 0;
	  var count = 0, error = 0;
	  
	  for(i = 0; i< number; i++)
	  {
	      name = "letter_" +i;
	      letter_value = document.getElementById(name).value;
	      name = "points_" +i;
	      points_value = document.getElementById(name).value;
	      if(!is_whitespace(letter_value) && !is_whitespace(points_value))
	      {
		   letters[count] = letter_value;
		   if(bad_char(letter_value) == false || is_real(points_value) == false)
                        error++;
		   count++;
	      }
	  }
	  if(check_letter_unique(letters) == false)
	  {
	      window.alert('<?cs var:lang.grade_book_items.letter_grades_unique ?>');
	      return 0;
	
	  }
	  if(error > 0)
          {
	      window.alert('<?cs var:lang.grade_book_items.letter_points_contain_bad_char ?>');
	      return 0;
	  }

       }
       return 1;
   }

   function detectNewForm()
   {
       var item_name_value = document.getElementById('item_name').value;
       var item_category_value = get_selected_value('item_category');
       var item_due_date_value = document.getElementById('item_due_date').value;
       var grade_method_value = get_selected_value('grade_method');
       if(!is_whitespace(item_name_value) && item_category_value !="-1" && !is_whitespace(item_due_date_value) && grade_method_value !="-1")
	     return 1;
       else
	     return 0;

   }

   function formexits(name)
   {
       var elements = document.forms[0].elements;
       var i;
       for(i =0; i<elements.length; i++)
       {
	    if(elements[i].name == name)
		  return 1;
       }
       return 0; 
   }

   function unique_name_check(unique)
   {
	var i, j;
	var len = unique.length;
	for(i =0; i<len; i++)
	{
	   for(j = 0; j<len; j++)
	     if(j != i)
	     {
		 if(unique[i] == unique[j])
			return 0;
	     }
	}
	return 1;
   }

   function checkItems()
   {
      var errors = 0;
      var changes = 0;
      var name;
      var name_old;
      var unique = new Array();
      var value_new;
      var value_old;
      var i;
      var number = document.getElementById('number_items').value;
      
      for(i = 1; i<= number; i++)
      {
          name = "item_name_" + i;
	  value_new = document.getElementById(name).value;
	  unique[i-1] = value_new;
          name = "item_name_old_" + i;
	  value_old = document.getElementById(name).value;
	  if(is_whitespace(value_new) || bad_char(value_new) == false)
	  {
	     errors++;
             name = "item_name_error_" + i;
	     var star  = document.getElementById(name);
             star.style.visibility = "visible";
	  }
	  if(value_new != value_old)
             changes++;

          name = "item_cat_" + i;
          value_new = get_selected_value(name);
          name = "item_cat_old_" +i;
	  value_old = document.getElementById(name).value;
	  if(value_new == "-1")
	  {
	     errors++;
             name = "item_cat_error_" + i;
	     var star  = document.getElementById(name);
             star.style.visibility = "visible";
	  }
	  if(value_new != value_old)
             changes++;

          name = "item_points_" +i;
          if(formexits(name))
	  {
	     value_new = document.getElementById(name).value;
	     if(is_whitespace(value_new) || is_real(value_new) == false)
	     {
	        errors++;
                name = "item_points_error_" + i;
	        var star  = document.getElementById(name);
                star.style.visibility = "visible";
	     }
	     
             name = "item_points_old_" +i;
	     value_old = document.getElementById(name).value;
	     if(value_new != value_old)
		     changes++;
	  }

          name = "item_extra_" + i;
          value_new = get_selected_value(name);

          name = "item_extra_old_" +i;
	  value_old = document.getElementById(name).value;
	  if(value_new != value_old)
		 changes++;

          name = "item_hide_" + i;
          value_new = get_selected_value(name);
          name = "item_hide_old_" + i;
	  value_old = document.getElementById(name).value;
	  if(value_new != value_old)
		 changes++;
      }

      if(errors > 0)
      {
	  window.alert('<?cs var:lang.grade_book_items.update_error ?>');
	  return 0;
      } 

      if(!unique_name_check(unique))
      {
	  window.alert('<?cs var:lang.grade_book_items.item_name_unique ?>');
	  return 0;
      }

      if(changes > 0)
	   return 1;
      else
	 return 2; 

   }

   function getNextUrl(url, some)
   {
       var myform = document.getElementById('item_form');
       myform.nextUrl.value = url;
       if(some == "update")
       {
          if(checkItems() == 1)
	  {
	      var confirm = window.confirm('<?cs var:lang.grade_book_items.update_confirm ?>');
	      if(confirm) 
	      {
	         myform.save_option.value="update";
                 myform.submit();
	      }
	  } 
	  else if(checkItems() == 2)
	  {
	       window.alert('<?cs var:lang.grade_book_items.no_changes ?>');
	  }

       }
       else if(some == "save")
       {
           if(newItem())
	   {
	      var confirm = window.confirm('<?cs var:lang.grade_book_items.save_new_item_confirm ?>');
	      if(confirm) 
	      {
	         myform.save_option.value="save";
                 myform.submit();
	      }
	      else
	         return false;
	   }
	   else
	      return false;

       }
       else if(some.length > 0)
       {

	    var confirm = window.confirm('<?cs var:lang.grade_book_items.delete_item_confirm ?>');
	    if(confirm)
	    {
	       myform.save_option.value=some;
               myform.submit();
	    }
	    else 
		return false;

          
       }
       else
       {
           if(detectNewForm())
	   {
              if(newItem())
	      {
	        var confirm = window.confirm('<?cs var:lang.grade_book_items.save_new_item_confirm ?>');
		if(confirm)
	           myform.save_option.value="save";
		else
	           myform.save_option.value="no";
                myform.submit();
	      }
	      else
		  return false;
	   }
	   else if(checkItems() == 1)
	   {
	      var confirm = window.confirm('<?cs var:lang.grade_book_items.update_confirm ?>');
	      if(confirm) 
	      {
	         myform.save_option.value="update";
                 myform.submit();
	      }
	      else
	      {
	         myform.save_option.value="no";
                 myform.submit();
	      }
	   }
	   else
	   {
	        myform.save_option.value="no";
                myform.submit();
	   }
       }
   }
   </script>

 <?cs else ?>
   <script type="text/javascript">
   function getNextUrl(url, some)
   {
       var myform = document.getElementById('item_form');
       myform.nextUrl.value = url;
       myform.save_option.value = "no";
       myform.submit(); 
   }
   </script>
 <?cs /if ?>

</head>


<?cs call:define_body() ?> 
<?cs if:cat_members ?>
<?cs call:print_members() ?>
<?cs else ?>
<div id="container">
<?cs call:print_course_heading(back_url, lang.grade_book_menu_util.goback) ?>
<div>
<br />
<br />
  <?cs call:grade_menu()  ?>
</div>
<div id="content">
<?cs call:print_content() ?>
</div>
</div>
<?cs /if ?>

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