function voteEvent(matchId, eventType, eventSide, eventId) {
	var req = new Request({method: 'post', url: '/ratings/voteEvent.php', onSuccess: function(respText) {
		$$('.ev_' + eventType + '_form').each(function(el) {
			el.empty();
		});
		
		$('ev_' + eventType + eventSide + eventId + '_form').set('html', '<img src="/static/images/icon_check_on.gif" />');
		$('ev_' + eventType + eventSide + eventId + '_text').set('html', respText);
	}}).send('match_id=' + matchId + '&event_type=' + eventType + '&event_side=' + eventSide + '&event_id=' + eventId);
}

function sndReq(vote,id_num,ip_num,units) {
	$('unit_ul' + id_num).set('html', '<div class="loading"></div>');
	    
    var myRequest = new Request({method: 'get', url: '/ratings/rpc.php', onSuccess: function(respText) {
    	var update = new Array();
    	update = respText.split('|');
    	changeText(update[0], update[1]);
    }}).send('j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units);
}

function amSliceClick(chart_id, index, title, value, percents, color, description) {
	doChartVote(chart_id, title);
}

function doChartVote(chartId, value) {
	var req = new Request({method: 'post', url: '/ratings/doChartVote.php', onSuccess: function(respText) {
		$(chartId).reloadData();
	}}).send('target=' + chartId + '&value=' + value);
}

function doMomVote(matchId, playerName) {
	var req = new Request({method: 'post', url: '/ratings/doMomVote.php', onSuccess: function(respText) {
		$('chart_mom_1').reloadData();
		$('chart_mom_2').reloadData();
	}}).send('matchId=' + matchId + '&playerName=' + playerName);
}

function doTraitVote(chartId, userId, value) {
	var req = new Request({method: 'post', url: '/ratings/doTraitVote.php', onSuccess: function(respText) {
		$(chartId).reloadData();
	}}).send('user_id=' + userId + '&value=' + value);
}

function changeText( div2show, text ) {
	$(div2show).set('html', text);
}

window.addEvent('domready', function() {
	$$('a.rater').each(function(element) {
		element.addEvent('click', function() {
			var parameterString = this.href.replace(/.*\?(.*)/, "$1"); // onclick="sndReq('j=1&q=2&t=127.0.0.1&c=5');
			var parameterTokens = parameterString.split("&"); // onclick="sndReq('j=1,q=2,t=127.0.0.1,c=5');
			var parameterList = new Array();

			for (j = 0; j < parameterTokens.length; j++) {
				var parameterName = parameterTokens[j].replace(/(.*)=.*/, "$1"); // j
				var parameterValue = parameterTokens[j].replace(/.*=(.*)/, "$1"); // 1
				parameterList[parameterName] = parameterValue;
			}
			var theratingID = parameterList['q'];
			var theVote = parameterList['j'];
			var theuserIP = parameterList['t'];
			var theunits = parameterList['c'];
			
			//alert('sndReq('+theVote+','+theratingID+','+theuserIP+','+theunits+')');
			
			sndReq(theVote,theratingID,theuserIP,theunits);
			
			return false;
		});
	});
});