<!-- newsletter block -->
{strip}
<div class="subscribe{if $block.Side != 'left' && $block.Side != 'right'} light-inputs{/if}">
    <div class="submit-cell">
        <input placeholder="{$lang.massmailer_newsletter_your_name}" type="text" id="newsletter_name" maxlength="50" />
    </div>
    <div class="submit-cell">
        <input placeholder="{$lang.massmailer_newsletter_your_e_mail}" type="text" id="newsletter_email" maxlength="100" />
    </div>
    <input class="button" id="subscribe_user" type="button" value="{$lang.massmailer_newsletter_subscribe}" data-default-val="{$lang.massmailer_newsletter_subscribe}" />
</div>
{/strip}

<script class="fl-js-dynamic">
lang['no_response_from_server'] = '{$lang.massmailer_newsletter_no_response}';
{literal}
$(document).ready(function(){
    $('#subscribe_user').click(function(){
        $(this).val(lang['loading']).attr('disabled', 'true');
        var $name = $('#newsletter_name');
        var $email = $('#newsletter_email');
        var data = {
            mode: 'newsletterSubscribe',
            name: $name.val(),
            email: $email.val()
        };
        $.getJSON(rlConfig['ajax_url'], data, function(response) {
            if (response) {
                if (response.status == 'OK' || response.status == 'WARNING') {
                    $('#newsletter_name').val('');
                    $('#newsletter_email').val('');
                    $('#subscribe_user').val($('#subscribe_user').data('default-val')).removeAttr('disabled');
                    if (response.status == 'OK') {
                        printMessage('notice', response.data.content);
                    } else {
                        printMessage('warning', response.data.content);
                    }
                } else {
                    $('#subscribe_user').val($('#subscribe_user').data('default-val')).removeAttr('disabled');
                    printMessage('error', response.data.message);
                }
            } else {
                $('#subscribe_user').val($('#subscribe_user').data('default-val')).removeAttr('disabled');
                printMessage('warning', lang['no_response_from_server']);
            }
        }).fail(function(){
            $('#subscribe_user').val($('#subscribe_user').data('default-val')).removeAttr('disabled');
            printMessage('warning', lang['no_response_from_server']);
        });
    });
});
{/literal}
</script>
<!-- newsletter block end -->