var xmlHttp, timer;

function ajaxRequest(){
	if(timer)
		clearTimeout(timer);
	try{
		xmlHttp=new XMLHttpRequest();
	}catch(e){
		try{
			xmlHttp=new ActiveXObject("MSXML2.XMLHTTP.3.0");
		}catch(er){
			// alert("Could Not Initiate HTTPRequest!");
			return;
		}
	}
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			if(xmlHttp.status==200)
				handleRequest(xmlHttp);
			else
				handleError(xmlHttp);
		}
	};
	xmlHttp.open("GET","radio.php?song&"+Math.random(),true);
	xmlHttp.send(null);
}

function handleRequest(txt){
	if(txt.responseText)
		document.getElementById("song").innerHTML=txt.responseText;
	timer=setTimeout(ajaxRequest,5000); // 10 seconds
}

function handleError(err){
	// alert("A " + err.status + " Error Occurred.\nError Message: " + err.statusText);
	return;
}
