

// JavaScript Document

function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
        var anchor = anchors[i];
        if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
            anchor.target = "_blank";
    }
}

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if ((charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46) || charCode == 13)
        return false;

    return true;
}

var currentSubSelected = "";

function isEmail(alphaField) {
    if (document.getElementById(alphaField).value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
        return true;
    } else {
        return false;
    }
}

function isNumericMaxLength(alphaField, maxLength) {

    alphaField = document.getElementById(alphaField);
    if (isNaN(alphaField.value) == false && alphaField.value.length > 0 && alphaField.value.length == maxLength) {
        return true;
    } else {
        return false;
    }
}

function checkAge(min_age, day, month, year) {

    if (isNaN(day) || isNaN(month) || isNaN(year)) { return false; }

    //*** is valid date
    if (month == 2 && day > daysInFebruary(year)) {
        return false;
    }

    if (month == 4 || month == 6 || month == 9 || month == 11) {
        if (day == 31) {
            return false;
        }
    }

    if (year < 1900) { return false; }

    //** are they old enough?
    var theirDate = new Date((year + min_age), month, day);
    var today = new Date;

    if ((today.getTime() - theirDate.getTime()) < 0) {
        return false;
    }
    else {
        return true;
    }

}

//function to validate Feb day
function daysInFebruary(year) {
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}

function handleMOButtons(btype,fname) {
    document.getElementById(btype).src = "images/buttons/" + fname;
}

function handleMoutButtons(btype,fname) {
        document.getElementById(btype).src = "images/buttons/" + fname;
}