
if (document.images){
  pic1 = new Image(220,19); 
  pic1.src = "img/rating_loading.gif"; 

  pic2 = new Image(25,75); 
  pic2.src = "img/rating_star.gif"; 

  pic3 = new Image(25,75); 
  pic3.src = "img/rating_star_2.gif"; 
  
  pic4 = new Image(16,13); 
  pic4.src = "img/rating_tick.gif";
  
  pic5 = new Image(14,14); 
  pic5.src = "img/rating_warning.gif";
}

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,resc_id,myid){

	xmlHttp = GetXmlHttpObject()
	
	if(xmlHttp == null){
		alert ("Your browser does not support AJAX!");
		return;
	}

	xmlHttp.onreadystatechange = function(){
		
	var loader = document.getElementById('loading_'+resc_id);
	var uldiv = document.getElementById('ul_'+resc_id);
	
		if (xmlHttp.readyState == 4){ 
			
			//loader.style.display = 'none';
			var res = xmlHttp.responseText;
		
			loader.style.display = 'block';
			loader.innerHTML = '<IMG SRC="img/rating_tick.gif"> Thanks!';

			var newPerc = res*20;
			var ulRater = document.getElementById('rater_'+resc_id);
			ulRater.className = 'star-rating2';
		
			var all_li = ulRater.getElementsByTagName('li');
		
			// start at 1 because the first li isn't a star
			for(var i=1;i<all_li.length;i++){
			
				all_li[i].getElementsByTagName('a')[0].onclick = 'return false;';
				all_li[i].getElementsByTagName('a')[0].setAttribute('href','#');
			
			}
		
			if(navigator.appName == 'Microsoft Internet Explorer'){
				uldiv.style.setAttribute('width',newPerc+'%'); // IE
			 } else {
				uldiv.setAttribute('style','width:'+newPerc+'%'); // Everyone else
			 }
		} else {
			loader.innerHTML = '<img src="img/rating_loading.gif" alt="loading" />';	
		}
	
	}
	var url = "rating_process.php";
	var params = "id="+resc_id+"&rating="+rating+"&userid="+myid;
	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);

} 


function reportbroken(resc_id) {
  xmlHttp = GetXmlHttpObject()
  xmlHttp.onreadystatechange = function(){
	document.getElementById("bbnoptrow"+resc_id).innerHTML="Thanks for reporting! We will look into it.";
  } 
  var url = "storebreakage.php";
  var params = "id="+resc_id;
  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);
}