var APPCONTEXT = "/gp";

function goGame(elem,seo) {
	top.window.document.location.href = APPCONTEXT+'/showGame.do?id_game=' + elem + seo;
}

/**
 * selected_tab: avvisi_tab tornei_tab amici_tab giochi_tab record_tab
 */
$(document).ready(function(){
	
	// Gestione tab
	var current_tab = 'avvisi_tab';
	if(selected_tab != '')
		current_tab = selected_tab;
	
	viewTab(current_tab);
	
	$('.tab_link').each(function (){
		$(this).click(function(){
			viewTab(this.id);
			return false;
		});
	});
	
	
	//Setup links badge e giochi
	$('.sp_user').each(function(item){
		$(this).click(function(){
			var userId = $(this).attr("id_user");
			popupPlayer(userId);
		});
	});
	$('.sp_game').each(function(item){
		$(this).click(function(){
			var gameId = $(this).attr("id_game");
			top.document.location.href='/gp/showGame.do?id_game='+gameId;
		});
	});
});


function viewTab(current_tab){
	$('.tab_link').each(function (){
		var tabName = this.id.substring(0,(this.id.length-4));
		$(this).css('backgroundImage','url('+APPCONTEXT+'/images/es/profile/wall/' + tabName +'_off.jpg)');
		$('#'+tabName+'_content').css('display','none');
	});
	
	if(current_tab == 'bloccati_tab'){
		var subsection = current_tab;
		current_tab = 'amici_tab';
		switchSections('blackList');
	}
	
	var activeTabName = current_tab.substring(0,(current_tab.length-4));
	$('#'+current_tab).css('backgroundImage','url('+APPCONTEXT+'/images/es/profile/wall/' + activeTabName +'_on.jpg)');
	$('#'+activeTabName+'_content').fadeIn("fast");
	
};

function sendUserDescription(formDesc,callFunc) {
  var errorStr = "Si &egrave; verificato un errore nella richiesta";
  $.post(APPCONTEXT+"/webService.do?dispatch=saveUserDesc",
  			 {id:formDesc.id.value, description:formDesc.description.value},
  			 function(data, textStatus) {
  			  var res = ""; 
          $(data).find("result").each(function(){res = $(this).text();});   
          if (res == "ok")
           callFunc();
          else
           fuepsAlert(errorStr);
  			 }
        );
}

