Index: admin/reset_courses.php
===================================================================
--- admin/reset_courses.php	(revision 456)
+++ admin/reset_courses.php	(revision 458)
@@ -3,12 +3,13 @@
  * This allows you to reset more than one course at a time.
  * Hacked from /course/reset.php
  * Chris Fryer <c.j.fryer@lse.ac.uk> 27/08/2008
+ * Lei Zhang <lei.zhang@canterbury.ac.nz> 30/04/2010 add ajax function to choose courses.
  */
 
 require('../config.php');
 require_once("$CFG->libdir/adminlib.php");
 require_once('reset_courses_form.php');
+require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_animation', 'yui_datasource', 'yui_autocomplete'));
 
 admin_externalpage_setup('resetcourses');
 
@@ -28,13 +29,22 @@
 
 if ($mform->is_cancelled()) {
    	redirect($CFG->wwwroot.'/admin/index.php', '' , 0);

 } else if ($data = $mform->get_data(false)) { // no magic quotes
 
+	$names = explode(",", $data->courseids);
+	$ids = array();
 	$errors = array();
 	$counter = 0;
-	foreach ($data->courseids as $id) {
 	
+	foreach ($names as $course) {
+		$course = trim($course);
+		if(!empty($course)) {
+			array_push($ids, array_search($course, $mform->all_courses()));
+		}
+	}
+
+	foreach ($ids as $id) {
 		set_time_limit(30); // Should be enough for each course
 
 		$data->id = clean_param($id, PARAM_INT);
@@ -85,6 +95,37 @@
 } 
 
 $mform->display();
+//var_dump($mform->all_courses());
+//foreach ($mform->all_courses() as $key=>$value){ echo "[id:'$key',course: '$value'],";}
+$courses = array();
+ foreach ($mform->all_courses() as $key=>$name) { 
+	$n=0;
+	while(isset($courses[$name.($n?"[$n]":'')])) {$n++;}
+	$courses[$name.($n?"[$n]":'')] = '{course: "'.$name.'", id: "'.$key.'"}';
+ } 
+?>
+<script type="text/javascript">
+	courses = [<?php echo implode(',', $courses); ?>];
 
+	YAHOO.example.ItemSelectHandler = function() {
+	    // Use a LocalDataSource
+	    var oDS = new YAHOO.util.LocalDataSource(courses);
+	    oDS.responseSchema = {fields : ["course", "id"]};
+
+	    // Instantiate the AutoComplete
+	    var oAC = new YAHOO.widget.AutoComplete("id_courseids", "myContainer", oDS);
+	    oAC.prehighlightClassName = "yui-ac-prehighlight";
+	    oAC.useShadow = true;
+	    oAC.queryDelay = 0;
+		oAC.delimChar = ",";		
+		
+	    return {
+	        oDS: oDS,
+	        oAC: oAC
+	    };
+	}();
+</script>
+
+<?php
 admin_externalpage_print_footer();
-?>
+?>
\ No newline at end of file
Index: admin/reset_courses_form.php
===================================================================
--- admin/reset_courses_form.php	(revision 456)
+++ admin/reset_courses_form.php	(revision 458)
@@ -2,20 +2,24 @@
 require_once $CFG->libdir.'/formslib.php';
 
 class admin_course_reset_form extends moodleform {
+	
+	function all_courses() {
+		$courses = array();
+        foreach (get_courses('all', 'c.shortname ASC', 'c.id, c.shortname') as $course) {
+            if ($course->id == 1) continue; // Do not allow the site (i.e. front page) to be reset here.
+            $courses[$course->id]  = trim($course->shortname);
+        }
+		return $courses;
+	}
+	
     function definition (){
         global $CFG;
 
         $mform =& $this->_form;
-		
-        $courses = array();
-        foreach (get_courses('all', 'c.shortname ASC', 'c.id, c.shortname') as $course) {
-            if ($course->id == 1) continue; // Do not allow the site (i.e. front page) to be reset here.
-            $courses[$course->id]  = $course->shortname;
-        }
 
         $mform->addElement('header', 'coursesheader', get_string('courses'));
-        $mform->addElement('select', 'courseids', 'Select courses to be reset', $courses, array('multiple' => 'multiple')); //FIXME for i18n
-
+		$mform->addElement('text', 'courseids', 'Courses to be reset', array('size' => 50, 'maxlength' => 255)); //FIXME for i18n
+		$mform->addElement('html', '<div id="myContainer"></div>');
         $mform->addElement('header', 'generalheader', get_string('general'));
 
         $mform->addElement('date_selector', 'reset_start_date', get_string('startdate'), array('optional'=>true));
@@ -92,7 +96,7 @@
         }
 
         $buttonarray = array();
-        $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('resetcourse').'s');
+        $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('resetcourse').'s', 'onClick="setValue();"');
 //      $buttonarray[] = &$mform->createElement('submit', 'selectdefault', get_string('selectdefault'));
 //      $buttonarray[] = &$mform->createElement('submit', 'deselectall', get_string('deselectall'));
         $buttonarray[] = &$mform->createElement('cancel');
Index: theme/uc_standard/styles.css
===================================================================
--- theme/uc_standard/styles.css	(revision 456)
+++ theme/uc_standard/styles.css	(revision 458)
@@ -572,39 +572,72 @@
 .audiorecording_files {float:left;}
 
+ /**
+* Autocomplete style for admin/reset_courses.php
+ **/
+
+#mform1 .yui-ac {
+	position:relative;
+	width:60em;/*  set width here or else widget will expand to fit its container */
+    padding-bottom:3em;
+}
+#mform1 .yui-ac-input {
+	position:absolute;
+}
+#mform1 .yui-ac-container {
+	position:absolute;
+	top:2em;
+	width:50%;
+	left:19em;
+}
+#mform1 .yui-ac-content {
+	position:absolute;
+	width:100%;
+	border:1px solid #808080;
+	background:#fff;
+	overflow:hidden;
+	z-index:9050;
+}
+
+#mform1 .yui-ac-shadow {
+	position:absolute;
+	margin:.3em;
+	width:100%;
+	background:#000;
+	-moz-opacity:.10;
+	opacity:.10;
+	filter:alpha(opacity=10);
+	z-index:9049;
+}
+
+#mform1 .yui-ac iframe {
+	opacity:0;
+	filter:alpha(opacity=0);
+	padding-right:.3em;
+	padding-bottom:.3em;
+}
+
+#mform1 .yui-ac-content ul {
+	margin:0;
+	padding:0;
+	width:100%;
+}
+
+#mform1 .yui-ac-content li {
+	margin:0;
+	padding:2px 5px;
+	cursor:default;
+	white-space:nowrap;
+	list-style:none;zoom:1;
+}
+
+#mform1 .yui-ac-content li.yui-ac-prehighlight {
+	background:#B3D4FF;
+}
+
+#mform1 .yui-ac-content li.yui-ac-highlight {
+	background:#426FD9;
+	color:#FFF;
 }
\ No newline at end of file
