var II = function(item,rate,max){
	var id;
	for (var x=1;x<=rate;x++){
		id = item+'-'+x;
		document.getElementById(id).src = 'http://images.mmosite.com/gamelist/public/img/1.gif';
   }
   for(var x=(rate+1);x<=max;x++){
		id = item+'-'+x;
		document.getElementById(id).src = 'http://images.mmosite.com/news/gamelisttemp/0.gif';
   }
};
var FX = function(item,i,max){
	var id;
	// Show the selected boxes
	for (var x=1;x<=i;x++){
		id = item+'-'+x;
		document.getElementById(id).src = 'http://images.mmosite.com/gamelist/public/img/1.gif';
	}
	for(var x=(i+1);x<=max;x++){
		id = item+'-'+x;
		document.getElementById(id).src = 'http://images.mmosite.com/news/gamelisttemp/0.gif';
	}
};
var MS = function(item,rate,max){

   var MC = $('.rate'), base = "http://"+window.location.host+"/";
	if(item){
		var success = function(response, status){
			if(response == 1){
				$('.rate').update((base+'ranking/get/game_'+item+'.shtml'));
			}else{
				alert(response);
				MC.empty().setHTML('AfterBegin', '<img src="http://images.mmosite.com/gamelist/public/img/error.png" title="Unknown Error!" /> Error ...');
			}
		};
		var course = function(){
			MC.empty().setHTML('AfterBegin', '<img src="http://images.mmosite.com/gamelist/public/img/loading.gif" /> Sending ...');
		};
		var failure = function(){
			MC.empty().setHTML('AfterBegin', '<img src="http://images.mmosite.com/gamelist/public/img/error.png" title="Unknown Error!" /> Error ...');
		};
		MC.empty().setHTML('AfterBegin', '<img src="http://images.mmosite.com/gamelist/public/img/loading.gif" /> Sending ...');
		(new ThinkJS.XHR).post((base+'ranking/post.shtml?gid='+item+'&rate='+rate+'&max='+max), ('gid='+item+'&rate='+rate+'&max='+max), success, course, failure, 'text');
	}
};
var SaveComment = function(){
	var MF = $('#McComment'), MC = $('#x-say>div.x-sexy');
	var success = function(response, status){
		if(response == 1){
			$('#McComment>@input', '#McComment>@textarea').clear();
			MC.empty().setHTML('AfterBegin', '<input id="McSubmit" name="McSubmit" type="submit" value=" Submit " />');
			$('#x-wrapper').update(MF.getProperty('action')[0]);
		}else{
			MC.empty().setHTML('AfterBegin', '<input id="McSubmit" name="McSubmit" type="submit" value=" Try again " />');
		}
	};
	var course = function(){
		MC.empty().setHTML('AfterBegin', '<img src="http://images.mmosite.com/gamelist/public/img/ing.gif" /> 正在发送请求 ...');
	};
	MC.removeClass('on').empty().setHTML('AfterBegin', '<img src="http://images.mmosite.com/gamelist/public/img/ing.gif" /> 正在发送请求 ...');
	MF.submit(MF.getProperty('action')[0], success, course, null, 'text');
};

//window.onReady(function(){
//$('#x-my-favorite').on('click', function(){
//		var V = $$('@a', this).getProperty('rel', 0), T = V.split('#');
//		if(ThinkJS.def(T[1])){
//			var MC = $(this);
//			var success = function(response, status){
//				if(response == 1){
//					MC.empty().setHTML('AfterBegin', ('<a rel="'+V+'">Delete It from My List</a>'));
//					$('x-game-user').update((T[0].replace('game.shtml', 'widget/game_')+T[1]+'.shtml'));
//				}else if(response == -1){
//					MC.empty().setHTML('AfterBegin', ('<a rel="'+V+'">Add to Favorites</a>'));
//					$('x-game-user').update((T[0].replace('game.shtml', 'widget/game_')+T[1]+'.shtml'));
//				}else{
//					MC.empty().setHTML('AfterBegin', ('<a rel="'+V+'">Unknown error！</a>'));
//				}
//			};
//			var course = function(){
//				MC.empty().setHTML('AfterBegin', '<a><img src="http://images.mmosite.com/gamelist/public/img/ing.gif" /> Sending ...</a>');
//			};
//			var failure = function(){
//				MC.empty().setHTML('AfterBegin', ('<a rel="'+V+'">Unknown error！</a>'));
//			};
//			(new ThinkJS.XHR).post(T[0], ('id='+T[1]), success, course, failure, 'text');
//		}
//	});
//});

function favorite(){
	var V = document.getElementById('fav').getAttribute('rel');
	var T = V.split('#');
	MC = $('#fav');
	var success = function(response, status){
		
		if(response == 1){
				MC.empty().setHTML('AfterBegin', ('<a rel="'+V+'">Delete It from My List</a>'));
				$('x-game-user').update((T[0].replace('game.shtml', 'widget/game_')+T[1]+'.shtml'));
			}else if(response == -1){
				MC.empty().setHTML('AfterBegin', ('<a rel="'+V+'">Add to Favorites</a>'));
				$('x-game-user').update((T[0].replace('game.shtml', 'widget/game_')+T[1]+'.shtml'));
			}else{
				MC.empty().setHTML('AfterBegin', ('<a rel="'+V+'">Unknown error！</a>'));
			}
	};
	var course = function(){
		MC.empty().setHTML('AfterBegin', '<img src="http://images.mmosite.com/gamelist/public/img/loading.gif" /> Sending ...');
		//alert('course');
	};
	var failure = function(){
		MC.empty().setHTML('AfterBegin', '<img src="http://images.mmosite.com/gamelist/public/img/error.png" title="Unknown Error!" /> Error ...');
		//alert('falure');
	};
	MC.empty().setHTML('AfterBegin', '<img src="http://images.mmosite.com/gamelist/public/img/loading.gif" /> Sending ...');
	(new ThinkJS.XHR).post(T[0]+"?id="+T[1], ('id='+T[1]), success, course, failure, 'text');
}