var invoice_ask_field = jQuery( '#billing_invoice_ask' );
var vat_number_field = jQuery( '#billing_vat_number' );
if ( invoice_ask_field.length ) {
	invoice_ask_field.change( function () {
		var vat_number_p = vat_number_field.closest( 'p' );
		if ( invoice_ask_field.is( ':checked' ) ) {
			vat_number_p.show();
		} else {
			vat_number_p.hide();
			vat_number_field.val( '' );
		}
	} );
	jQuery( document ).ready( function () {
		var invoice_ask_pref = invoice_ask_field.attr( 'data-invoice-ask' ) || invoice_ask_field.closest( 'label' ).attr( 'data-invoice-ask' );
		if ( vat_number_field.val().length > 2 && invoice_ask_pref !== '0' ) {
			invoice_ask_field.prop( 'checked', true );
		}
		invoice_ask_field.trigger( 'change' );
	} )
}
