$(document).ready(function() {
	$("#btnSend").click(function(){
		$("#alert_comment").hide();
		var comment_str = $.trim($("#comment").val());
		var code = $.trim($("#code").val());
		if(comment_str==''){
			$("#alert_comment").html("Vui lòng nhập vào nội dung bình luận.");
			$("#alert_comment").show('slow');
		}else{
			var data = {'comment_value':comment_str,'code':code};
			var gameid = $("#gameid").val();
			url = '/games/comment/'+gameid+'.html';
			$.ajax({
				type:'POST',
				url: url,
				data: data,
				dataType: "json",
				success:function(json){
					msg = json.alert_msg;
					status = json.status;
					if(status == 'sended'){
						$("#alert_msg").css('color','green');
						$("#comment").val('');
						$("#code").val('');
						$("#image").attr('src','/news/security_image/'+Math.floor(Math.random()*101)+'.html');
					}else{
						$("#alert_msg").css('color','red');
					}
					$("#alert_msg").html(msg);
					goPage(1);
				}
			});
		}
	});
	
	
	goPage = function(page){
		var gameid = $("#gameid").val();
		var data = {'p':page};
		url = '/games/ajax_load_comment/'+gameid+'.html';
		$.ajax({
			type:'POST',
			url: url,
			data: data,
			dataType: "html",
			success:function(html){
				$("#comment_area").html(html);
			}
		});				
	}
	
	
});


function send_abuse(game_comment_id){
	var gameid = $("#hid_comm_game_id").val();
	var dataquery = {
		gameid:gameid,
		game_commentid:game_comment_id
	};
	url="/games/abuse/"+gameid+".html";
	$.ajax({
		type: "POST",
		url: url,
		data: dataquery,
		dataType: "json",
		success:function(json){
			$("#abuse_alert").css('border','solid 1px #FF9900');
			if(json.status == 'success'){
				$("#abuse_alert").css('background','#F9FFFE');
			}else{
				$("#abuse_alert").css('background','#FFFFCC');
			}
			$("#abuse"+json.game_commentid).html("Đã thông báo");
			$("#abuse_alert").html(json.msg);
		}
	});
}
function goPage(pg){
	curAction = document.paging_form.action;
	newAction = curAction+'/'+pg+'.html';
	alert(newAction);
	document.paging_form.action = newAction;
	document.paging_form.page.value=pg;
	document.paging_form.submit();
}