var browser = navigator.appName;
function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

var httpa;


function setrating(val,id)
{
	
	httpa = createRequestObject(); 
	var str="addrating.php?scrapid="+id+"&value="+val;
	httpa.open('get', str);
	httpa.onreadystatechange = handleResponse;
	httpa.send(null);
}

function handleResponse() {
	if(httpa.readyState == 4){
		var response = httpa.responseText;
	    if(response==1)
	    {
		 alert("Your rating has been accepted"); 
		 document.getElementById('up').src="images/thumbs-up1.gif";
		 document.getElementById('down').src="images/thumbs-down1.gif";
		}
		else if(response==0){
		 alert("Your rating is already present in the database");
	    }
		else if(response==-1){
	     alert("You cannot rate your own scrap");
		}	
	}
}
