﻿function accessibleForms()
{
    var inputs, textareas
    var forms = document.getElementsByTagName('fieldset')
    for (var i = 0; i < forms.length; i++) {
        if (forms[i].className != 'accessible') {
            continue
        }
        inputs = forms[i].getElementsByTagName('input')
        for (var j = 0; j < inputs.length; j++) {
            if (inputs[j].type != 'text' && inputs[j].type != 'password') {
                continue
            }
            inputs[j].onfocus = function() {
                this.className += ' focused'
            }
            inputs[j].onblur = function() {
                this.className = this.className.replace(/ focused/g, '')
            }
        }
        textareas = forms[i].getElementsByTagName('textarea')
        for (var j = 0; j < textareas.length; j++) {
            textareas[j].onfocus = function() {
                this.className = 'focused'
            }
            textareas[j].onblur = function() {
                this.className = null
            }
        }
    }
}

function externalLinks()
{
    if (!document.getElementsByTagName) {
        return
    }
    var anchor
    var anchors = document.getElementsByTagName('a')
    for (var i = 0; i < anchors.length; i++) {
        anchor = anchors[i]
        if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external') {
            anchor.target = '_blank'
        }
    }
}

function iconLinks() {
/*
    var lis = $$('ul.eroom-docs-list li')
    for (var j = 0; j<lis.length; j++)
    {
        lis[j].style.cursor = 'pointer'
        lis[j].onclick = function() {
            var my1 = this.childNodes[0].href;
            my1 = escape(my1);
            window.open(my1);
            //window.location = this.childNodes[0].href

        }
    }*/
}

function init()
{
    accessibleForms()
    externalLinks()
    iconLinks()
}

sfHover = function() {
    try {
        var sfEls = document.getElementById("nav").getElementsByTagName("LI");
    }
    catch (e) {
        var sfEls = document.getElementById("Healthnav").getElementsByTagName("LI");
    }
    if (typeof document.getElementsByTagName('body')[0].style.maxHeight != 'undefined') {

    }
    for (var i = 0; i < sfEls.length; i++) {
        sfEls[i].onmouseover = function() {
            // IE7 will not fire onmouseout event when moving directly from sub-menu to a top menu, so force onmouseout functionality
            var lis = this.parentNode.getElementsByTagName('LI')
            for (var j = 0; j < lis.length; j++) {
                if (lis[j] != this && lis[j].parentNode.parentNode != this) {
                    lis[j].className = lis[j].className.replace(new RegExp(" hover\\b"), "")
                }
            }
            this.className += " hover";
        }
        sfEls[i].onmouseout = function() {
            this.className = this.className.replace(new RegExp(" hover\\b"), "")
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover)

window.onload = init