// All part of the Dynamic Star Rating by Jordan Boesch!
// http://creativecommons.org/licenses/by-nc-nd/2.5/ca/
// PRE-LOAD IMAGES -----------------------------

if (document.images){
  pic1 = new Image(220,19);
  pic1.src = "images/ratio/rating_loading.gif";

  pic2 = new Image(25,75);
  pic2.src = "images/ratio/rating_star.gif";

  pic3 = new Image(25,75);
  pic3.src = "images/ratio/rating_star_2.gif";

  pic4 = new Image(16,13);
  pic4.src = "images/ratio/rating_tick.gif";

  pic5 = new Image(14,14);
  pic5.src = "images/ratio/rating_warning.gif";
}

// AJAX ----------------------------------------

var xmlHttp

function GetXmlHttpObject(){

var xmlHttp = null;

	try {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp = new XMLHttpRequest();
	  }
	catch (e) {
	  // Internet Explorer
	  try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e){
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }

	return xmlHttp;

}

// Calculate the rating
function rate(rating,id,show5,showPerc,showVotes){

	xmlHttp = GetXmlHttpObject()

	if(xmlHttp == null){
		alert ("Your browser does not support AJAX!");
		return;
	  }

	xmlHttp.onreadystatechange = function(){

	var loader = document.getElementById('loading_'+id);
	var uldiv = document.getElementById('ul_'+id);

		if (xmlHttp.readyState == 4){

			//loader.style.display = 'none';
			var res = xmlHttp.responseText;

				loader.style.display = 'block';
				loader.innerHTML = '<div class="voted_twice"><a href=login.php>Login to Rate</a></div>';
		
		} else {
			loader.innerHTML = '<img src="images/ratio/rating_loading.gif" alt="loading" />';
		}

	}
	var url = "rating_process.php";
	var params = "id="+id+"&rating="+rating;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);

}