	function getFB(page){
  	if(page)
  	{
  		xmlhttp.open('get', 'facebook/fbc_other.php?page='+page);
  	}
  	else
  	{
  		xmlhttp.open('get', 'facebook/fbc_dashboard.php');
  	}
		xmlhttp.onreadystatechange = handleFB;
		xmlhttp.send('');
	}

	function handleFB(){
		if(xmlhttp.readyState == 4){ //Finished loading the response
			if (xmlhttp.status == 200) {
				var response = xmlhttp.responseText;
				var items = response.split("|");
		  	document.getElementById('facebook').innerHTML = items[1];
		  	FB.ensureInit(FB.XFBML.Host.parseDomTree);
		  	if(items[0] == 1)
		  	{
					FB.Connect.showPermissionDialog("read_stream,publish_stream,offline_access");
				}
    	} else {
      	/* Error or no data */
      	document.getElementById('facebook').innerHTML = '';
    	}
		}
	}

	function updateFBPrefs(uid,pref,p_val){
  	xmlhttp.open('get', 'facebook/fb_prefs.php?uid='+uid+'&pref='+pref+'&pv='+p_val);
		xmlhttp.onreadystatechange = function(){ handleFBPrefs(pref) };
		xmlhttp.send('');
	}

	function handleFBPrefs(pref){
		if(xmlhttp.readyState == 4){ //Finished loading the response
			if (xmlhttp.status == 200) {
				var response = xmlhttp.responseText;
		  	document.getElementById(pref).innerHTML = response;
    	} else {
      	/* Error or no data */
      	document.getElementById(pref).innerHTML = '';
    	}
		}
	}

	function facebook_onload(already_logged_into_facebook, page)
	{
  	// user state is either: has a session, or does not.
  	// if the state has changed, detect that and reload.
  	FB.ensureInit(function() {
      FB.Facebook.get_sessionState().waitUntilReady(function(session) {
          var is_now_logged_into_facebook = session ? true : false;

          // if the new state is the same as the old (i.e., nothing changed)
          // then do nothing

          if (is_now_logged_into_facebook == already_logged_into_facebook) {
            return;
          }

          // otherwise, refresh to pick up the state change
         //window.location.reload(true);
         getFB(page);
      });
		});
	}