 function updateRating() {

	 	try{
    if((http.readyState == 4)&& (http.status == 200)){
        var response = http.responseText;

	 		//alert(response); DEBUG

	var resp_arr = response.split("||");
			if (resp_arr[0] == 'ERR') {
				alert(resp_arr[1]);
			}

			if (resp_arr[0] == 'OK') {
				var type = resp_arr[1];
				var id = resp_arr[2];
				var total = parseInt(resp_arr[3]);
        var count = parseInt(resp_arr[4]);

          var theUL = document.getElementById('rater_ul'+type+id); // the UL
          if (theUL) { theUL.innerHTML = '<li id="rater_li'+type+id+'" class="current-rating" style="width:0px"></li>'; }
                                updatePage(type,id,total,count);
			}


	}
    }

catch(e){
}
finally{}
			// alert(request.responseText);  // DEBUGGING 
		
}


 function updateComments() {

	 	try{
    if((http.readyState == 4)&& (http.status == 200)){
        var response = http.responseText;

	 		//alert(response); DEBUG

	var resp_arr = response.split("||");
	
				var type = resp_arr[1];
				var id = resp_arr[2];
          var theDIV = document.getElementById('comments_'+type+'_'+id); // the UL
			if (resp_arr[0] == 'ERR') {
				 if (theDIV) { theDIV.innerHTML = resp_arr[3]; }
			}

			if (resp_arr[0] == 'OK') {
				

          if (theDIV) { theDIV.innerHTML = resp_arr[3]; }
			}


	}
    }

catch(e){
}
finally{}
			// alert(request.responseText);  // DEBUGGING 
		
}



function createRequestObject() {  //Get the right xmlHTTP, including IE, FF and Opera, try and catch for errors error catching
	var xmlhttp;
try
    {
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(f)
        {
             xmlhttp=null;
        }
    }
    if(! xmlhttp&&typeof XMLHttpRequest!="undefined")
    {
         xmlhttp=new XMLHttpRequest();
    }
	return  xmlhttp;
}
var http = createRequestObject(); //make the AJAX thingy
var timeoutholder=null; //this variable holds the timeouts which wait between keypresses


function sndReq(type, id, rate) { //this function asks for the functions

	em=escape(id);  //escape for URLs
try{
    http.open('get', 'comment.php?prid='+id+'&type='+type+'&rate='+rate);  //sends request
    http.onreadystatechange = updateRating; //ensures the response is handled by the correct function
    http.send(null);}
	catch(e){}
	finally{}

}

function sndReqComments(type, id, comment, email, name) { //this function asks for the functions

	em=escape(id);  //escape for URLs
try{
    http.open('get', 'comment.php?prid='+id+'&type='+type+'&comment='+comment+'&email='+email+'&name='+name);  //sends request
    http.onreadystatechange = updateComments; //ensures the response is handled by the correct function
    http.send(null);}
	catch(e){}
	finally{}

}
function handleResponse() {

}
function rate(type,id,rate){ //Sets a timeout waiting to look up but cancels it if another key is pressed within 0.4 secs
 var theUL = document.getElementById('rater_ul'+type+id); // the UL
           if (theUL) { theUL.innerHTML = '<div class="loading"></div>'; }
								if(timeoutholder!=null)window.clearTimeout(timeoutholder);
	timeoutholder=window.setTimeout("sndReq(\'"+type+"\',\'"+id+"\',\'"+rate+"\');", 0);
}

function comment(type,id){ //Sets a timeout waiting to look up but cancels it if another key is pressed within 0.4 secs
var comment=String('comment_' + type + '_' + id + '');
var commentValue=document.getElementById(comment).value;
var email=String('email_' + type + '_' + id + '');
var emailValue=document.getElementById(email).value;
var name=String('name_' + type + '_' + id + '');
var nameValue=document.getElementById(name).value;
if(commentValue=="Komentar:" || emailValue=="Email:" || nameValue=="Ime:"){
alert("Molimo Vas popunite sva tri polja");
return false;
}
 var theUL = document.getElementById('comments_'+type+'_'+id); // the UL
           if (theUL) { theUL.innerHTML = '<div class="loading"></div>'; }
								if(timeoutholder!=null)window.clearTimeout(timeoutholder);
	timeoutholder=window.setTimeout("sndReqComments(\'"+type+"\',\'"+id+"\',\'"+commentValue+"\',\'"+emailValue+"\',\'"+nameValue+"\');", 0);
}


function updatePage (type,id,total,count) {
                        var avg = Math.round(((total)/(count))*10)/10;
                        var new_width =  Math.round(avg / 5 * 150);
                        var span_avg = document.getElementById("ajaxrating_" + type + "_" + id + "_avg");
                        if (span_avg) {span_avg.innerHTML = avg; }
                        var span_ttl = document.getElementById("ajaxrating_" + type + "_" + id + "_ttl");
                        if (span_ttl) {span_ttl.innerHTML =  total + r; }
                        var span_cnt = document.getElementById("ajaxrating_" + type + "_" + id + "_cnt");
                        if (span_cnt) {span_cnt.innerHTML =  count; }
                        var rater_li = document.getElementById("rater_li" + type +  id);
                        if (rater_li) {rater_li.style.width =  new_width.toString() + "px"; }
                        var thumb = document.getElementById("thumb" + type +  id);
                        if (thumb) {thumb.innerHTML =  ""; }
                        var thanks = document.getElementById("thanks" + type +  id);
                        if (thanks) {thanks.innerHTML =  "Hvala na glasanju!"; }
}


