
function addToPlaylist(artist, song, videoid) {
	d = document.getElementById("playlistSidebar");
	d.innerHTML = "Please wait, generating playlist...";
	addToMyPlaylist(artist, song, videoid);
}

function ajaxObject() {
	var ab;
	if (window.XMLHttpRequest) {
		ab = new XMLHttpRequest(); // For Mozilla browsers
	} else if (window.ActiveXObject) {
		ab = new ActiveXObject("Microsoft.XMLHTTP"); // For IE
		if(!ab) {
			ab = new ActiveXObject("Msxml2.XMLHTTP"); // For IE
		}
	} else {
		return false;
	}
	return ab;
}
var httpAjax = new ajaxObject();

function addToMyPlaylist(artist, song, videoid) {
	httpAjax.abort();
	requestPage = "add_to_playlist.php?artist="+artist+"&song="+song+"&videoid="+videoid;
	httpAjax.open("GET", requestPage, true);
	httpAjax.onreadystatechange = handleServerResponse;
	httpAjax.send(null);
}
function handleServerResponse() {
	d = document.getElementById("playlistSidebar");
	if(httpAjax.readyState == 4) {
		if(httpAjax.status == 200) {
			d.innerHTML = httpAjax.responseText;
			//window.alert("Added To Session"+ httpAjax.responseText);
		}
	} else {
		d.innerHTML = "Please wait, generating playlist...";
	}
}

function clearPlaylist() {
	httpAjax.abort();
	d = document.getElementById("playlistSidebar");
	d.innerHTML = "Please wait, clearing playlist...";
	requestPage = "clear_playlist.php";
	httpAjax.open("GET", requestPage, true);
	httpAjax.onreadystatechange = handleClearPlaylistResponse;
	httpAjax.send(null);
}
function handleClearPlaylistResponse() {
		d = document.getElementById("playlistSidebar");
	if(httpAjax.readyState == 4) {
		if(httpAjax.status == 200) {
			d.innerHTML = "";
		}
	} else {
		d.innerHTML = "Please wait, clearing playlist...";
	}
}

