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


<?cs def:print_description(mydata) ?>
  <tr>
   <td colspan="2" class="table_heading"><?cs var:mydata ?></td>
  </tr>
<?cs /def ?>




<?cs def:print_radio(name, value, desc, id) ?>
  <tr>
   <td><input type="radio" name="<?cs var:name ?>" value="<?cs var:value ?>" id="<?cs var:name ?>_<?cs var:id ?>" title="<?cs var:desc ?>"/></td>
   <td><?cs var:desc ?></td>
  </tr>
<?cs /def ?>





<?cs def:print_ampm(prefix) ?>
    <select name="<?cs var:prefix ?>_am" id="<?cs var:prefix ?>_am" >
    <option value="0" <?cs if:current_is_am ?>selected="selected"<?cs /if ?> ><?cs var:lang.survey_deliver_form.am ?></option>   
    <option value="1" <?cs if:!current_is_am ?>selected="selected"<?cs /if ?> ><?cs var:lang.survey_deliver_form.pm ?></option>   
    </select>
<?cs /def ?>




<?cs def:print_hour(prefix) ?> 
    <select name="<?cs var:prefix ?>_hour" id="<?cs var:prefix ?>_hour"  >
    <?cs loop:x=#1, #12, #1 ?>
      <?cs if:x < #10 ?>
        <option value="<?cs var:x ?>" <?cs if:x == current_hour ?> selected="selected" <?cs /if ?> >0<?cs var:x ?></option>
      <?cs else  ?>
      <option value="<?cs var:x ?>" <?cs if:x == current_hour ?> selected="selected" <?cs /if ?> ><?cs var:x ?></option>
     <?cs /if ?>
   <?cs /loop ?>
  </select>
<?cs /def ?>




<?cs def:print_min(prefix) ?> 
    <select name="<?cs var:prefix ?>_min" id="<?cs var:prefix ?>_min" >
    <?cs loop:x=#0, #59, #1 ?>
      <?cs if:x < #10 ?>
        <option value="<?cs var:x ?>" <?cs if:x == current_minute ?> selected="selected" <?cs /if ?> >0<?cs var:x ?></option>
      <?cs else  ?>
       <option value="<?cs var:x ?>" <?cs if:x == current_minute ?> selected="selected" <?cs /if ?> ><?cs var:x ?></option>
     <?cs /if ?>
   <?cs /loop ?>
  </select>
<?cs /def ?>




<?cs def:print_time(prefix) ?>
<tr>
  <td valign="middle" colspan="2">
   <a href="javascript:openBrWindow('calendar_pick?textId=<?cs var:prefix ?>', 'pickdate')" title="<?cs var:lang.survey_deliver_form.date_picker_title ?>"><img src="<?cs var:image_path ?>pickdate.jpg" alt="<?cs var:lang.survey_deliver_form.pick_date ?>" align="center"/></a>
    <input type="text" name="<?cs var:prefix ?>" id="<?cs var:prefix ?>" maxlength="10" size="10" title="<?cs var:lang.survey_deliver_form.use_date_picker ?>" />
    <?cs call:print_hour(prefix) ?> : <?cs call:print_min(prefix) ?> <?cs call:print_ampm(prefix) ?>
  </td>
 </tr>
<?cs /def ?>






<?cs def:print_course_description(my_desc) ?>
 <?cs if:my_desc ?><?cs var:my_desc ?><?cs else ?><?cs var:lang.no_description ?><?cs /if ?>
<?cs /def ?>




