function getHTTPObject() {
	var http = false;
	//Use IE's ActiveX items to load the file.
	if(typeof ActiveXObject != 'undefined') {
		try {http = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) {
			try {http = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (E) {http = false;}
		}
	//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
	} else if (XMLHttpRequest) {
		try {http = new XMLHttpRequest();}
		catch (e) {http = false;}
	}
	return http;
}

function doRating(type,id){
	var http = getHTTPObject();
	var rating = document.ratingForm.rating.value;
	var params = 'ajax=true&type='+type+'&id='+id+'&rating='+rating;
	http.open("POST", "/rate/", true);
	
	//Send the proper header infomation along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	
	http.onreadystatechange = function(){
		switch(http.readyState){
			case 4:
				if(http.status == 200){
					document.getElementById('rating').innerHTML = http.responseText;
				}else{
					document.getElementById('rating').innerHTML = 'An error occurred.';
				}
			break;
			case 3:
				document.getElementById('rating').innerHTML = 'Processing...';
			break;
		}
		//alert(http.readyState);
	}
	http.send(params);
}

function updateNowPlaying(type,id){
	var http = getHTTPObject();
	var params = 'type='+type+'&id='+id;
	http.open("POST", "/nowplaying_ajax.php", true);
	
	//Send the proper header infomation along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	
	http.onreadystatechange = function(){
		switch(http.readyState){
			case 3:
				if(http.status == 200){
					document.getElementById('np_content').innerHTML = 'Updating...';
				}else{
					document.getElementById('np_content').innerHTML = 'An error occurred.';
				}
			break;
			case 4:
				document.getElementById('np_content').innerHTML = http.responseText;
			break;
		}
	}
	http.send(params);
	
	// set auto update timer
	setTimeout("updateNowPlaying('"+type+"',"+id+")", 30*1000);
}