function createXMLHTTPRequest() {
	try {	// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		xmlHttp.overrideMimeType('text/html');
	}
	catch (e) {    // Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
}

function ajaxRequest(action, parameters) {
	xmlHttp = false;
	//var urlString = buildURL(action);
	var urlString = 'index.php';
	
	switch (action) {	
		case 'showLyrics':
			urlString = "tracks/" + parameters;
			break;
			
		case 'displayShows':
			urlString = "http://artistdata.sonicbids.com/counteractive/shows/xml/future";
			break;
	}
	
	if ((urlString == '') || (parameters == '')) {
		alert('build switch case for this action');
		return false;
	}
	
	createXMLHTTPRequest();
	
	if (action == 'doLogin') {
		xmlHttp.onreadystatechange = function() {;
			if(xmlHttp.readyState == 4) {
				if (xmlHttp.status == 200) {
					action = action + '();';
					eval(action);
				}
			} else {
				var errorText = '<span class="error">Please wait...</span>';
				document.getElementById('errorArea').innerHTML = errorText;
			}
		}
	} else {
		xmlHttp.onreadystatechange = function() {;
			if(xmlHttp.readyState == 4) {
				if (xmlHttp.status == 200) {
					action = action + '();';
					eval(action);
				} 
			}
		}
	}
	
	xmlHttp.open("POST", urlString, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	//xmlHttp.setRequestHeader("Content-length", parameters.length);
	//xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
	return false;
}

function showLyrics() {
	var foundLyrics = "<p>" + nl2br(xmlHttp.responseText) + "</p>";
	var lyricsBoxControls = "<p><a href=\"javascript:HideContent('lyricsBox')\">[click to hide]</a></p>";
	document.getElementById('lyricsBox').innerHTML = lyricsBoxControls + foundLyrics + lyricsBoxControls;
	ShowContent('lyricsBox')
}

function displayShows() {
	var foundShows = "<p>" + nl2br(xmlHttp.responseText) + "</p>";
	var lyricsBoxControls = "<p><a href=\"javascript:HideContent('lyricsBox')\">[click to hide]</a></p>";
	document.getElementById('lyricsBox').innerHTML = lyricsBoxControls + foundShows + lyricsBoxControls;
	ShowContent('lyricsBox')
}

function HideContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "block";
}
function ReverseContentDisplay(d) {
	if(d.length < 1) { return; }
	if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
	else { document.getElementById(d).style.display = "none"; }
}

function nl2br(text){
	text = escape(text);
	if(text.indexOf('%0D%0A') > -1){
		re_nlchar = /%0D%0A/g ;
	}else if(text.indexOf('%0A') > -1){
		re_nlchar = /%0A/g ;
	}else if(text.indexOf('%0D') > -1){
		re_nlchar = /%0D/g ;
	}
	return unescape( text.replace(re_nlchar,'<br />') );
}
