var rating;
var starNumber;

/**
* Rates the quote via AJAX
*
* @param	object	The event that was fired
* @param	integer	What to rate the quote (-1-5)
* @param	integer	The quote's ID
*
*/
function rateQuote(e, rating, quoteId) {
	do_an_e(e);
	var submitString = 'do=rate&quoteid=' + quoteId + '&vote=' + rating;

	try {
		var agent = new vB_AJAX_Handler(true);
		agent.onreadystatechange(function() {
				if (checkAgentStatus(agent)) {
					var results = agent.handler.responseText.split("\t");
					var statsObjects = fetchObjectDupes('stats' + quoteId);
					var i = 0;
					while (statsObjects[i]) {
						statsObjects[i].innerHTML = quotes_phrase_total + ': ' + results[0] + ' - ' + quotes_phrase_votes + ': ' + results[1] + ' - ' + quotes_phrase_average + ': ' + results[2];
						i++;
					}

					var ratingObjects = fetchObjectDupes('rating' + quoteId);
					i = 0;
					while (ratingObjects[i]) {
						ratingObjects[i].innerHTML = quotes_phrase_you_rated_this + results[3];
						i++;
					}
				}
		});
		agent.send('quotes.php', submitString + '&ajax=y');
	}
	catch (error) {
		window.location.href = 'quotes.php?' + SESSIONURL + submitString;
	}
}

/**
* Highlights the stars in 1 to 5 rating mode
*
* @param	integer	The quote's ID
* @param	integer	Number of the star currently hovered over
* @param	integer	The quote's unique BBCode id (the value of $globalcounter)
*
*/
function fillStars(quoteId, starNumber, uniqueId) {
	if (!is_regexp) {
		return false;
	}

	var starSource = fetch_object('star1-' + quoteId + '-' + uniqueId).src;
	starSource = starSource.replace(/star-empty\.gif$/i, 'star-filled.gif');
	var i = 1;

	while (i <= starNumber) {
		fetch_object('star' + i + '-' + quoteId + '-' + uniqueId).src = starSource;
		i++;
	}
}

/**
* Unhighlights all stars for a particular quote
*
* @param	integer	The quote's ID
* @param	integer	The quote's unique BBCode id (the value of $globalcounter)
*
*/
function emptyStars(quoteId, uniqueId) {
	if (!is_regexp) {
		return false;
	}

	var starSource = fetch_object('star1-' + quoteId + '-' + uniqueId).src;
	starSource = starSource.replace(/star-filled\.gif$/i, 'star-empty.gif');

	fetch_object('star2-' + quoteId + '-' + uniqueId).src = starSource;
	fetch_object('star3-' + quoteId + '-' + uniqueId).src = starSource;
	fetch_object('star4-' + quoteId + '-' + uniqueId).src = starSource;
	fetch_object('star5-' + quoteId + '-' + uniqueId).src = starSource;
}