﻿/////////////////////////////////////// MASTERPAGE/////////////////////////////////////////////


// initialize the library with your Facebook API key

//FB.init({ apiKey: '139034912816589' });

FB.init({ appId: '161711123873329', status: true, cookie: true,
    xfbml: true
});
// fetch the status so that we can log out,  once the login status is fetched, call handleSessionResponse
FB.getLoginStatus(handleSessionResponse);

/*FB.login(function(response) {
if (response.session) {
if (response.perms) {
alert('user is logged in 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');
}
} else {
alert('is not logged in')
}
}); , { perms: 'read_stream,publish_stream,offline_access' });*/

// handle a session response from any of the auth related calls
function handleSessionResponse(response) {
    // if we dont have a session (which means the user has been logged out, redirect the user)
    if (!response.session) {
        //window.location = "http://www.borrowedgames.com/Authentication/Login/";
        //alert('FAIL');
        return;
    }
    else {

        window.response = response;

        carregaFacebook(response);
    }

    //FB.logout(handleSessionResponse);
}

function retornaXml() {
    if (requestFacebook.readyState == 4) {
        if (requestFacebook.status == 200) {
            var responseDoc = requestFacebook.responseXML;
            var access_token = responseDoc.getElementsByTagName("access_token")[0];
            if (access_token.firstChild.nodeValue != "") {
                location.href = "cadastro/bemvindo.aspx";
            }
        }
    }
}

function createRequest() {
    try {
        request = new XMLHttpRequest();
    }
    catch (tryMS) {
        try {
            request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (otherMS) {
            try {
                request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (failed) {
                request = null;
            }
        }
    }
    return request;
}
