Object.extend(document, {
    UNIQUE_ID_PREFIX: 'RANDOM:'
  , getUniqueId: function() {
        var suffix;
        do {
            suffix = Number.randomInteger();
        } while ($(this.UNIQUE_ID_PREFIX + suffix) !== null);
        return this.UNIQUE_ID_PREFIX + suffix;
    }

// Standard functionality of <label> tags implemented for Safari and extended for other to activate() instead of focus() and more.
  , makeLabelsMoveFocus: function() {
        $$('label').invoke('observe', 'click', function() {
            if ($(this.readAttribute('for')) !== null
            && $(this.readAttribute('for')).match('input,textarea,select')) {
                if (Prototype.Browser.WebKit) {
                    if ($(this.readAttribute('for')).match('[type=\'radio\']')) {
                        $$('[name=' + $(this.readAttribute('for')).readAttribute('name') + ']').invoke('removeAttribute', 'checked');
                        $(this.readAttribute('for')).writeAttribute('checked');
                    } else if ($(this.readAttribute('for')).match('[type=checkbox]')) {
                        if ($(this.readAttribute('for')).match('[checked]')) {
                            $(this.readAttribute('for')).removeAttribute('checked');
                        } else {
                            $(this.readAttribute('for')).writeAttribute('checked');
                        }
                    }
                }
                $(this.readAttribute('for')).activate();
            } // if
        }); // invoke
    }

  , EMAIL_CLASS: 'EMAIL'
  , substituteEmails: function() {
        $$('span.' + document.EMAIL_CLASS).each(function(element) {
            element.replaceElement($a(
                $H({href: 'mailto:' + element.innerHTML.replace(' (at) ', '@')}).merge(
                    ['id', 'title', 'dir', 'xml:lang', 'class', 'style'].inject($H()
                                                                              , function(hash, attribute) {
                         if (element.readAttribute(attribute) !== null) {
                             hash[attribute] = element.readAttribute(attribute);
                         }
                         return hash;
                     }
                )), element.innerHTML.replace(' (at) ', '@')
            ));
        });
    }
/*
  , DEFAULT_CLASS: 'DEFAULT'
  , EMPTY_CLASS: 'EMPTY'
  , setInputsAndTextareasDefaultValues: function(website) { // website parameter is only for Safari
        $$('input[type=\'hidden\'][id^=\'DEFAULT]').each(function(element) {
            if (/^DEFAULT(_NOT_SEARCH)?:[A-z][A-z\d-_:.]*$/.test(element.readAttribute('id'))) {
                var targetId = element.readAttribute('id').replace(/^DEFAULT(?:_NOT_SEARCH)?:([a-zA-Z][a-zA-Z\d-_:\.]*)$/, '$1');
                if ($(targetId) !== null
                 && ($(targetId).nodeName.toLowerCase() === 'input'
                 && ($(targetId).readAttribute('type') === null || $(targetId).readAttribute('type') === 'text')
                  || $(targetId).nodeName.toLowerCase() === 'textarea')
                 && !$(targetId).hasClassName(this.DEFAULT_CLASS)) {
                     if (!/^DEFAULT_NOT_SEARCH/.test(element.readAttribute('id')) && $(targetId).nodeName.toLowerCase() !== 'textarea') {
                         if (Prototype.Browser.WebKit) {
                            $(targetId).writeAttribute($H({type: 'search'
                                                         , placeholder: $F(element)
                                                         , autosave: website
                                                         , results: 5}).toObject());
                            return;
                         } else {
                             $(targetId).replaceElement($span(
                                 $H({'class': 'search'}).toObject()
                               , $span($H({'class': 'magnifyingGlass'}).toObject()).observe('click', function() {$(targetId).activate();})
                               , $span($H({'class': 'rightBorder'}).toObject())
                               , $span($H({'class': 'reset'}).toObject()).observe('click', function() {
                                     $(targetId).value = '';
                                     $(targetId).activate();})
                               , $(targetId).cloneNode(true)
                             ));

                             new Form.Element.Observer($(targetId)
                               , 0.1
                               , function(element, value) {
                                     if (value === '') {
                                         element.parentNode.addClassName(document.EMPTY_CLASS);
                                     } else {
                                         element.parentNode.removeClassName(document.EMPTY_CLASS);
                                     }
                             });
                         }
                    }
                    Object.extend($(targetId), {
                        DEFAULT: $F(element)
                    });
                    if ($F($(targetId)) === $(targetId).DEFAULT) {
                        $(targetId).value = ''; // so that Firefox does not remember the last field value
                    }
                    Object.extend($(targetId), {
                        isDefault: function() {
                            return this.hasClassName(document.DEFAULT_CLASS);
                        }

                      , clear: function() {
                            if (this.isDefault()) {
                                this.removeClassName(document.DEFAULT_CLASS);
                                if (this.parentNode.nodeName.toLowerCase() === 'span' && this.parentNode.hasClassName('search')) {
                                    this.parentNode.removeClassName(document.DEFAULT_CLASS);
                                }
                                this.value = ''; // this can't be easily replaced with writeAttribute because of textareas
                            }
                            return this;
                        }

                      , reset: function() {
                            if ($F(this) === '') {
                                this.blur();
                                this.addClassName(document.DEFAULT_CLASS);
                                if (this.parentNode.nodeName.toLowerCase() === 'span' && this.parentNode.hasClassName('search')) {
                                    this.parentNode.addClassName(document.DEFAULT_CLASS);
                                }
                                this.value = this.DEFAULT; // this can't be easily replaced with writeAttribute because of textareas
                            }
                            return this;
                        }
                    }).reset()
                      .observe('focus', $(targetId).clear.bindAsEventListener($(targetId)))
                      .observe('blur', $(targetId).reset.bindAsEventListener($(targetId)))
                      .observe('keyup', (function(event) {
                           if (event.keyCode === Event.KEY_ESC) {
                               this.value = '';
                           }
                       }).bindAsEventListener($(targetId)));
                    $($(targetId).form).observe('submit', function(event) {$(targetId).clear();});
                }
            }
        }, this);
    }*/
});