
<div id="bx-cnv-form-submit-text" class="bx-cnv-form-submit-text bx-def-margin-left bx-def-font-grayed"></div>
<div class="clear_both"></div>

<script>

    $(document).ready(function() {

        setInterval(function () {
            var $e = $('#bx-cnv-form-submit-text');
            var $eForm = $e.parents('form');
            var $eSubmit = $eForm.find('[type=submit]');
            var aData = { draft_save: '1' }
            var fCallback = function (data) {
                var aData;
                if ('undefined' != typeof(data) && (aData = data.split(',')) && aData.length) {
                    $('input[name=draft_id]').val(parseInt(aData[0]));
                    if (aData.length > 1 && aData[1])
                        $('input[name=csrf_token]').val(aData[1]);
                    $e.html('<span>' + _t('_bx_cnv_draft_saved_success') + '</span>');
                    setTimeout(function () {
                        $e.find('span').fadeOut();
                    }, 3000);
                } else {
                    $e.html(_t('_bx_cnv_draft_saving_error'));
                }
            };
            
            aData[$eSubmit.attr('name')] = 1;
            
            $eForm.ajaxSubmit({
                url: document.location.href,
                data: aData,
                beforeSubmit: function (formData, jqForm, options) {
                    for (var i=0; i < formData.length; i++) { 
                        if ('text' == formData[i].name && !formData[i].value.length) // don't save empty drafts
                            return false;
                    }
                    return true;
                },         
                error: fCallback, 
                success: fCallback
            }); 
        }, 10000);

    });

</script>
