var invoice_id = 0 ;
var autosave_interval_id = null ;

/* MODAL */

// pre-submit callback
function showRequest_modal(formData, jqForm, options) {
    // formData is an array; here we use $.param to convert it to a string to display it
    // but the form plugin does this for you automatically when it submits the data
    var queryString = jQuery.param(formData);

    // jqForm is a jQuery object encapsulating the form element.  To access the
    // DOM element for the form do this:
    // var formElement = jqForm[0];

    invoice_id = parseInt(jQuery('#invoice_id').val());

    if(is_mobile() || !split_view){
        if(jQuery('#task_modal').val() == "delete_entry"){
            jQuery('#deletebutton_modal').button('loading');
        }
        else jQuery('#savebutton_modal').button('loading');
    }
    else{
        jQuery('#savebutton_inline').button('loading');
    }

    // here we could return false to prevent the form from being submitted;
    // returning anything other than false will allow the form submit to continue
    return true;
}

// post-submit callback
function showResponse_modal(response, statusText, xhr, $form)  {

    var new_invoice_id = parseInt(response.content.id) ;

    item_to_highlight = invoice_id ;

    // var processedData = prepareResponseData(response.content);
    vm.current_invoice.update(response.content);
    render_reload_item(vm.current_invoice);

    update_summary(response.summary);

    if(is_mobile() || !split_view){
        jQuery('#savebutton_modal').button('reset');
        jQuery('#deletebutton_modal').button('reset');
        jQuery('#closebutton_modal').click();
    }
    else{
        jQuery('#savebutton_inline').button('reset');
        jQuery('#savebutton_preview_inline').button('reset');
        jQuery('#deletebutton_inline').button('reset');

        get_history(vm.current_invoice.id);

    }

    if(preview_after_save){
        preview_after_save = 0;
        preview_invoice(vm.current_invoice.id, vm.current_invoice);
    }

    new_items = 0;

    //notify if there are messages
    notify_messages(response.notifications);

}
