function substituteEmails() {
    var EMAIL_CLASS_NAME = 'EMAIL';

    function substituteEmail(node) {
        var a = document.createElement('a')
          , email = node.firstChild.nodeValue.replace(/ \(at\) /, '@');
        a.href = 'mailto:' + email;
        a.className = node.className.withoutClassName(EMAIL_CLASS_NAME);
        a.appendChild(document.createTextNode(email));
        var parentNode = node.parentNode;
        parentNode.replaceChild(a, node);
    }
    while ($$('span.' + EMAIL_CLASS_NAME).length > 0) {
        substituteEmail($$('span.' + EMAIL_CLASS_NAME)[0]);
    }
}

// especially for Opera for Mac CSS (poor Aqua buttons implementation)
function macness() {
    if (navigator.platform.toLowerCase().indexOf('mac') !== -1) {
        document.body.className = document.body.className.withClassName('MAC');
    }
}

function hundredPercent() {
    document.getElementsByTagName('html')[0].style.height = '100%';
    document.body.style.height = '100%';
    var height = document.body.offsetHeight;
    $('page').style.minHeight = 0;
    document.body.style.height = 'auto';
    setTimeout(function() {
                   if (document.body.offsetHeight < height) {
                       document.body.style.height = '100%';
                       $('page').style.height = '100%';
                   } else {
                       document.getElementsByTagName('html')[0].style.height = 'auto';
                       $('page').style.height = 'auto';
                       $('footer').style.position = 'static';
                       setTimeout(function() {
                                      $('footer').style.position = 'absolute';
                                  }, 0);
                   }
               }, 0);
}

function focusToFirstInputOrTextarea() {
    var i = 0
      , FOCUS_CLASS_NAME = 'FOCUS'
      , elements = $$('.' + FOCUS_CLASS_NAME);
    for (; i < elements.length; i++) {
        if ((elements[i].nodeName.toLowerCase() === 'input' || elements[i].nodeName.toLowerCase() === 'textarea') && elements[i].className.containsClassName(FOCUS_CLASS_NAME)) {
            try {
                elements[i].focus();
            } catch (exception) {
                // Internet Explorer: Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus.
            }
            break;
        }
    }
}




Event.observe(window, 'load', substituteEmails);
Event.observe(window, 'load', macness);

if (navigator.userAgent.indexOf('AppleWebKit') !== -1) {
    Event.observe(window, 'load', function() {
                                      $('footer').parentNode.replaceChild($('footer').cloneNode(true), $('footer'));
                                  });
    Event.observe(window, 'resize', function() {
                                      $('footer').parentNode.replaceChild($('footer').cloneNode(true), $('footer'));
                                  });
}

Event.observe(window, 'load', focusToFirstInputOrTextarea);