function star_on(star) {
	// get picture id
	var picid = star.id.substr(0, star.id.indexOf('_'));

	// get stars
	var stars = new Array(5);
	for (i = 0; i != 5; i ++)
		stars[i] = document.getElementById(picid+"_"+(i+1));
	
	total = parseInt(star.id.substr(star.id.indexOf('_')+1,1));

	for (i = 0; i != 5; i++)
		if (i < total)
			stars[i].className = "on";
		else
			stars[i].className = "off";
}

function star_off(star) {
	var picid = star.id.substr(0, star.id.indexOf('_'));
	for (i = 0; i != 5; i ++)
		document.getElementById(picid+"_"+(i+1)).className = "off";
}

var xmlhttp;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
	alert("Your browser does not support XMLHTTP!");
}

function get_rating(rating)
{
	return rating.substring(rating.indexOf('_') + 1);
}

function get_picid(rating)
{
	return rating.substring(0, rating.indexOf('_'));
}

function ratepic(rating) {
	xmlhttp.open("POST", "ratepic.php", true);
	var params = "p="+get_picid(rating.id)+"&r="+get_rating(rating.id);
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			alert(xmlhttp.responseText);
			if (xmlhttp.responseText.indexOf("Sorry") == -1)
				location.reload(true);
		}
	}

	xmlhttp.send(params);
}