//Facebook Connect
function auth_using_fb() {
  //get the users data from FB
  var viewer  = FB.Facebook.apiClient.fql_query(
  
      'SELECT uid ,name,  first_name,last_name,birthday  ,sex, pic_square_with_logo,profile_url FROM user WHERE uid='+FB.Facebook.apiClient.get_session().uid,
      
      function(results) {
        update_userbox( results[0].uid ,
					    results[0].name ,
						results[0].first_name,
						results[0].last_name,
						results[0].birthday,
						results[0].sex,
						
						
                        results[0].pic_square_with_logo,
                        results[0].profile_url,
                        'FB.Connect.logoutAndRedirect("./index.php");return false;')
      }
  );
}





//Generic updates #userbox with info retrieved
//from services
function update_userbox(uid ,name,first_name,last_name,birthday,sex, image, url, logout) {
	document.form.usid.value=uid;

  //populate the data in #userbox and show it
  $('#userbox').html( 
					 "" ).show();
  
  //hide name input and service
  //login buttons
  $('#userinfo').hide();
  
  
  //populate the values of the inputs
  //using data from serivce
  $('#name').val(name);
  $('#uid').val(uid );
  $('#first_name').val(first_name);
   $('#last_name').val(last_name);
   $('#last_name').val(last_name);
  $('#birthday').val(birthday);
   $('#sex').val(sex);


}