<?cs def:print_search_form() ?>
<?cs with:lang=lang.survey_deliver_form ?>
  <p class="instructions"><?cs var:lang.course_selection_instructions ?></p>
  <table cellspacing="0" cellpadding="2"  class="table_heading">
  <tr>
    <td align="right" class="regheading"><?cs var:lang.internal_course_name_label ?></td>
    <td align="center"><input type="text" name="search" size="12" maxlength="<?cs var:max_search ?>" title="<?cs var:lang.internal_course_name_title ?>" /></td>
    <td align="right" class="regheading"><?cs var:lang.course_group_label ?></td>
    <td>
     <select name="subdir" size="5" id="subdir" multiple="multiple" title="<?cs var:lang.course_group_title ?>" >
     <?cs each:grp = course_group ?>
         <option value="<?cs var:grp.value ?>" <?cs if:grp.is_selected ?>selected="selected"<?cs /if ?> ><?cs var:grp.value ?> (<?cs call:print_course_description(grp.description) ?>)</option>
     <?cs /each ?>
     </select>
    </td>
 
    <td valign="middle">
     <input type="submit" value="<?cs var:lang.submit_button ?>" title="<?cs var:lang.submit_button_title ?>" />
    </td>
 </tr>


<?cs ### 'INCLUDE ____ COURSES' RADIO BUTTONS ?>

<tr>
  <td class="regheading" align="right"><?cs var:lang.include_course_type_label ?></td>
  <td colspan="4" style="font-weight:normal" >
    <input type="radio" name="type" value="0" checked="checked" title="<?cs var:lang.standalone_and_centralized ?>" /><?cs var:lang.standalone_and_centralized ?> 
    <input type="radio" name="type" value="1"  title="<?cs var:lang.only_standalone ?>" /><?cs var:lang.only_standalone ?> 
    <input type="radio" name="type" value="2"  title="<?cs var:lang.only_centralized ?>" /><?cs var:lang.only_centralized ?> 
 </td>
</tr>




<?cs ### 'MATCHES MUST _____ SEARCH STRING' RADIO BUTTONS ?>

<tr>
  <td class="regheading" align="right"><?cs var:lang.search_match_label ?></td>
  <td colspan="4" style="font-weight:normal" >
    <input type="radio" name="where" value="0" checked="checked" title="<?cs var:lang.contain ?>" /><?cs var:lang.contain ?> 
    <input type="radio" name="where" value="1"  title="<?cs var:lang.start_with ?>" /><?cs var:lang.start_with ?> 
    <input type="radio" name="where" value="2"  title="<?cs var:lang.end_with ?>" /><?cs var:lang.end_with ?> 
 </td>
</tr>

</table>
<?cs /with ?>
<?cs /def ?>


    



<?cs call:html_header() ?>
<head>
  <title><?cs var:lang.survey_deliver_form.page_title ?></title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <link rel="StyleSheet" href="<?cs var:image_path ?>common.css" type="text/css" />
  <link rel="StyleSheet" href="<?cs var:image_path ?>survey.css" type="text/css" />
  <script type="text/javascript" src="<?cs var:image_path ?>form_validation.js"></script>
  <script type="text/javascript">


  function check_select(good_id)
   {
     var index = document.getElementById(good_id).selectedIndex;
     if(index ==-1)
        return false;
     else
       return true;
   }
  
  

  function test_radio(prefix, num)
   {
    var test;
    var count =0;
    for(i=0; i<num; i++)
    {
       var ss = prefix + i;
       test = document.getElementById(ss).checked;
        if(test)
          count++;
    }
    return count;
   }




  function get_time_string(id_name, type_str)
  {
   var time_str = "";
   var zero_hour = "";
   var zero_min = "";
   var my_date = document.getElementById(id_name).value;
   var name = id_name + "_hour";
   var hour = parseInt(get_selected_value(name));
   var name = id_name + "_min";
   var min = parseInt(get_selected_value(name));
   var name = id_name + "_am";
   var pm = parseInt(get_selected_value(name));

   if(hour < 10)
      zero_hour = "0";
   if(min < 10)
      zero_min = "0";
   time_str = type_str + " " + my_date + " " + zero_hour + hour + ":" + zero_min + min;
   if(pm)
     time_str += " <?cs var:lang.survey_deliver_form.pm ?>";
   else
     time_str += " <?cs var:lang.survey_deliver_form.am ?>";
      
   return time_str;    
  }



  function validate_form()
  {

    if(!test_radio("taker_", 4))
     {
      window.alert("<?cs var:lang.survey_deliver_form.taker_left_blank ?>");
      return false;
     } 


    if(!test_radio("save_course_", 2))
     {
      window.alert("<?cs var:lang.survey_deliver_form.list_courses_left_blank ?>");
      return false;
     }



    var date_string = document.getElementById("release").value;
    if(checkvalid_date_string(date_string) == false)
     {
      window.alert("<?cs var:lang.survey_deliver_form.release_date_invalid ?>");
      return false;
     }
    

    date_string = document.getElementById("unrelease").value;
    if(checkvalid_date_string(date_string) == false)
     {
      window.alert("<?cs var:lang.survey_deliver_form.unrelease_date_invalid ?>");
      return false;
     }
    

    date_string = document.getElementById("result").value;
    if(checkvalid_date_string(date_string) == false)
     {
      window.alert("<?cs var:lang.survey_deliver_form.result_date_invalid ?>");      
      return false;
     }


   var release_str = get_time_string("release", "<?cs var:lang.survey_deliver_form.available_label ?>");
   var unrelease_str = get_time_string("unrelease", "<?cs var:lang.survey_deliver_form.removed_label ?>");
   var result_str = get_time_string("result", "<?cs var:lang.survey_deliver_form.result_label ?>");
   var all = release_str + "\n" + unrelease_str + "\n" + result_str;
   return window.confirm(all); 


  }




 function openBrWindow(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');
    new_window.focus();
 }
