function callAjax(strURL, postStr, returnFunc) {
    var xmlHttpReq = false;
    var self = this;
    var return_str = "";
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
                return_str = returnFunc + '("'+self.xmlHttpReq.responseText+'");';
                eval(return_str);
		clearTimeout (timerid);
		timerid = setTimeout('ClearMessage()', 5000);
        }
    }
    self.xmlHttpReq.send(postStr);
}

var timerid = 0;

function RatingMessage (response) {
	var votedata = response.split('|');
	if (votedata[0] == "YES") {
		document.getElementById("RatingMessage").innerHTML = "Thanks for voting ^_^";
		var static_rater = '<div id="unit_long'+votedata[1]+'">';
		static_rater += '<ul id="unit_ul'+votedata[1]+'" class="unit-rating" style="width:150px;">';
		static_rater += '<li class="current-rating" style="width:'+votedata[2]+'px;">Currently '+votedata[3]+'/'+votedata[4]+'</li>';
		static_rater += '</ul>';
		static_rater += '<p class="voted">Rating: <strong> '+votedata[5]+'</strong>/'+votedata[4]+' ('+votedata[6]+' '+votedata[7]+' cast)</p>';
		static_rater += '</div>';
		document.getElementById("ratingblock").innerHTML = static_rater;
	} else if (votedata[0] == "BLM") {
		document.getElementById("RatingMessage").innerHTML = "Thank you for rating. The video has been deleted due to your vote.";
	} else if (votedata[0] == "MLT") {
		document.getElementById("RatingMessage").innerHTML = "You cannot vote more than once.";
	} else {
		document.getElementById("RatingMessage").innerHTML = "Fuck, a voting error.";
	}
}

function ClearMessage () {
	document.getElementById("RatingMessage").innerHTML = "";
}

function SendRating (rating, video, ip, var_c) {
	var param ="j="+rating+"&q="+video+"&t="+ip+"&c="+var_c;
	var callurl = '/rating/db.php';
	callAjax(callurl, param, "RatingMessage");
	document.getElementById("RatingMessage").innerHTML = "voting...";
}