(function($){
	$.fn._get_student_result = function(data) {
		window.location = data.link+"?id="+data.result;
	}
})(jQuery);

jQuery(document).ready(function($){
	$(document).on("change blur keyup", "#surname, #student_id, #term", function(){
		
		var selector = $("#student_id").val();
		// $("#surname").val("");
		var term = $("#term").val();
		if(selector.length > 5) {
			$("#display-name-verification").html("Searching for User")
				.addClass("alert-default pt-2 pb-2 pl-2 pr-2 mt-2 mb-1")
				.removeClass("alert-success");
			$.ajax({
				type: "post",
				url: "contents/plugins/eedu_portal/ajax.php",
				data: {"action": "result_checker_get_user", "selector": selector, "term": term}
			}).done(function(data){
				try {
					data = JSON.parse(data);
					$("#display-name-verification").html(data)
				}
				catch(err) {
					console.log(err);
					$("#display-name-verification").html("User Not Found")
						.addClass("alert-warning pt-2 pb-2 pl-2 pr-2 mt-2 mb-1")
						.removeClass("alert-success");
				}
				finally{
					console.log(data);
				}
			}).fail(function(e){
				console.log(e);
				$("#display-name-verification").html("User Not Found")
					.addClass("alert-warning pt-2 pb-2 pl-2 pr-2 mt-2 mb-1")
					.removeClass("alert-success");
			})
		} else {
			$("#display-name-verification").html("")
				.removeClass("alert-success alert-warning pt-2 pb-2 pl-2 pr-2 mt-2 mb-1")
				
		}
		
	});
})