diff --git a/uc_order/uc_order.admin.inc b/uc_order/uc_order.admin.inc
index a205497..d015608 100644
--- a/uc_order/uc_order.admin.inc
+++ b/uc_order/uc_order.admin.inc
@@ -547,80 +547,233 @@ function uc_order_select_form_submit($form, &$form_state) {
 
 /**
  * Creates a new order and redirect to its edit screen.
+ *
+ * @see uc_order_create_form_create_validate()
+ * @see uc_order_create_form_create_submit()
+ * @ingroup forms
  */
-function uc_order_create() {
-  drupal_add_js(array('ucURL' => array('adminOrders' => url('admin/store/orders/'))), 'setting');
-  drupal_add_js(drupal_get_path('module', 'uc_order') . '/uc_order.js');
+function uc_order_create_form($form, &$form_state) {
+  $form['customer_type'] = array(
+    '#type' => 'radios',
+    '#options' => array(
+      'search' => t('Search for an existing customer.'),
+      'create' => t('Create a new customer account.'),
+      'none' => t('No customer account required.'),
+    ),
+    '#required' => TRUE,
+    '#default_value' => 'search',
+    '#ajax' => array(
+      'callback' => 'uc_order_create_form_customer',
+      'wrapper' => 'uc-order-customer',
+      'progress' => array('type' => 'throbber'),
+    ),
+  );
 
-  $build = array();
-  $build['search_button'] = array(
-    '#markup' => uc_store_get_icon('file:order_view') . ' ' . t('Search for an existing customer.'),
-    '#prefix' => '<div id="customer-search-link" style="position: relative; top: 2px; cursor: pointer;" onclick="load_customer_search();">',
+  $form['customer'] = array(
+    '#prefix' => '<div id="uc-order-customer">',
     '#suffix' => '</div>',
+    '#tree' => TRUE,
   );
-  $build['create_button'] = array(
-    '#markup' => uc_store_get_icon('file:menu_customers_small') . ' ' . t('Create a new customer.'),
-    '#prefix' => '<div id="customer-create-link" style="position: relative; top: 2px; cursor: pointer;" onclick="load_new_customer_form();">',
-    '#suffix' => '</div>',
+
+  if (!isset($form_state['values']['customer_type']) || $form_state['values']['customer_type'] == 'search') {
+    $form['customer'] += array(
+      '#type' => 'fieldset',
+      '#title' => t('Customer search'),
+      '#description' => t('Enter full or partial names or email addresses.'),
+    );
+    $form['customer']['first_name'] = array(
+      '#type' => 'textfield',
+      '#title' => t('First name'),
+      '#size' => 24,
+      '#maxlength' => 32,
+    );
+    $form['customer']['last_name'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Last name'),
+      '#size' => 24,
+      '#maxlength' => 32,
+    );
+    $form['customer']['email'] = array(
+      '#type' => 'textfield',
+      '#title' => t('E-mail'),
+      '#size' => 24,
+      '#maxlength' => 96,
+    );
+    $form['customer']['search'] = array(
+      '#type' => 'button',
+      '#value' => t('Search'),
+      '#ajax' => array(
+        'callback' => 'uc_order_create_form_customer_search',
+        'wrapper' => 'uc-order-customer-results',
+        'progress' => array('type' => 'throbber'),
+      ),
+    );
+    $form['customer']['uid'] = array(
+      '#prefix' => '<div id="uc-order-customer-results">',
+      '#suffix' => '</div>',
+    );
+
+    if (isset($form_state['values']['customer']['email'])) {
+      $query = db_select('users', 'u')->distinct();
+      $query->leftJoin('uc_orders', 'o', 'u.uid = o.uid');
+      $query->fields('u', array('uid', 'mail'))
+        ->fields('o', array('billing_first_name', 'billing_last_name'))
+        ->condition('u.uid', 0, '>')
+        ->condition(db_or()
+          ->isNull('o.order_status')
+          ->condition('o.order_status', uc_order_status_list('general', TRUE), 'IN')
+        )
+        ->condition('o.billing_first_name', db_like(trim($form_state['values']['customer']['first_name'])) . '%', 'LIKE')
+        ->condition('o.billing_last_name', db_like(trim($form_state['values']['customer']['last_name'])) . '%', 'LIKE')
+        ->condition(db_or()
+          ->condition('o.primary_email', db_like(trim($form_state['values']['customer']['email'])) . '%', 'LIKE')
+          ->condition('u.mail', db_like(trim($form_state['values']['customer']['email'])) . '%', 'LIKE')
+        )
+        ->orderBy('o.created', 'DESC')
+        ->range(0, $limit = 11);
+
+      $result = $query->execute();
+
+      $options = array();
+      foreach ($result as $user) {
+        $name = '';
+        if (!empty($user->billing_first_name) && !empty($user->billing_last_name)) {
+          $name = $user->billing_first_name . ' ' . $user->billing_last_name . ' ';
+        }
+        $options[$user->uid] = $name . '(' . $user->mail . ')';
+      }
+
+      $more = '';
+      if (count($options) == $limit) {
+        array_pop($options);
+        $more = t('More than !limit results found. Refine your search to find other customers.', array('!limit' => $limit - 1));
+      }
+
+      if (!empty($options)) {
+        $form['customer']['uid'] += array(
+          '#type' => 'radios',
+          '#title' => t('Select customer'),
+          '#description' => $more,
+          '#options' => $options,
+          '#default_value' => reset(array_keys($options)),
+        );
+      }
+      else {
+        $form['customer']['uid'] += array(
+          '#markup' => '<p>' . t('Search returned no results.') . '</p>',
+        );
+      }
+    }
+  }
+  elseif ($form_state['values']['customer_type'] == 'create') {
+    $form['customer'] += array(
+      '#type' => 'fieldset',
+      '#title' => t('New customer details'),
+    );
+    $form['customer']['email'] = array(
+      '#type' => 'textfield',
+      '#title' => t('E-mail'),
+      '#size' => 24,
+      '#maxlength' => 96,
+    );
+    $form['customer']['sendmail'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('E-mail customer account details.'),
+    );
+  }
+
+  $form['actions'] = array('#type' => 'actions');
+  $form['actions']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Create order'),
+    '#validate' => array('uc_order_create_form_create_validate'),
+    '#submit' => array('uc_order_create_form_create_submit'),
   );
-  $build['customer_select'] = array('#markup' => '<div id="customer-select"></div><br />');
-  $build['create_form'] = drupal_get_form('uc_order_create_form');
 
-  return $build;
+  return $form;
+}
+
+/**
+ * Ajax callback: updates the customer selection fields.
+ */
+function uc_order_create_form_customer($form, &$form_state) {
+  return $form['customer'];
+}
+
+/**
+ * Ajax callback: updates the customer search results.
+ */
+function uc_order_create_form_customer_search($form, &$form_state) {
+  return $form['customer']['uid'];
 }
 
 /**
- * Selects a customer to whom to assign a new order.
+ * Form validation handler for customer search.
  *
- * @see uc_order_create_form_submit()
+ * @see uc_order_create_form()
  * @ingroup forms
  */
-function uc_order_create_form($form, &$form_state) {
-  $form['customer'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('New order customer'),
-    '#description' => t('Use the buttons above to have these fields filled in or just submit the form with the fields blank to create a blank order.'),
-    '#collapsible' => FALSE,
-  );
-  $form['customer']['uid'] = array(
-    '#type' => 'hidden',
-    '#default_value' => 0,
-  );
-  $form['customer']['text']['uid_text'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Customer number'),
-    '#default_value' => 0,
-    '#maxlength' => 10,
-    '#size' => 10,
-    '#disabled' => TRUE,
-  );
-  $form['customer']['text']['primary_email_text'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Primary e-mail'),
-    '#default_value' => '',
-    '#maxlength' => 64,
-    '#size' => 32,
-    '#disabled' => TRUE,
-  );
+function uc_order_create_form_create_validate($form, &$form_state) {
+  switch ($form_state['values']['customer_type']) {
+    case 'search':
+      if (empty($form_state['values']['customer']['uid'])) {
+        form_set_error('customer][uid', t('Please select a customer.'));
+      }
+      break;
 
-  $form['actions'] = array('#type' => 'actions');
-  $form['actions']['create'] = array(
-    '#type' => 'submit',
-    '#value' => t('Create order'),
-  );
+    case 'create':
+      $email = trim($form_state['values']['customer']['email']);
+      if (!valid_email_address($email)) {
+        form_set_error('customer][mail', t('Invalid e-mail address.'));
+      }
 
-  return $form;
+      $uid = db_query("SELECT uid FROM {users} WHERE mail LIKE :mail", array(':mail' => $email))->fetchField();
+      if ($uid) {
+        form_set_error('customer][mail', t('An account already exists for that e-mail.'));
+      }
+      break;
+  }
 }
 
 /**
- * Form submission handler for uc_order_create_form().
+ * Form submission handler for customer search.
  *
  * @see uc_order_create_form()
+ * @ingroup forms
  */
-function uc_order_create_form_submit($form, &$form_state) {
+function uc_order_create_form_create_submit($form, &$form_state) {
   global $user;
 
-  $order = uc_order_new($form_state['values']['uid'], 'post_checkout');
+  switch ($form_state['values']['customer_type']) {
+    case 'search':
+      $uid = $form_state['values']['customer']['uid'];
+      break;
+
+    case 'create':
+      // Create new account.
+      $email = trim($form_state['values']['customer']['email']);
+      $fields = array(
+        'name' => uc_store_email_to_username($email),
+        'mail' => $email,
+        'pass' => user_password(),
+        'status' => variable_get('uc_new_customer_status_active', TRUE) ? 1 : 0,
+      );
+      $account = user_save(NULL, $fields);
+      $uid = $account->uid;
+
+      if ($form_state['values']['customer']['sendmail']) {
+        // Manually set the password so it appears in the e-mail.
+        $account->password = $fields['pass'];
+        drupal_mail('user', 'register_admin_created', $email, NULL, array('account' => $account), uc_store_email_from());
+        drupal_set_message(t('A welcome message has been e-mailed to the new user.'));
+      }
+      break;
+
+    default:
+      $uid = 0;
+  }
+
+  $order = uc_order_new($uid, 'post_checkout');
   uc_order_comment_save($order->order_id, $user->uid, t('Order created by the administration.'), 'admin');
 
   $form_state['redirect'] = 'admin/store/orders/' . $order->order_id . '/edit';
diff --git a/uc_order/uc_order.module b/uc_order/uc_order.module
index 072d353..8908c38 100644
--- a/uc_order/uc_order.module
+++ b/uc_order/uc_order.module
@@ -135,7 +135,8 @@ function uc_order_menu() {
   $items['admin/store/orders/create'] = array(
     'title' => 'Create order',
     'description' => 'Create an empty new order.',
-    'page callback' => 'uc_order_create',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('uc_order_create_form'),
     'access arguments' => array('create orders'),
     'weight' => -5,
     'file' => 'uc_order.admin.inc',
