/*
/weblog.js from phroggy.com 5.5

(C) 2009 Andy Lyttle, all rights reserved.
This code may be distributed and modified under the terms of
the GNU General Public License.
http://phroggy.com/opensource/
*/

var searchterm='';

function updateSearch() {
	var url=document.getElementById('ajax_path').value;
	var q=document.getElementById('search_string').value;
	if(q==searchterm) return false; // prevent duplicate searches
	searchterm=q;
	// get xmlHttp object on any supported browser
	var xmlHttp;
	try {
		xmlHttp=new XMLHttpRequest(); // Firefox, Safari, Opera, etc.
	} catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer 6
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer 5.5
			} catch (e) {
				// errors fail silently
				return false;
			}
		}
	}
	// what to do when we get query results back
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			var lines=xmlHttp.responseText.split("\n");
			document.getElementById('search_status').innerHTML=lines.shift();
			document.getElementById('search_results').innerHTML=lines.join("\n");
		}
	}	
	// send the query
	xmlHttp.open("GET",url+"?q="+escape(q),true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(null);
}
