var suffix = window.location.host.substr(window.location.host.length-3,3)=='com'?'com':'tmc';
function getCommentsData(num,order){

	//alert($("#comment").val());
	if($("#comment").val()!=''){
		
		$.ajax({
		
			"url":"http://"+window.location.host+"/comment/getcommentsvar.shtml",
			"type":"POST",
			"data":"comment="+$("#comment").val()+"&num="+num+"&order="+order,
			"success":function(msg){
			
				//alert(msg);
				eval(msg);
				getcommentinfo(userList,conList,timeList,infoidList,diggList,buryList,fl);
				statCommentCon(total_con);
				$('span[@group="total_con"]').html(total_con+'');
				/*登入用户名*/
			}
		})	
	}
}
function getcommentinfo(userList,conList,timeList,infoidList,diggList,buryList,fl)
{
	if (userList.length<=0 || conList.length<=0)
	return ;
	var str="";
	var imgurl = "http://images.mmosite.com/www/images/newpop/";
	for (i=0;i<userList.length;i++)
	{
		str += "<table width=\"98%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"13\" height=\"15\"><img src=\""+ imgurl +"pop_01.gif\" width=\"13\" height=\"15\"><\/td><td background=\""+ imgurl +"pop_02.gif\"><\/td><td width=\"15\"><img src=\""+ imgurl +"pop_04.gif\" width=\"15\" height=\"15\"><\/td><\/tr><tr><td valign=\"top\" background=\""+ imgurl +"pop_09.jpg\"><img src=\""+ imgurl +"pop_05.gif\" width=\"13\" height=\"69\"><\/td><td height=\"50\" background=\""+ imgurl +"pop_06.gif\" valign=\"top\" class=\"comm_js_bg\"><div class=\"comm_js_conten\"><p class=\"floor\">#"+fl[i]+"</p><a href=\"javascript:quote("+infoidList[i]+")\" class=\"quote_box\">Quote</a><div class=\"comm_dig\"><a title=\"Digg\" href=\"#notop\" onClick=\"DoDigg('"+infoidList[i]+"');\"><img alt=\"digg\" title=\"digg\" src=\"http://images.mmosite.com/comment/digg.gif\" align=\"absmiddle\" border=\"0\"></a> <span id=\"diggnum_"+infoidList[i]+"\">"+diggList[i]+"</span>&nbsp;&nbsp;<a title=\"Bury\" href=\"#notop\" onClick=\"DoBury('"+infoidList[i]+"');\"><img alt=\"bury\" title=\"bury\" src=\"http://images.mmosite.com/comment/bury.gif\" align=\"absmiddle\" border=\"0\"></a> <span id=\"burynum_"+infoidList[i]+"\">"+buryList[i]+"</span>&nbsp;&nbsp;&nbsp;<\/div>"+conList[i]+"<\/div><\/td><td valign=\"top\" background=\""+ imgurl +"pop_10.jpg\"><img src=\""+ imgurl +"pop_08.gif\" width=\"15\" height=\"69\"><\/td><\/tr><tr><td valign=\"top\"><img src=\""+ imgurl +"pop_11.gif\" width=\"13\" height=\"26\"><\/td><td background=\""+ imgurl +"pop_14.gif\"><img src=\""+ imgurl +"pop_12.gif\" width=\"54\" height=\"26\"><\/td><td><img src=\""+ imgurl +"pop_16.gif\" width=\"15\" height=\"26\"><\/td><\/tr><\/table><div class=\"comm_js_title\"><em><span>"+userList[i]+" <\/span> said<\/em><p>&nbsp;&nbsp;"+timeList[i]+"<\/p><div style=\"clear:both\"><\/div><\/div>";
	}
	
	document.getElementById('commentinfoDiv').innerHTML = str;
}

function quote(val){
	document.getElementById('defind').value = val;
	document.getElementById('content').value = "[quote="+val+"]";
	document.getElementById('content').focus();
}

