function sendRating()
{
	var url = "http://www.aptn.ca/myAPTN/ajax/rating.php";

	var token = document.getElementById("token");

	var post = token.getAttribute("name") + "=" + token.getAttribute("value");
	post += "&series=" + document.getElementById("series").value;
	post += "&episode=" + document.getElementById("episode").value;
	post += "&rating=" + document.getElementById("input-rating").value;
	post += "&video=" + document.getElementById("video").getAttribute("value");

	sendURIEncodedRequest(url, post, processRating);
}

function getRating()
{
	var url = "http://www.aptn.ca/myAPTN/ajax/ratingGet.php";

	var token = document.getElementById("token");

	var post = token.getAttribute("name") + "=" + token.getAttribute("value");
	post += "&series=" + document.getElementById("series").value;
	post += "&episode=" + document.getElementById("episode").value;
	post += "&rating=" + document.getElementById("input-rating").value;
	post += "&video=" + document.getElementById("video").getAttribute("value");

	sendURIEncodedRequest(url, post, processGetRating);
}

function processRating()
{
	getRequest();

	if (blnFound)
	{
		var children = dom.getElementsByTagName("rating")[0].childNodes;

		var valid = (dom.getElementsByTagName("valid")[0].firstChild.nodeValue == "yes");

		arrRequest.splice(i, 1);

		blnFound = false;

		if (valid)
			alert("You have successfully rated this video. Meegwetch.");
		else
			alert("There was an error completing your entry form.");
	}
	else if (blnError)
	{
		var result = arrRequest[i][1].getResponseHeader("Status");

		arrRequest.splice(i, 1);

		blnError = false;

		alert("There was an error processing your request.");
	}
}

function processGetRating()
{
	getRequest();

	if (blnFound)
	{
		var children = dom.getElementsByTagName("rating")[0].childNodes;

		var valid = (dom.getElementsByTagName("valid")[0].firstChild.nodeValue == "yes");

		arrRequest.splice(i, 1);

		blnFound = false;

		if (valid)
		{
			var rating = parseInt(dom.getElementsByTagName("averageRating")[0].firstChild.nodeValue);

			var anElement = document.getElementById("noRating");

			if (rating == -1)
			{
				if (anElement.firstChild != null)
					anElement.removeChild(anElement.firstChild);

				anElement.appendChild(document.createTextNode("This video does not have a rating yet."));

				r.setValue(rating);
				r.renderStars(0, true);
			}
			else
			{
				if (anElement.firstChild != null)
					anElement.removeChild(anElement.firstChild);

				r.setValue(rating);
				r.renderStars(rating, true);

				var stringRating = "";

				for (var x = 0; x < rating; x++)
					stringRating += "* ";
			}
		}
		else
		{
			alert("There was an error retrieving the rating.");
		}
	}
	else if (blnError)
	{
		var result = arrRequest[i][1].getResponseHeader("Status");

		arrRequest.splice(i, 1);

		blnError = false;

		alert("There was an error processing your request.");
	}
}
