function xmlhttpPost(strURL, mode) {
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open('GET', strURL, true);
	try {
		self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		self.xmlHttpReq.onreadystatechange = function() {
			if (self.xmlHttpReq.readyState == 4) {
				if (mode == 0)
					updateBox(self.xmlHttpReq.responseText);
				else
					updateArtist(self.xmlHttpReq.responseText);
			}
		}
		
		self.xmlHttpReq.send('');
	} catch (e) {
		document.getElementById('ajaxbox').innerHTML = '<p>Unable to retrieve results</p>';
		document.getElementById('loading_img').src = 'loading_done.gif';
	}
}

function updateBox(str) {
	document.getElementById('loading_img').src = 'loading_done.gif';
	document.getElementById('ajaxbox').innerHTML = str;
}

function updateArtist(str) {
	document.getElementById('loading_img').src = 'loading_done.gif';
	arr = str.split('|||')
	document.getElementById('artist').innerHTML = arr[1];
	document.getElementById('albums').innerHTML = arr[0];
}

function getBox(q, st, ps) {
	document.getElementById('loading_img').src = 'loading.gif';
	xmlhttpPost('ajaxbox.asp?q=' + q + '&st=' + st + '&ps=' + ps, 0);
}

function showArtist(artist) {
	document.getElementById('loading_img').src = 'loading.gif';
	xmlhttpPost('ajaxartist.asp?artist=' + artist, 1);
}

function search_delay(element) {
	// Create a function to get the search results
	var func = function() { getBox(document.getElementById('ab_q').value, 'RhapArtist', 10); };

	// Check to see if there is already a timeout and if so...
	// ...cancel it and create a new one
	if ( element.zid ) {
		clearTimeout(element.zid);
	}
	element.zid = setTimeout(func,500);
}
