//Facebook Connect
function auth_using_fb() {
  //get the users data from FB
    	
    FB.api('/me', function(response) {
         var query = FB.Data.query('select name, pic_square, profile_url, email from user where uid={0}', response.id);
         query.wait(function(rows) {

		update_userbox( rows[0].name,
						rows[0].email,
		                rows[0].pic_square,
		                rows[0].profile_url,
		                
		                'FB.Connect.logoutAndRedirect("./index.php");return false;')
		                
		                               
         });
    });  
    	              	  		  	
}

function logout(){
	$('#userbox').html( "" ).show();
	$('#message').attr("disabled", "disabled");
	$('#enviar').attr("disabled", "disabled");
}

//Generic updates #userbox with info retrieved
//from services
function update_userbox(name, email, image, url, logout) {

  //populate the data in #userbox and show it
  $('#userbox').html( "<a href='"+url+"'>"
                    + "<img alt='"+name+"' src='"+image+"' />"
                    + "" + name + "</a> "
                     ).show();
  
  //populate the values of the inputs
  //using data from serivce
  $('#name').val(name);
  $('#url').val(url);
  $('#image').val(image);
  $('#email').val(email);
  
  $('#message').removeAttr('disabled');
  $('#rola').removeAttr('disabled');
  $('#aquien').removeAttr('disabled');
  $('#enviar').removeAttr('disabled');

}

function graphStreamPublish(msg){	       
        FB.api('/me/feed', 'post', { message: msg }, function(response) {
            if (!response || response.error) {
                 alert('No se pudo postear');
            } else {
                 alert('Se posteo a tu feed de facebook');
            }
       });
 }

