function revertStar(sn)
{
	image = "/_images/" + sn;
	document.getElementById('wxstar').style.backgroundImage = "url(" + image + ")";
}

function changeStar(sn)
{
	image = "/_images/star" + sn + ".gif";
	document.getElementById('wxstar').style.backgroundImage = "url(" + image + ")";
	<!--
	if (document.images)
	{
		pic1 = new Image(120,24); pic1.src="/_images/star1.gif";
		pic2 = new Image(120,24); pic2.src="/_images/star2.gif"; 
		pic3 = new Image(120,24); pic3.src="/_images/star3.gif"; 
		pic4 = new Image(120,24); pic4.src="/_images/star4.gif"; 
		pic5 = new Image(120,24); pic5.src="/_images/star5.gif";
	}
	//-->
}

// ##### //

// Holds an instance of XMLHttpRequest
var xmlHttp = createXmlHttpRequestObject();

// creates an XMLHttpRequest instance
function createXmlHttpRequestObject() 
{
	// will store the reference to the XMLHttpRequest object
	var xmlHttp;
	// this should work for all browsers except IE6 and older
	try
	{
		// try to create XMLHttpRequest object
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		// assume IE6 or older
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");
		
		// try every prog id until one works
		for(var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
		{
			try
			{
				// try to create XMLHttpRequest object
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch (e)
			{
				// ignore potential error
			}
		}
	}
	
	// return the created object or display an error message
	if(!xmlHttp)
	{
		alert("Error creating the XMLHttpRequest object.");
	}
	else
	{
		return xmlHttp;
	}
}

// Read a file from the server
function rateUpdate(gi,rating)
{			
	// Only continue if xmlHttp isn't void
	if(xmlHttp)
	{
		// Try to connect to the server
		try
		{
			//
			document.getElementById('wxrating').innerHTML = "<p>Submitting...</p>";
			
			// Initiate the asynchronous HTTP request
			var rand = Math.floor(Math.random()*999999);
			// alert("/ajax-rate.php?rand=" + rand + "&gi=" + gi + "&rating=" + rating);
			xmlHttp.open("GET","/ajax-rate.php?rand=" + rand + "&gi=" + gi + "&rating=" + rating,true);
			xmlHttp.onreadystatechange = handleRequestStateChangeRate;
			xmlHttp.send(null);
		}
		catch(e)
		{
			// Display the error in case of failure
			//alert("Can't connect to server:\n" + e.toString());
		}
	}
}

// Functioncalled when the state of the HTTP request changes
function handleRequestStateChangeRate()
{
	// When readystate is 4, we are ready to read the server response
	if(xmlHttp.readyState == 4)
	{
		// Continue only if HTTP status is OK
		if(xmlHttp.status == 200)
		{
			try
			{
				// Do something with the response from the server
				handleServerResponseRate();
			}
			catch(e)
			{
				// Display error message
				//alert("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// Display status message
			//alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
		}
	}
}

// Handles the response received from the server
function handleServerResponseRate()
{
	// Retrieve the server's response
	var response = xmlHttp.responseText;
	var arrayed = response.split("-");
	var rating = arrayed[0];
	var ratings = arrayed[1];
	
	// Update the stars
	image = "/_images/" + rating;
	document.getElementById('wxstar').style.backgroundImage = "url(" + image + ")";
	// Update the count
	document.getElementById('wxrating').innerHTML = "<p>" + ratings + "</p>";
	// Update the guide
	document.getElementById('wxguide').innerHTML = "<p>Thank you, your rating was counted</p>";
	// Remove buttons
	document.getElementById('wxstar').innerHTML = "&nbsp;";
		
}
