﻿

$(document).ready(function() {
	// create dialog
	$('#subsDialog').dialog({
		modal: true,
		autoOpen: false,
		bgiframe: true,
		resizable: false,
		//width: 950,
		height: 140,
		buttons: {
			"Close": function() {
				$(this).dialog('close');
			}
		}
	});

});

function OnRatingClick(sender, gameid, tbl, displayAllVoteCount, countArea, vote) {
	var gameId = $('#' + gameid).val();
	var counts = CallService('SaveRating', "'GameId':'" + gameId + "','Rating':'" + vote + "','DisplayAllVoteCount':'" + displayAllVoteCount + "'");
	if (counts == 'MAXANON' ) {
		$('#subsDialog').dialog('open');
		return;
	}
	if (counts == 'ERROR') {
		alert('There has been an error saving your rating.');
		return;
	}

	$('#' + countArea).html(counts);

	$('#' + tbl + ' td[id*=_Up]').removeClass('vote_up_button_td');
	$('#' + tbl + ' td[id*=_Down]').removeClass('vote_down_button_td');
	$('#' + tbl + ' td[id*=_Ignore]').removeClass('vote_ignore_button_td');

	switch (vote) {
		case "U":
			$('#' + tbl + ' td[id*=_Up]').addClass('vote_up_button_td');
			break;
		case "D":
			$('#' + tbl + ' td[id*=_Down]').addClass('vote_down_button_td');
			break;
		case "G":
			$('#' + tbl + ' td[id*=_Ignore]').addClass('vote_ignore_button_td');
			break;
	}
}

// jsonData =  "'gameID':'5','ratingValue':'U'"
function CallService(method, jsonData) {
	var ret;
	if (jsonData == null) jsonData = "";
	$.ajax({
		type: "POST",
		url: "/RatingService.aspx/" + method,
		data: "{" + jsonData + "}",
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		success: function(result) {
			//			alert(msg.d);
			ret = result.d;
		},
		async: false
	});
	return ret;
}

