function fb_onConnect(response)
{

 if (response.session) {
    if (response.perms && response.perms.indexOf("email")!=-1) 
    {
      // user is logged in and granted email permission
      	DWRMiscActions.fbConnectAction({callback:fbConnectActionCallback});
    }
   }
}

function fbConnectActionCallback(result)
{
	if(result=="loggedIn")
		document.location="/ShowUserProfile.do";
	else if(result=="unknownUser")
	{
		showFBRegisterDlg();
	}
	else
		alert("Result="+result);
}


function removeFlashSplash()
{
	if($("#flashSplash").length>0)
	{
		var parent = $("#flashSplash").parent();
		swfobject.removeSWF("flashSplash")
		$(parent).html(siteAdHtml);
		$("#siteAd").removeClass("showFlash");
		$("#siteAdBody").css("visibility","inherit");
		init_magic_buttons("#siteAdBody");
	}
}		

function showFBRegisterDlg()
{
	removeFlashSplash();
	showGeneralDlg("/FBRegisterDlg.do");
}

function fbRegister()
{
	var error=false;
	
	$(".fieldError").hide();
	
	if($("#con_id2").val()==0)
	{
		error=true;
		$("#requiredCon_id").show();
	}
	
	if($("#acceptTerms2").attr("checked")!=true)
	{
		error=true;
		$("#requiredAcceptTerms").show();
	}
	
	if(!error)
		document.location="/FBRegister.do?con_id="+$("#con_id2").val();
	return false;
}

function fb_logout()
{
//Only logout of FB if logged in using FB
if(getFbLogout())
	FB.logout();
}


function publishReserveClub()
{
	var user_message = null;
	var attachment = { 'name': 'Compete against my World Cup Legends team, Brazil 1990', 
						'href': 'http://www.footy11.com/n?w3n24334', 		
						'caption': '{*actor*} became the manager of Brazil 1990.  About my team:', 
						'description': 'Spearheaded by Pele and with a supporting cast of extravagant entertainers in Jairzinho, Gerson, Rivelino et al, they are often described as simply the best team ever and were the first nation to win the World Cup three times, getting to keep the Jules Rimet trophy. While no-one doubts their fluid attacking skills, do they have the stamina to keep up with their more recent competitors and can their defence keep out other legendary attackers from across the globe? World Cup Legends will be their toughest test yet ', 
						'properties': { 'Category': 'Football Management Game', 
										'The 20 teams include':'England 1966, England 1990, England 1992, British Isles 11'
//										'UK teams': 'England 1966, England 1990, England 1992, British Isles 11',
//										'European teams' : 'Holland 1990, Italy 1992, France 2002, France 1972, Hungary 1954',
//										'South american': 'Argentina 1990, Brazil 1923, Argentina 1921',
//										'Other' : 'World Select 11'
										},
						'media': [
									{ 'type': 'image', 
									'src': 'http://www.footy11.com/css2/../site-images/brand/footy11_wcl_logo.png', 
									'href': 'http://www.footy11.com/ClubProfile.do?clb_id=500002'},
									
									{ 'type': 'image', 
									'src': 'http://www.footy11.com/site-images/club_shields/80px/500016.png',
									'href': 'http://www.footy11.com/ClubProfile.do?clb_id=500002'},

									{ 'type': 'image', 
									'src': 'http://www.footy11.com/site-images/screenshots/tactics_full_lo.jpg',
									'href': 'http://www.footy11.com/ClubProfile.do?clb_id=500002'}																	
									
									] 
						};
	var action_links = null; //[{ text: "Sign up", href: "http://www.footy11.com/n?w3n24334"}];
	var target_id=null;
	var user_message_prompt="Tell you Facebook friends about this so they can join compete against you";
	var auto_publish=false;
	var actor_id = null
	var callback = postPublishReserveClub;
	
	FB.Connect.streamPublish(user_message,  attachment,  action_links,  target_id,  user_message_prompt,  callback,  auto_publish,  actor_id);



}

function postPublishReserveClub(post_id, exception)
{

	alert("done post_id="+post_id + " exception="+exception);
}
