function applySelectedInstructor(resObj, callingObj) {
	var idObj = findFormElementByName(callingObj.parentNode, "input", "instructor_id[]");
	if (resObj) {
		callingObj.value = AjaxResParam(resObj, "full_name");
		idObj.value = AjaxResParam(resObj, "id");
	} else {
		idObj.value = 0;
	}
}

function instructorList(evt) {
	evt = evt ? evt : window.event;
	ajaxList.getOptions(evt,applySelectedInstructor, '/instructor/ajax_instructor.php','getInstructorList','name_search');
}

var activeInstructorCheckObj = null;
var activeInstructorCheckValidate = null;
function instructorCheck() {
	var evt = instructorCheck.arguments[0] ? instructorCheck.arguments[0] : window.event;
	activeInstructorCheckValidate = instructorCheck.arguments[1] ? true : false;
	var callingObj = (evt.target || evt.srcElement);
	activeInstructorCheckObj = callingObj;
	if (!trim(callingObj.value)) return;
	AjaxRequest('/instructor/ajax_instructor.php', applyInstructor ,'getInstructorByName','name_search', callingObj.value);
}

function applyInstructor(resObj) {
	if ((!resObj.getElementsByTagName("instructor") || !resObj.getElementsByTagName("instructor").length) && activeInstructorCheckValidate) {
		alert("No Matching Instructors");	
		var idObj = insFinder_findFormElementByName(activeInstructorCheckObj.parentNode, "input", "instructor_id[]");
		idObj.value = 0;
		activeInstructorCheckObj.focus();
		return;
	}
	if ((!resObj.getElementsByTagName("instructor") || !resObj.getElementsByTagName("instructor").length) && activeInstructorCheckValidate) return;
	if (resObj.getElementsByTagName("instructor").length > 1) {
		alert("Multiple matches!");
		callingObj.focus();
		return;
	}
	resObj = resObj.getElementsByTagName("instructor")[0];
	var idObj = insFinder_findFormElementByName(activeInstructorCheckObj.parentNode, "input", "instructor_id[]");
	if (resObj) {
		activeInstructorCheckObj.value = AjaxResParam(resObj, "full_name");
		idObj.value = AjaxResParam(resObj, "id");
	} else {
		idObj.value = 0;
	}
}

function insFinder_findFormElementByName(thisObj, tag, sName) {
	var tagList = thisObj.getElementsByTagName(tag);
	for (var i=0; tagList[i]; i++) {
		if (tagList[i].name && tagList[i].name.toLowerCase() == sName.toLowerCase())
			return tagList[i];
	}
	return null;
}

