
//*** Break out of frames
if (top.location != location) {
    top.location.href = document.location.href;
}


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 (day > 31) { return false; }

    if (year < 1900) { return false; }

    if (month < 1 || month > 12) { 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;
    }

function redirectIfNotOfAge() {

    if (getCookie('CrownRoyalAgeGate') != "didIt=true") {
        loc = Base64.encode(window.location.href);
        if (window.location.pathname.indexOf("/fra/") > -1) {
            document.location.href = "../default_fra.aspx?page=" + loc;
        } else {
        document.location.href = "../default.aspx?page=" + loc;
       }
    }
}

    function getCookie(c_name) {
        if (document.cookie.length > 0) {
            c_start = document.cookie.indexOf(c_name + "=");
            if (c_start != -1) {
                c_start = c_start + c_name.length + 1;
                c_end = document.cookie.indexOf(";", c_start);
                if (c_end == -1) c_end = document.cookie.length;
                return unescape(document.cookie.substring(c_start, c_end));
            }
        }
        return "";
    }