﻿//function facebook_login_get_permission() {
//        FB.login(
//    function(response) {
//        if (response.session) {
//            InitiateAsyncRequestHead('true');
//        } else {
//            InitiateAsyncRequestHead('false');
//        }
//    }, {
//    //perms: "email,user_birthday,user_location,user_photos,publish_stream"
//    scope: "email,publish_stream"
//    });
//}
function facebook_login_get_permission() {
    FB.login(
    	function (response) {
    	    if (response.authResponse) {

    	        InitiateAsyncRequestHead('true');

    	    } else {
    	        InitiateAsyncRequestHead('false');
    	    }
    	}, {
    	    scope: "email,publish_stream"

    	});
}
function ask_for_permissions(permissions) {
    FB.login(
    function (response) {
        if (response.authResponse) {
            InitiateAsyncRequest('true');
        } else {
            InitiateAsyncRequest('false');
        }
    }, {
        scope: permissions
    });
}

function streamPublish(message_title, message_caption, message_description, message_link, hrefTitle, hrefLink, userPrompt) {
    var publish = {
        method: 'feed',
        message: userPrompt,
        name: message_title,
        caption: message_caption,
        description: (
		  message_description
	  ),
        link: message_link,
        // picture: image_src,
        actions: [
		{ name: hrefTitle, link: hrefLink }
	  ],
        user_message_prompt: ''
    };

    FB.ui(publish, null);

}

function fbs_click() {
   if (confirm('This link will take you to a Web site to which this Privacy Policy does not apply. We encourage you to read the Privacy Policy of every Web site you visit.')) {
       u = location.href;
       t = document.title;
       window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');
       return false;
   }
}
function sharestory(u, t) {
   if (confirm('This link will take you to a Web site to which this Privacy Policy does not apply. We encourage you to read the Privacy Policy of every Web site you visit.')) {
       window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');
       return false;
   }
}
function twitter_click() {
   if (confirm('This link will take you to a Web site to which this Privacy Policy does not apply. We encourage you to read the Privacy Policy of every Web site you visit.')) {
       u = location.href;
       t = "M2"
       window.open('http://twitter.com/home?status=' + encodeURIComponent(t) + ' ' + encodeURIComponent(u), 'sharertwitter', 'toolbar=0,status=0,width=626,height=436');
       return false;
   }
}

function share_on_facebook(id) {
    var hrefTitle = 'http://www.dothefish.com/default.aspx?assetid=' + id.toString();
    var message_title = "Do The Fish";
    var userPrompt = "Enter your message";
    var hrefLink = 'http://www.dothefish.com/default.aspx?assetid=' + id.toString();
    var hrefTitle = 'http://www.dothefish.com/default.aspx?assetid=' + id.toString();
    var message_caption = "";
    var message_description = "";
    FB.ui(
         {

             method: 'stream.publish',
             message: message_title,
             display: 'dialog',
             attachment: {
                 name: hrefLink,
                 caption: message_caption,
                 description: (
                    message_description
                   ),
                 href: hrefLink
             },
             action_links: [
                   { text: "http://www.dothefish.com", href: "http://www.dothefish.com" }
                 ],

             user_message_prompt: userPrompt
         },
               function(response) {
                   if (response && response.post_id) {
                       //  alert('Post published successfully.');
                   } else {
                       // alert('Post was not published.');
                   }
               }
             );
}

