// Run when the share is submited
$('#postCommentBtn').click(function() {
	
	// Only do this if the Share-to-facebook is set.
	if ($('#shareFacebook').attr("checked")) {
		var permission = "publish_stream"; // String of permissions to require
		
		FB.getLoginStatus(function(response) {
			//if (response.session) {
				// logged in and connected user

				//$("#movieCommentForm").submit();
			//} else {
				// no user session available
				
				FB.login(function(response) {
					if (response.session) {
						
						if (response.perms == permission) {
		
							// alert("user is logged in and granted some permissions.");
							// user is connected and granted some permissions.
							// perms is a comma separated list of granted permissions
						} else {
							/*
							// alert("user is logged in, but did not grant any permissions.");
							// user is logged in, but did not grant any permissions
							
							// Remove share on Facebook
							$('#comment > form > .socials > a.facebook').removeClass("active");
							$('#shareFacebook').removeAttr("checked");
							*/
		
						}
		
						$("#movieCommentForm").submit();
					} else {
						// user is not connected
						
						// Remove share on Facebook
						$('#comment > form > .socials > a.facebook').removeClass("active");
						$('#shareFacebook').removeAttr("checked");
						
						$("#movieCommentForm").submit();
					}
					
				}, {perms:permission}); // END FB.login
			//}; // END if response.session
		}); // END FB.getLoginStatus
		
		return false;

	}; // END #ShareFacebook checked
}); // END click

/*


// Run when the share is submited
$('#ShareSubmit').click(function() {
	
	// Only do this if the Share-to-facebook is set.
	if ($('#ShareFacebook').attr("checked")) {
		var permission = "publish_stream"; // String of permissions to require
		
		// Make sure the facebook-api script is loaded
		FB.ensureInit(function() {
			
			FB.Connect.requireSession(function() {
				
				// Check is user already granted for this permission or not
				FB.Facebook.apiClient.users_hasAppPermission(permission, function (result) {
					
					// If the user have'nt set 'permission'
					if (result == 0) {
	
						// Show the facebook permission dialog
						FB.Connect.showPermissionDialog(permission, function(result) {
							
							FB.Facebook.apiClient.users_hasAppPermission(permission, function (result) {
							
								if (result == 0) {
									// Remove share on facebook, because the
									// user have not accepted permission
									$('#comment > form > .head > .facebook > a').removeClass("active");
									$('#ShareFacebook').removeAttr("checked");
								}
								
								$("#movieCommentForm").submit();
								
							});

							
						}, true, null);
						
					} else {
						
						$("#movieCommentForm").submit();
						
					}// END !hasPerm
					
				}); // END users_hasAppPermission
				
				
			}); // END requireSession
		}); // END ensureInit
		
		return false;

	}; // END #ShareFacebook checked
}); // END click
*/