﻿/*jslint browser: true, nomen: false, plusplus: true, undef: true, white: true */

document.addEvent('ready', function () {
    var i, link, links = document.links;
    for (i = 0; (link = links[i]); i += 1) {
        if ((/mailto:/).test(link.href)) {
            continue;
        }
        if (link.hostname.search(window.location.hostname) == -1 && ((/http(s)?:/).test(link.href))) {
            link.target = '_blank';
            link.title = 'Link opens in new window';
        }
    }
    if (document.getElementById('enroll')) {
        var input, inputs = ['firstName', 'lastName'];
        for (i = 0; (input = document.getElementById(inputs[i])); i += 1) {
            input.addEvent('focus', function () {
                if (this.getProperty('value') == this.getProperty('title')) {
                    this.setProperty('value', '');
                }
            }).addEvent('blur', function () {
                if (this.getProperty('value') === '') {
                    this.setProperty('value', this.getProperty('title'));
                }
            });
        }
        document.get('#enroll button')[0].addEvent('click', function () {
            for (i = 0; (input = document.getElementById(inputs[i])); i += 1) {
                if (input.getProperty('value') == input.getProperty('title')) {
                    input.setProperty('value', '');
                }
            }
        });
    }
    if (document.getElementById('selectYear')) {
        document.getElementById('year').addEvent('change', function () {
            document.getElementById('loading').style.visibility = 'visible';
            document.getElementById('selectYear').submit();
        });
    }
});

document.ready();