$(document).ready(function() {

	// Rating
	if($("#yourrating").is(":visible")) {
		$("#rate1").click(function() {
			$.post('gamepage.php',{ mode : 'rating', rate: 1, idgame: $("#idgame").val() },
				function(ret) {
					$("#rate1").hide();
					$("#rate2").hide();
					$("#rate3").hide();
					$("#rate4").hide();
					$("#rate5").hide();
					var splitted = ret.split("|");

					if(ret != "You need to be logged in to rate games.") {				
			$("#currentrating").css("z-index", 30);
			$("#currentrating").css("width", "13px");
			//$("#thanksrating").css("background-image", "url(../images/bg/yourrating.gif)");
	
					}
					alert(ret);
				}
			);
		});
		$("#rate2").click(function() {
			$.post('gamepage.php',{ mode : 'rating', rate: 2, idgame: $("#idgame").val() },
				function(ret) {
					$("#rate1").hide();
					$("#rate2").hide();
					$("#rate3").hide();
					$("#rate4").hide();
					$("#rate5").hide();
					var splitted = ret.split("|");

					if(ret != "You need to be logged in to rate games.") {				
	
			$("#currentrating").css("z-index", 30);
			$("#currentrating").css("width", "26px");
			//$("#thanksrating").css("background-image", "url(../images/bg/yourrating.gif)");
					}
					alert(ret);
				}
			);
		});
		$("#rate3").click(function() {
			$.post('gamepage.php',{ mode : 'rating', rate: 3, idgame: $("#idgame").val() },
				function(ret) {
					$("#rate1").hide();
					$("#rate2").hide();
					$("#rate3").hide();
					$("#rate4").hide();
					$("#rate5").hide();
					var splitted = ret.split("|");

					if(ret != "You need to be logged in to rate games.") {				
	
			$("#currentrating").css("z-index", 30);
			$("#currentrating").css("width", "39px");
			//$("#thanksrating").css("background-image", "url(../images/bg/yourrating.gif)");
					}
					alert(ret);
				}
			);
		});
		$("#rate4").click(function() {
			$.post('gamepage.php',{ mode : 'rating', rate: 4, idgame: $("#idgame").val() },
				function(ret) {
					$("#rate1").hide();
					$("#rate2").hide();
					$("#rate3").hide();
					$("#rate4").hide();
					$("#rate5").hide();
					var splitted = ret.split("|");
	
					if(ret != "You need to be logged in to rate games.") {				
	
		//	$("#currentrating").css("z-index", 30);
		//	$("#currentrating").css("width", "52px");
		//	$("#thanksrating").css("background-image", "url(../images/bg/yourrating.gif)");
					}
					alert(ret);
				}
			);
		});
		$("#rate5").click(function() {
			$.post('gamepage.php',{ mode : 'rating', rate: 5, idgame: $("#idgame").val() },
				function(ret) {
					$("#rate1").hide();
					$("#rate2").hide();
					$("#rate3").hide();
					$("#rate4").hide();
					$("#rate5").hide();
					var splitted = ret.split("|");
					if(ret != "You need to be logged in to rate games.") {				
		//				$("#currentrating").css("z-index", 30);
		//				$("#currentrating").css("width", "65px");
		//				$("#thanksrating").css("background-image", "url(../images/bg/yourrating.gif)");
					}	
					alert(ret);
				}
			);
		});
	}
	
	// Comments
	$("#sendcmm").click(function() {
		var str = $("#comment").val();
		str = jQuery.trim(str);
		if (str == "Insert your comment here" || str == "") {
			alert("Please, write a comment!");
		} else {
			$.post('gamepage.php',{ mode : 'comment', iduser: $("#iduser").val(), comment: $("#comment").val(), idgame: $("#idgame").val() },
				function(ret) {
					$("#comment").val("");
					var splitted = ret.split("|");
					alert(ret);
					//$(document).reload();
				}
			);
		}
	});
});