function getMouseXy(ev){

	var x = ev.pageX || (ev.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
	var y = ev.pageY || (ev.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
	return [x,y];
}

function isLogin(){
	
	if($("input[@name='mcflag']").val()==1){
		
		return true;
	}
	else{
		
		return false;
	}
}

function showVote(ev){
	
	if(isLogin()==false){
		
		window.location.href = "http://accounts.mmosite."+suffix+"/port/login.php?url="+escape(window.location.href);
		return false;
	}
	var xy = getMouseXy(ev);
	$("#vote_area").css({
		
		//"top":xy[1],
		//"left":xy[0],
		"display":''
	});
}


function chanagePointTotal(val){
	
	$("#vote_point").html(val);
	//showVoteDiv(true);
	$("#vote_r").attr('class','star'+val);
	
	/*变总分之后，4项小分也变*/
	var options = ['graphics','originality','gameplay','community'];
	for(i=0;i<4;i++){
		
		$("#"+options[i]+"_point").html(val+'.0');
		$("#"+options[i]+"_r").attr('class','star'+val);
	}
}

function chanagePointOption(type,val){
	
	var options = ['graphics','originality','gameplay','community'];
	var count = 0;
	for(i=0;i<4;i++){
		
		if(options[i] == type){ continue; }
		count = count+parseFloat($("#"+options[i]+"_point").html());
	}
	/*总分*/
	total_point = Math.round((count+val)*10/4)/10;
	$("#vote_point").html(total_point);//保留一个小数点
	$("#vote_r").attr('class','star'+Math.round((count+val)/4));
	
	/*选项分*/
	$("#"+type+"_point").html(val+'.0');
	$("#"+type+"_r").attr('class','star'+val);
}

function closevote(){
	
	$("#vote_area").hide();
}

function submitvote(){
	
	var totalpoint = $("#vote_point").html();
	var graphicspoint = $("#graphics_point").html();
	var originalitypoint = $("#originality_point").html();
	var gameplaypoint = $("#gameplay_point").html();
	var communitypoint = $("#community_point").html();
	var gid = $("input[@name='gid']").val();

	$.ajax({
		
		url:"http://"+window.location.host+"/game/gamevote.shtml",
		type:"get",
		data:"total="+totalpoint+"&graphics="+graphicspoint+"&originality="+originalitypoint+"&gameplay="+gameplaypoint+"&community="+communitypoint+"&gid="+gid+"&a="+Math.random(),
		success:function(msg){

			if(msg == 1){
				
				num = parseInt($("span[@group='v_num']").html());
				graphics_voted = (parseFloat($("strong[@group='gra']").html())*num+parseFloat(graphicspoint))/(num+1);
				originality_voted = (parseFloat($("strong[@group='ori']").html())*num+parseFloat(originalitypoint))/(num+1);
				gameplay_voted = (parseFloat($("strong[@group='gam']").html())*num+parseFloat(gameplaypoint))/(num+1);
				community_voted = (parseFloat($("strong[@group='com']").html())*num+parseFloat(communitypoint))/(num+1);

				$("strong[@group='gra']").html(Math.round(graphics_voted*10)/10);
				$("strong[@group='ori']").html(Math.round(originality_voted*10)/10);
				$("strong[@group='gam']").html(Math.round(gameplay_voted*10)/10);
				$("strong[@group='com']").html(Math.round(community_voted*10)/10);
				$("span[@group='v_num']").html(num+1);
				$("span[@group='v_point']").html(Math.round((graphics_voted+originality_voted+gameplay_voted+community_voted)/4*10)/10);
				//ex4optionLevel();
				alert('Success! Thanks for your vote');
				var commentContent = document.getElementById("vcontent").value;
				if(commentContent!=''){
					
					document.forms['votecomment'].submit();
				}
			}else{
				
				//alert(msg);
			}
			if(msg == 2){
				
				alert('you have already voted');
			}
			if(msg == 3){
				
				//alert('please login first');
				window.location.href = "http://accounts.mmosite."+suffix+"/port/login.php?url="+escape(window.location.href);
			}
		}
	});
	closevote();
}

function ex4optionLevel(){
	
	var options = ['gra','ori','gam','com'];
	var s = '<img  src="http://images.mmosite.com/gamelist/images/star_a.gif">';
	var c = '<img  src="http://images.mmosite.com/gamelist/images/star_b.gif">';
	var h = '<img style="position:absolute;clip:rect(0px,13px,27px,0px)" src="http://images.mmosite.com/gamelist/images/star_a.gif">';
	//$("#ii").css({"position":"absolute","clip":"rect(0px,13px,27px,0px)"});
	for(i=0;i<4;i++){
		
		var decimal;
		var point;
		point = (Math.round($("span[@group='"+options[i]+"']").html()*10/2)/10)+"";
		decimal = point.charAt(2);
		
		//alert("point:"+point.charAt(0)+"decimal:"+decimal);
		$("span[@group='"+options[i]+"level']").html(' ');
		for(j=1;j<=5;j++){
			
			if(j<=parseInt(point.charAt(0))){
				
				$("span[@group='"+options[i]+"level']").append(s);
				//完整绿星星
				continue;
			}
			if(j==(parseInt(point.charAt(0))+1)){
				
				if(decimal<=3){
					
					$("span[@group='"+options[i]+"level']").append(c);
					//白星星
				}
				if(decimal>3 && decimal<7){
					
					$("span[@group='"+options[i]+"level']").append(h);
					//半颗
				}
				if(decimal>=7){
					
					$("span[@group='"+options[i]+"level']").append(s);
					//完整
				}
				continue;
			}
			$("span[@group='"+options[i]+"level']").append(c);
		}
	}
}

function updateCommentsCount(gid){
	
	alert($('#commentsCount').html());
//	$.ajax({
//		
//		url:'http://'+window.location.host+'/comment/updateCommentCount.shtml',
//		type:'post',
//		data:'gid='+gid+'&count='+$('#commentsCount').html()
//	});
}

function favorite(id){
	
	$.ajax({
		
		"url":"http://"+window.location.host+"/favorite/game.shtml",
		"type":"get",
		"data":"id="+id,
		"success":function(msg){
			
			if(msg == 1){
				
				$(".addasfav").html("already add");
			}
			if(msg == 'nologin'){
				
				alert('please login first');
			}
		}
	})
}


function statCommentCon(commentCon){
	
	//alert(commentCon);
	$.ajax({
		
		'url':"http://"+window.location.host+"/comment/statCommentCount.shtml",
		'type':'GET',
		'data':'comment_count='+commentCon+'&gid='+$("#gid").val()
	})
}