function loginwithamazon_add_footer_script()
{
    $popup = 'false';
    if (!empty($_SERVER['HTTPS'])) {
        $popup = 'true';
    }
    $csrf = LoginWithAmazonUtility::hmac($_SESSION[LoginWithAmazonUtility::$CSRF_AUTHENTICATOR_KEY]);
    ?>
    <div id="amazon-root"></div>
    <script type="text/javascript">

        window.onAmazonLoginReady = function() {
            amazon.Login.setClientId('<?php 
    echo get_option('loginwithamazon_client_id');
    ?>
');
            amazon.Login.setUseCookie(true);
            <?php 
    if (isset($_GET['loggedout']) && $_GET['loggedout'] == 'true') {
        ?>
            amazon.Login.logout();
            <?php 
    }
    ?>
        };
        (function(d) {
            var a = d.createElement('script'); a.type = 'text/javascript';
            a.async = true; a.id = 'amazon-login-sdk';
            a.src = 'https://api-cdn.amazon.com/sdk/login1.js';
            d.getElementById('amazon-root').appendChild(a);
        })(document);

        function activateLoginWithAmazonButtons(elementId) {
            document.getElementById(elementId).onclick = function() {
                var options = {
                    scope: 'profile',
                    state: '<?php 
    echo $csrf;
    ?>
',
                    popup: <?php 
    echo $popup;
    ?>
                };
                amazon.Login.authorize(options, '<?php 
    echo str_replace('http://', 'https://', site_url('wp-login.php'));
    ?>
?amazonLogin=1');

                return false;
            };
        }
    </script>

<?php 
}