﻿function twReload() {
    window.location.reload();
    /*__doPostBack('Twitter', 't');*/
}
function fbComment() {
    var img = document.getElementById('ctl00_cphMain_uc_datos_flook_imgFoto').src;
    var ft = document.getElementById('ctl00_cphMain_uc_datos_flook_LblTitulo').innerText;
    var fd = document.getElementById('ctl00_cphMain_uc_datos_flook_LblComentarioUsu').innerText;

    window.open('http://www.facebook.com/share.php?s=%20100&p[title]=' + document.title + ': ' + ft + '&p[url]=' + window.location.href + '&p[images][0]=' + img + '&p[summary]=' + fd + ' - Flook - Compartí tu look ', 'Compartir', 'width=800,height=400,left=150,top=100,scrollbar=no,resize=no', '')
}

function FB_test_perm(api_key, xd_receiver, permission, callback) {
    FB.Bootstrap.requireFeatures(["Connect"], function() {
    FB.Facebook.init(api_key, xd_receiver);
        FB.Connect.requireSession(function() {
            FB.Facebook.apiClient.users_hasAppPermission(permission, function(result) {
                if (result != 0)
                    return callback(true);

                FB.Connect.showPermissionDialog(permission, function(result) {
                    return callback(result == null ? false : (result.indexOf(permission) != -1));
                }, true, null);
            });
        });
    });
}

function FB_perm_result(value) {
    value ? window.location.reload(): alert('Algunas funcionalidades no estaran activadas');
}


function fLogin() {
    var u = window.location.href;
    if (u.indexOf("localhost:") > -1) {
        /*Local*/        
        FB_test_perm("c316b57c527e34dd38d3ae7a4e3d8c0e", "xd_receiver.htm", "publish_stream", FB_perm_result);
    }
    else if (u.indexOf("dev.") > -1) {
        /*Dev*/        
        FB_test_perm("b3d4f7a8587e7c465b094ef6049944bf", "xd_receiver.htm", "publish_stream", FB_perm_result);
    }
    else if (u.indexOf("stage.") > -1) {
        /*Stage*/        
        FB_test_perm("33d650c12ac6f1b5b5cb939295adf733", "xd_receiver.htm", "publish_stream", FB_perm_result);
    }
    else if (u.indexOf("http://www.flook.") > -1 || u.indexOf("http://flook.")) {
        FB_test_perm("ee920a5583cb5f543c2e8cc1419d6795", "xd_receiver.htm", "publish_stream", FB_perm_result);
    }
 
}

function fLogout() {
    FB.Connect.logout(function() { window.location.reload(true); });
}

function fValidateUser() {
    if (FB.Facebook.apiClient.get_session() != null) {
        document.getElementById('fb_mensaje').innerHTML = 'Tu usuario de Facebook no esta vinculado a tu cuenta Flook.';
        document.getElementById('ctl00_cphMain_uc_login1_uc_twitter1_lblTWError').style.display = 'none';
    } else { fLogin(); }
}
