function facebookLogin() {
	FB.Connect.get_status().waitUntilReady(function(status) {
	switch(status) {
		case FB.ConnectState.appNotAuthorized:
		case FB.ConnectState.userNotLoggedIn:
			FB.Connect.requireSession(function() {
				loggedInFb();
			});
			break;
		case FB.ConnectState.connected:
			loggedInFb();
			break;
		}
	});
}			
function loggedInFb() {
	var api = FB.Facebook.apiClient;
	var user = api.get_session().uid;
	var quary = "SELECT email, publish_stream FROM permissions WHERE uid=" + user;
	api.fql_query(quary, function(rows) {
		if (!rows[0].email || !rows[0].publish_stream) {
			FB.Connect.showPermissionDialog("publish_stream,email",function() {
				sendInfo();
			});
		}
		else if (rows[0].publish_stream) {
			var actionLinks = [{ "text": "Join the CRNC", "href": "http://www.crnc.org"}];
			var attachment = {
				'name': 'Join the College Republicans Today',
				'href': 'http://www.crnc.org',
				'caption': '{*actor*} is joining in with the CRs',
				'description': 'College Republicans is the nation\'s oldest, largest, and most active youth political organization. Founded in 1892, there are currently over 200,000 CR\'s around the country on 1,800+ campuses in every state and DC.',
			};
			FB.Connect.streamPublish('', attachment, actionLinks);
		}
	});
}
function sendInfo() {
	var api = FB.Facebook.apiClient;
	var user = api.get_session().uid;
	var quary = "SELECT email FROM permissions WHERE uid=" + user;
	api.fql_query(quary, function(rows) {
		if (rows[0].email) {
			var quary = "SELECT first_name, last_name, email, current_location FROM user WHERE uid=" + user;
			api.fql_query(quary, function(rows) {
				document.SUPPORTER327237.first_name.value = rows[0].first_name;
				document.SUPPORTER327237.last_name.value = rows[0].last_name;
				document.SUPPORTER327237.email_address.value = rows[0].email;
				document.SUPPORTER327237.city.value = rows[0].current_location.city;
				document.SUPPORTER327237.state.value = stateSwitch(rows[0].current_location.state);
				document.SUPPORTER327237.zip.value = rows[0].current_location.zip;
				document.SUPPORTER327237.submit();
			});
		}
	});
}