function onFBConnected(user_id) {
FB.init("f188b40cbd42d80ece1f226c183c195b","xd_receiver.html"); 
document.getElementById('fb_login_box').innerHTML = '<fb:profile-pic uid="'+user_id+'" size="square" linked="true" />';
document.getElementById('fb_login_box').innerHTML += '&nbsp;&nbsp;Ciao&nbsp;<b><fb:name uid="'+user_id+'" useyou="false" firstnameonly="true" linked="false"></fb:name></b>&nbsp;|&nbsp;';
document.getElementById('fb_login_box').innerHTML += '<a href="javascript:popup_fb_invita(\'http://www.vainvacanza.it/fb/fbc/fb_invita.php\',\'fbinvita\',\'600\',\'640\',\'center\',\'front\');">Invita</a>&nbsp;|&nbsp;';
document.getElementById('fb_login_box').innerHTML += '<a href="#" onClick="FB.Connect.logout()">Esci da Facebook</a><br>';
 
FB.Facebook.apiClient.users_hasAppPermission("publish_stream",function(hasPermission) {
if (hasPermission == 0) {

 FB.Connect.showPermissionDialog(
    "publish_stream,offline_access,email,create_event",   // permission name(s)
    function(perms) {
   if (!perms) {
     alert("Attenzione!<br> Per un corretto funzionamento è necessario concedere tutti i permessi all'applicazione.<br>");
   }
   },false);
}
});

FB.init("f188b40cbd42d80ece1f226c183c195b","xd_receiver.html"); 


} 
 
function onFBNotConnected() {


 FB.init("f188b40cbd42d80ece1f226c183c195b","xd_receiver.html"); 
document.getElementById("fb_login_box").innerHTML = "<fb:login-button v=\"2\" size=\"large\">Accedi con Facebook</fb:login-button>";
FB.init("f188b40cbd42d80ece1f226c183c195b","xd_receiver.html");
}


var popup_fb_invitaWindow=null;
function popup_fb_invita(mypage,myname,w,h,pos,infocus){

if (pos == 'random')
{LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
else
{LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';popup_fb_invitaWindow=window.open('',myname,settings);
if(infocus=='front'){popup_fb_invitaWindow.focus();popup_fb_invitaWindow.location=mypage;}
if(infocus=='back'){popup_fb_invitaWindow.blur();popup_fb_invitaWindow.location=mypage;popup_fb_invitaWindow.blur();}

}


function pubaforismasufb(attachment, action_link) {
  FB.ensureInit(function () {
	//streamPublish(String user_message,  Object attachment,  Object action_links,  String target_id,  String user_message_prompt,  Function callback,  Boolean auto_publish,  String actor_id)
	FB.Connect.streamPublish('Mi piace!', attachment, action_link,null,'Ti piace?',on_pubaforismasufb,true);
  });
  
}

function on_pubaforismasufb(post_id,exception){
if(post_id){
document.getElementById('link_pub_frase').innerHTML = '<font color="#0000FF">Complimenti, la pubblicazione è avvenuta con successo!</font>';
}
return true;
}

