title: Combine jQuery UI dialog code for alerts and confirms (DRY)?
body: <p>I have the code below to show either an alert dialog with just an 'OK' button and a confirm dialog with a 'Cancel' and 'OK (submit)' button.</p>
  
  <p>As you can see there is a lot of repeated code and I was wondering if there way of writing this so that as little code as possible is repeated(written more than once)?</p>
  
  <p>I am learning jQuery quickly but am stuck as to how to write this better? Any help or examples would be really appreciated? Thank you very much</p>
  
  <p>External JS:</p>
  
  <pre><code>function alert() {
      var id = $('#dialog-alert');
      id.dialog({
          autoOpen: false,
          dialogClass: 'ui-alert',
          resizable: false,
          modal: true,
          width: 450,
          buttons: [{
              'text': 'OK',
              'class': 'btn btn-green',
              'click': function () { $(this).dialog('close'); }
          }]
      }).dialog('open');
      $('.ui-dialog :button').blur();
  };
  
  function confirm() {
      var id = $('#dialog-confirm');
      id.dialog({
          autoOpen: false,
          dialogClass: 'ui-alert',
          resizable: false,
          modal: true,
          width: 450,
          buttons: [{
              'text': 'Cancel',
              'class': 'btn btn-red',
              'click': function () { $(this).dialog('close'); }
          },
          {
              'text': 'OK',
              'class': 'btn btn-green',
              'click': function () { $('#completeform').submit(); }
          }]
      }).dialog('open');
      $('.ui-dialog :button').blur();
  };
  </code></pre>