﻿FB.init({
    appId: '210716097031', cookie: true,
    status: true, xfbml: true
});

showMe = function (response) {
    if (!response.session || user_login == 1) {
    } else {        
        FB.api(
        {
            method: 'fql.query',
            query: 'SELECT email, third_party_id, pic_big, name, sex FROM user WHERE uid=' + response.session.uid
        },
        function (response) {
            fb_connect(response[0].email + '|' + response[0].third_party_id + '|' + response[0].pic_big + '|' + response[0].name + '|' + response[0].sex + '|' + response[0].birthday_date + '|' + response[0].username + '|' + response[0].hometown_location);
        }
    );
    }
};

FB.getLoginStatus(function (response) {    
    showMe(response);
    FB.Event.subscribe('auth.sessionChange', showMe);
    FB.logout(function (response) { });
});

function fb_connect(data) {
    jQuery('#activity_panel').showLoading();
    $.ajax({
        type: "POST",
        url: urlBase + "/Handlers/FBConnect.ashx?d=" + data,
        success: function (data) {
            document.location.href = urlBase + '/Login.aspx?fbl=' + data;
        }
    });    
}

function login(user, password) {
    jQuery('#activity_panel').showLoading();
    document.location.href = urlBase + '/Login.aspx?u=' + user + '&p=' + password + '&ex=2' + '&ReturnURL=' + document.location.href;    
}

function logout() {
    FB.logout();
    document.location.href = urlBase + '/Login.aspx?a=1&ReturnURL=' + document.location.href;        
}



