
	var req = new Array();
	var t;
	var lastData;
	var lastReqNum = 0;
	
	function abortPreviousReqs()
	{
		for (i=0; i<lastReqNum; i++) {
			if (req[i]) {
				if(ARSInternal == false) {
					if(req[i].parentNode) {
						req[i].parentNode.removeChild(req[i]);
					}
				}
				else {
					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();

		// Offsite requst
		if(ARSInternal == false) {
			lastReqNum++;
			req[lastReqNum] = document.createElement('script');
			req[lastReqNum].setAttribute('type', 'text/javascript');
			req[lastReqNum].setAttribute('src', ARSBase+'../xmlsearch.php?offsite=1&'+data+'&time='+(new Date()).getTime());
			document.getElementsByTagName('head')[0].appendChild(req[lastReqNum]);
			return false;
		}

		// 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, categoryName)
	{
		var	data = 'q=' + query + '&type=' + searchType + '&c=' + categoryIDs + '&cn=' + categoryName;

		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';
		}
	}

	var ARSInternal = true;
	var ARSBase = '';

	function ARS(id)
	{
		// Is this a local or remote request?
		var scripts = document.getElementsByTagName('script');
		for(var i = 0; i < scripts.length; ++i) {
			if(scripts[i].src.indexOf('ars.js') != -1) {
				if(scripts[i].src.indexOf('?crossDomain=1') != -1) {
					ARSInternal = false;
					ARSBase = scripts[i].src.replace('ars.js?crossDomain=1', '');
				}
				else {
					ARSInternal = true;
				}
			}
		}

		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();
		
		//Get the category name if the dropdown is there.
		var categoryName = "";
		if (document.getElementById("categories")) {
			var catSelObj = document.getElementById("categories");
			categoryName = catSelObj[catSelObj.selectedIndex].value;
		}

		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,'" + categoryName + "')",400);
		}
	}
