function check_key(event) {
	console.log(event);
	if (evnet.keyCode == 13) {
		do_search();
	}
} 



var ajax = false;
if(window.XMLHttpRequest) ajax = new XMLHttpRequest();
else if(window.ActiveXObject) {
	try { ajax = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) {
		try { ajax = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch (e) {}
	}
}

function ajaxGetContent(type, url, parameter, output_function) {
	if(!ajax) eval(output_function + '(false);');
	ajax.onreadystatechange = function() {
		if(output_function != 'void' && ajax.readyState == 4) {
			if(ajax.status == 200) eval(output_function + '(ajax.responseText);');
			else eval(output_function + '(false);');
		}
	}
	if(type == "post") {
		ajax.open('POST', url, true);
		ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		ajax.send(parameter);
	} else {
		ajax.open('GET', url + ((parameter.length > 0)?"?":"") + parameter, true);
		ajax.send(null);
	}
}




function search_cb(res) {
	if(res == false) {
		document.getElementById('books-list').innerHTML = '<li>No result</li>';
		document.getElementById('labeled').style.display = 'none';
	} else {
		document.getElementById('books-list').innerHTML = res;
		document.getElementById('labeled').style.display = 'none';
	}
}


function do_search() {
	term = escape(document.getElementById('search_term').value.replace(' ','+'));
	ajaxGetContent('get', 'search.php', 'q='+term, 'search_cb');
}
