
var http_request = false;
function grab_playlist(vSite,vSource,vTotal_History)
{
	vURL = "grab_playlist.php?site=" + vSite + "&source=" + vSource;
	http_request = false;
	if (window.XMLHttpRequest) {// Mozilla, Safari,...
		
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/plain');
		}
	} else if (window.ActiveXObject) { // IE
		try 
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}
	if ( !http_request ) {
		alert('Giving up... Cannot retrieve listings.');
		return false;
	}
	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				
				vResults = http_request.responseText;
				if ( vResults ) {
					aResults = vResults.split('|');
					//aPlaying = aResults[0].split('~');
					//vArtist = aPlaying[0];
					//vSong = aPlaying[1];
					vArtist = aResults[0];
					vSong = aResults[1];
					strPlay_1Line = '';
					strPlay_2Line = '';
					strHistory_All = '';
					if ( vSong ) {
						strPlay_1Line = vSong;
						strPlay_2Line = "<strong>" + vSong + "</strong>";
					}
					if ( vArtist ) {
						if ( strPlay_1Line ) {
							strPlay_1Line = strPlay_1Line + " - ";
							strPlay_2Line = strPlay_2Line + "<br>";
						}
						strPlay_1Line = strPlay_1Line + vArtist;
						strPlay_2Line = strPlay_2Line + vArtist;
					}
					if ( aResults.length > 2 ) {
						//aHistory = aResults[1].split('*');
						//aHistory_Total = aHistory.length;
						aHistory_Total = aResults.length;
						if ( ( aHistory_Total - 2 ) > vTotal_History ) aHistory_Total = vTotal_History + 1;
						for (i=3;i<aHistory_Total;i++) 
						{
							//strHistory_All = strHistory_All + '<div style="padding-bottom: 3px; margin-bottom: 3px; border-bottom: 1px dashed #cecece;">' + aHistory[i].substring(12) + '</div>';
							strHistory_All = strHistory_All + '<div style="padding-bottom: 3px; margin-bottom: 3px; border-bottom: 1px dashed #cecece;">' + aResults[i] + '</div>';
						}
					}
					if ( document.getElementById("play_1line") && strPlay_1Line ) {
						if ( document.getElementById("play_1line").innerHTML != strPlay_1Line ) document.getElementById("play_1line").innerHTML = strPlay_1Line;
					}
					if ( document.getElementById("play_2line") && strPlay_2Line ) {
						if ( document.getElementById("play_2line").innerHTML != strPlay_2Line ) document.getElementById("play_2line").innerHTML = strPlay_2Line;
					}
					if ( document.getElementById("history_all") && strHistory_All ) {
						document.getElementById("history_all").innerHTML = strHistory_All;
					}
				}
			} else if (http_request.status == 500) {
				//document.getElementById("test01").innerHTML = http_request.responseText;
			} else {
				//document.getElementById("test01").innerHTML = http_request.responseText;
			}
		} else {
			//document.getElementById("agent0").innerHTML = "Fetching...";
		}
	}
	http_request.open('POST', vURL, true);
	http_request.send(vURL);
}

