function fbLogin(returnUrl) {
    var rHost = "https://" + document.location.host;
    if (!returnUrl || returnUrl == "") {
        returnUrl = $.query.get("ReturnUrl");
    }
    var session = FB.getSession();
    if (session) {
        // user already logged in to fb, log into redeemio
        window.location = rHost + "/SignIn/facebook.ashx?ReturnUrl=" + encodeURIComponent(returnUrl);
    }
    else {
        FB.login(function(response) {
            if (response.session) {
                if (response.perms) {
                    // user is logged in and granted some permissions
                    window.location = rHost + "/SignIn/facebook.ashx?ReturnUrl=" + encodeURIComponent(returnUrl)
                } else {
                    // user is logged in, but did not grant any permissions
                    $("#fb-error").html("* We need permission to access your email address via Facebook").show();
                }
            } else {
                // user is not logged in
                $("#fb-error").html("* Please login to Facebook and try again").show();
            }
        }, { perms: "email" });
    }
}
function fbLoginNoRedirect(loginSuccess) {
    FB.login(function(response) {
        if (response.session) {
            if (response.perms) {
                // user is logged in and granted some permissions
                loginSuccess();
            } else {
                // user is logged in, but did not grant any permissions
                $("#fb-error").html("* We need permission to access your email address via Facebook").show();
            }
        } else {
            // user is not logged in
            $("#fb-error").html("* Please login to Facebook and try again").show();
        }
    }, { perms: "email" });
}
function fbLogout(returnUrl) {
    if (!returnUrl || returnUrl == "") {
        returnUrl = $.query.get("ReturnUrl");
    }
    FB.logout(function(response) {
        // user is now logged out
        if (returnUrl != "") {
            window.location = returnUrl;
        }
        else {
            window.location.reload();
        }
    });
}
function fbLogoutNoRedirect(logoutSuccess) {
    FB.logout(function(response) {
        logoutSuccess();
    });
}
function opendeal(url, dealid) {
   window.open (url, "deal" + dealid, "");}
function ValidatorsEnabled(validators, enable) {
    $(validators).each(function(index) {
        ValidatorEnable($("#" + validators[index])[0], enable);
    });
}
function fbShare(params) {
    FB.ui(params, function(response) {
        // update share count
    });
}
