/*
Page:           rating.js
Created:        Aug 2006
Last Mod:       Mar 11 2007
Handles actions and requests for rating bars.
---------------------------------------------------------
ryan masuga, masugadesign.com
ryan@masugadesign.com
Licensed under a Creative Commons Attribution 3.0 License.
http://creativecommons.org/licenses/by/3.0/
See readme.txt for full credit details.
---------------------------------------------------------
*** DJH 28th April 2010:                              ***
*** 1. Altered to work with libs/ajax.js.             ***
*** 2. Changed function names to avoid clashes.       ***
*** 3. Removed apparently redundant calls to the      ***
***    behaviour.js library.                          ***
*** 4. Added milliseconds parameter to fix IE.        ***/

function sendRatingRequest(vote, id_num, ip_num, units) {
	//Grab a reference to the unordered list
	var theUL = document.getElementById('unit_ul'+id_num);
	//Switch the unordered list with a loading DIV
	if (theUL) {
		theUL.innerHTML = '<div class="loading"></div>';
	}
	//Set the name of the callback function
	httpRequest.onreadystatechange = handleRatingResponse;
	//Grab the number of milliseconds since 1st January 1970. We pass this as a parameter
	//in the URL below so that IE doesn't cache the result of the request. Without this
	//unique parameter, IE doesn't register the vote if the user casts the same vote twice
	//in succession. Firefox, of course, has no such problem.
	var currDate = new Date();
	var millsecondCount = currDate.getTime();
	//Send the HTTP request
	httpRequest.open('get', '../../../ajax/rating_bar.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units+'&unique='+millsecondCount, true);
	httpRequest.send(null);
}

function handleRatingResponse() {
	if (httpRequest.readyState==4) {
		if (httpRequest.status==200) {
			var response = httpRequest.responseText;
			var update = new Array();
			if(response.indexOf('|') != -1) {
				update = response.split('|');
				changeRatingText(update[0], update[1]);
			}
		}
	}
}

function changeRatingText(divID, responseText) {
	document.getElementById(divID).innerHTML = responseText;
}

