﻿var applicationID = "290520234312000";
var base = "tickats.com.lavender.arvixe.com";
var baseProd = "Tickats.com";

var urlBase = "http://" + base;
var site = "/tickats";
var RefreshGap = "/RefreshGap";
var LoginUrl = urlBase + site + "/login";
var ResponderUrl = site + "/Responder";
var MainAppPage = urlBase + site + "/purchase";
var extended = "publish_checkins,status_update,photo_upload,video_upload,create_event,rsvp_event,offline_access,email,create_note,share_item,publish_stream,contact_email,read_friendlists";
var user = "user_birthday,user_hometown,user_location,user_likes,user_activities,user_interests,user_events,user_checkins";
var friends = "friends_birthday,friends_location,friends_activities,friends_interests,friends_events,friends_checkins";
var scope = user + "," + friends + "," + extended;
var successFactor = "kudos";
var callback = "";
var windowRef = "";
$(function() {



    window.fbAsyncInit = function() {
        FB.init({
                appId: applicationID, // App ID
                channelUrl: '//' + base + '/channel.html', // Channel File
                status: true, // check login status
                cookie: true, // enable cookies to allow the server to access the session
                xfbml: false,  // parse XFBML
                oauth: true
            });

        FB.Event.subscribe('auth.logout', function(response) {
            //alert("Loggedout!!!");
            window.location.href = site + RefreshGap + "?logout=1";
        });

        FB.Event.subscribe('auth.authResponseChange', function(response) {
            // alert("response changed!!!");
            window.location.href = site + RefreshGap + "?logout=1";
        });



        FB.getLoginStatus(function(response) {
            if (response.status === 'connected') {
                // the user is logged in and connected to your
                // app, and response.authResponse supplies
                // the user’s ID, a valid access token, a signed
                // request, and the time the access token 
                // and signed request each expire
                var uid = response.authResponse.userID;
                var accessToken = response.authResponse.accessToken;
                //alert("connencted => " + accessToken);
            } else if (response.status === 'not_authorized') {
                window.location.href = site + RefreshGap + "?logout=1";
                // the user is logged in to Facebook, 
                //but not connected to the app
                //alert("app not approved");
            } else {
                window.location.href = site + RefreshGap + "?logout=1";
                //alert("not logged in");
                // the user isn't even logged in to Facebook.
            }
        });

        //Additional functions
    };

    // Load the SDK Asynchronously
    (function(d) {
        var js, id = 'facebook-jssdk'; if (d.getElementById(id)) { return; }
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        d.getElementsByTagName('head')[0].appendChild(js);
    }(document));
});
