// Standard AJAX lib

function getXMLHTTPRequest () {
	try {
		req = new XMLHttpRequest ();
	} catch (err1) {
		try {
			req = new ActiveXObject ("Msxml2.XMLHTTP");
		} catch (err2) {
			try {
				req = new ActiveXObject ("Microsoft.XMLHTTP");
			} catch (err3) {
				req = false;
			} 
		} 
	}
	return req;
}

function useHttpResponse (http, divid, displaywaittimer) {
	if (http.readyState == 4) {
		if (http.status == 200) {
			document.getElementById (divid).innerHTML = http.responseText;
		} else {
			document.getElementById (divid).innerHTML = '<p>useHttpResponse: AJAX request fatal error: ' + http.status + ' updating ' + divid + '</p>';
		}
	} else if (displaywaittimer) {
		document.getElementById (divid).innerHTML = '<p class="ajaxworking"><img src="furniture/ajaxworking.gif"></p>';
	}
}

// Site-specific functions

function updateHistory () {
	var http = getXMLHTTPRequest ();
	var actionurl = 'ajaxsources/block_browsinghistory.php?s=ajax';
	randno = parseInt (Math.random () * 999999999999999);
	var modurl = actionurl + "&rand=" + randno;
	http.open ("GET", modurl, true);
	http.onreadystatechange = function () {
		useHttpResponse (http, 'browsinghistory');
	}
	http.send (null);
}
function getSearchResults (searchmode, terms) {
	var http = getXMLHTTPRequest ();
	var actionurl = 'ajaxsources/search_'+searchmode+'.php?s=ajax&search=' + terms;
	randno = parseInt (Math.random () * 999999999999999);
	var modurl = actionurl + "&rand=" + randno;
	http.open ("GET", modurl, true);
	http.onreadystatechange = function () {
		useHttpResponse (http, 'searchresults');
	}
	http.send (null);
}
function sendCarerPayment (paymentid, payday, paymonth, payyear) {
	var http = getXMLHTTPRequest ();
	var actionurl = 'ajaxsources/action_paycarer.php?s=ajax&paymentid=' + paymentid + '&payday=' + payday + '&paymonth=' + paymonth + '&payyear=' + payyear;
	randno = parseInt (Math.random () * 999999999999999);
	var modurl = actionurl + "&rand=" + randno;
	http.open ("GET", modurl, true);
	http.onreadystatechange = function () {
		useHttpResponse (http, 'paymentstatus_' + paymentid, true);
	}
	http.send (null);
}

