/**
 * Implementation of hook_elements().
 */
function wysiwyg_elements() {
  $type = array();
  $type['textarea'] = array('#process' => array('wysiwyg_process_textarea'));
  $type['form'] = array('#process' => array('wysiwyg_process_form'));
  return $type;
}

/**
 * Implementation of hook_form_alter().
 */
function wysiwyg_form_alter(&$form, &$form_state, $form_id) {
  $form['#input'] = TRUE;
}

function wysiwyg_process_form($form) {
  $form['#input'] = FALSE;
  wysiwyg_purge_form($form);
  return $form;
}

/**
 * This is a cleanup function to remove the processing done by other editors
 * on textareas. The WYSIWYG Framework instead manages including all editors
 * when necessary on textareas.
 */
function wysiwyg_purge_form(&$form) {
  foreach (element_children($form) as $key) {
    wysiwyg_purge_form($form[$key]);
    if (isset($form['#type']) && $form['#type'] == 'textarea') {
      $editors = array_keys(wysiwyg_get_editors());
      foreach ($form['#process'] as $key => $function) {
        foreach ($editors as $editor) {
          if (strpos($function, $editor) === 0) {
            unset($form['#process'][$key]);
          }
        }
      }
    }
  }
}