
	var req = new Array();
	var t;
	var lastData;
	var lastReqNum = 0;

	function abortPreviousReqs()
	{
		for (i=0; i<lastReqNum; i++) {
			if (req[i]) {
				req[i].abort();
			}
		}
	}

	function processReqChange()
	{
		// only if req shows 'loaded'
		if (req[lastReqNum].readyState == 4) {
			// only if 'OK'
			if (req[lastReqNum].status == 200) {
				hideContactSearchingIcon();
				DisplayResults(req[lastReqNum].responseText);
			}
		}
	}

	function DoCallback(data)
	{
		var url = akbPath + '/xmlsearch.php';

		lastData = data;

		abortPreviousReqs();

		// branch for native XMLHttpRequest object
		if (window.XMLHttpRequest) {
			lastReqNum++;
			req[lastReqNum] = new XMLHttpRequest();
			req[lastReqNum].onreadystatechange = processReqChange;
			req[lastReqNum].open('POST', url, true);
			req[lastReqNum].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req[lastReqNum].send(data);
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			lastReqNum++;
			req[lastReqNum] = new ActiveXObject('Microsoft.XMLHTTP')
			req[lastReqNum].onreadystatechange = processReqChange;
			req[lastReqNum].open('POST', url, true);
			req[lastReqNum].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req[lastReqNum].send(data);
		}
	}

	function SearchQuestions(query, searchType, categoryIDs)
	{
		var	data = 'q=' + query + '&type=' + searchType + '&c=' + categoryIDs;

		if (query.length > 0 && data != lastData) {
			showContactSearchingIcon();
			DoCallback(data);
		} else {
			hideContactSearchingIcon();
		}
	}

	function DisplayResults(html)
	{
		if (html) {
			document.getElementById("SearchResults").innerHTML = html;
		}
	}

	function CloseXMLDiv()
	{
		document.getElementById("SearchResults").innerHTML = '';
	}

	function hideContactSearchingIcon()
	{
		if (document.getElementById('contactImgSearching')) {
			document.getElementById('contactImgSearching').style.display = 'none';
		}
		if (document.getElementById('contactImgNotSearching')) {
			document.getElementById('contactImgNotSearching').style.display = 'inline';
		}
	}

	function showContactSearchingIcon()
	{
		if (document.getElementById('contactImgSearching')) {
			document.getElementById('contactImgSearching').style.display = 'inline';
		}
		if (document.getElementById('contactImgNotSearching')) {
			document.getElementById('contactImgNotSearching').style.display = 'none';
		}
	}

	function ARS(id)
	{
		m = document.getElementById(id);

		// Some characters seem to break submitting so lets get rid of them
		ars_query = m.value.replace(/[\s\:\&\!\,\(\)\;]+/g, " ");

		// Get rid of any 2 character or less words from what we are submitting 
		// to xmlsearch.php
		words = ars_query.split(" ");
		ars_words = new Array();

		for (i=0,num=words.length; i<num; i++) {
			if (words[i].length>2) {
				ars_words.push(words[i]);
			}
		}

		ars_query = ars_words.join(" ");

		// If the query is longer then 2 characters, send it 
		if (ars_query.length > 2) {
			if (t) {
				window.clearTimeout(t);
			}
			t = window.setTimeout("SearchQuestions(ars_query,'ars',0)",400);
		}
	}
