// JavaScript Document
//Create a boolean variable to check for a valid Internet Explorer instance.
var xmlhttp = false;
//Check if we are using IE.
try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.6.0") }catch(e){}
try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0") }catch(e){}
try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP") }catch(e){}
try{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP") }catch(e){ xmlhttp = false;}

//If we are using a non-IE browser, create a javascript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp = new XMLHttpRequest();
}


function updateRating(id, value) {
	/*
	var i = 1;
	while (document.getElementById('rate_'+ i)) {
				document.getElementById('rate_'+i).disabled = true;
				i++;
	}
	*/
	xmlhttp.open("GET", '/js/vote.php?id='+id+'&rating='+value, true);
	xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {			
				var result = xmlhttp.responseText;
				rating = result.split("=");
				
				document.getElementById('result').innerHTML = (rating[0]/rating[1]).toFixed(2) + 
																											'<span style="font-size: 0.7em;"> ('+ rating[1] +' votes)</span>';
				document.getElementById('numOfVotes').innerHTML = rating[1];
				document.getElementById('thank_you_for_rating').innerHTML = "Thank you!";
				document.getElementById('your_rating').innerHTML = "Your rating: " +  value;
				document.getElementById('your_rating').style.display = 'inline';
		}
	}
	xmlhttp.send(null);
}