</script> 
</head>

<body>
<div>
   <a href="<?cs var:back_url ?>" title="<?cs var:lang.survey_deliver_form.back_button_title ?>">
    <img src="<?cs var:image_path ?>back_arrow.gif" width="50" height="34" alt="<?cs var:lang.survey_deliver_form.back_button_title ?>" />
   </a>
</div>

<div>
  <form  method="post" action="survey_deliver_course_list"  onsubmit="return validate_form()" >
  <div>
   <input type="hidden" name="id" value="<?cs var:id ?>" />
   <input type="hidden" name="admin" value="1" />
   <input type="hidden" name="count" value="<?cs var:count ?>" />
  </div>
 <p class="instructions" style="text-align:center" ><?cs var:lang.survey_deliver_form.instructions ?></p>
<table width="100%">
 <tr><td align="center">
  <table>

<?cs ### WHO SHOULD SEE AND BE ABLE TO TAKE THE SURVEY ### ?>

    <?cs call:print_description(lang.survey_deliver_form.who_can_take_label) ?>
    <?cs call:print_radio("taker", "all",  lang.survey_deliver_form.all_description, "0") ?> 
    <?cs call:print_radio("taker", "students",  lang.survey_deliver_form.students_description, "1") ?> 
    <?cs call:print_radio("taker", "teachers",  lang.survey_deliver_form.teachers_description, "2") ?> 
    <?cs call:print_radio("taker", "students_only",  lang.survey_deliver_form.students_only_description, "3") ?> 


<?cs ### SHOULD SUBMISSIONS LIST USER'S COURSES?    #### ?>

    <?cs call:print_description(lang.survey_deliver_form.list_courses_label) ?>
    <?cs call:print_radio("save_course", "1", lang.survey_deliver_form.yes, 1) ?>
    <?cs call:print_radio("save_course", "0", lang.survey_deliver_form.no, 0) ?>



<?cs ### WHEN SHOULD THE SURVEY BE MADE AVAILABLE?   #### ?>

    <?cs call:print_description(lang.survey_deliver_form.available_date_label) ?>
    <?cs call:print_time("release") ?>


<?cs ### WHEN SHOULD THE SURVEY BE REMOVED FROM USER PAGES? ### ?>
    <?cs call:print_description(lang.survey_deliver_form.removal_date_label) ?>
    <?cs call:print_time("unrelease") ?>


<?cs ### WHEN SHOULD YOU BE ABLE TO VIEW RESULTS?  ### ?>
    <?cs call:print_description(lang.survey_deliver_form.view_results_label) ?>
    <?cs call:print_time("result") ?>
 </table>



   <?cs call:print_search_form() ?>
</td></tr>
</table>
</form></div>
</body>
</html>
<?cs call:runtime() ?>
