(function ($, app, undefined) {
    $(document).ready(function () {
        var $error = $('#importErrorMsg'),
			$importDialog = $('#stbImportDialog').dialog({
			modal:    true,
            autoOpen: false,
            width:    600,
            buttons: {
                Import: function () {
					var $extension = $('input[name="extension"]:checked');

					$error.fadeOut();

					if (($extension.val() != 'spreadsheets' && !$('input[name="file"]').val())
						|| ($extension.val() == 'spreadsheets' && !$('input[name="settings[url]"]').val())
					) {
						$error.text('You need to choose the file!');
						$error.fadeIn();
						return;
					}
                    $importDialog.find('form').submit();
                },
                Cancel: function () {
                    $(this).dialog('close');
                }
            }
        });
        $('#import').on('click', function () {
			if(g_stbDoSaving === false && g_stbDoPreview === false) {
				$importDialog.dialog('open');
			}
        });
    });

}(window.jQuery, window.supsystic.Tables));