

$(document).ready(function() {
    //gateway events
    $('#agegate_inputs input').one("focus", function() {
        if ($(this).val() == "DD" || $(this).val() == "MM" || $(this).val() == "YYYY") {
            $(this).val('');
        }

        $(this).focus();

    });



    $('#agegate_inputs input').bind("keypress", function(e) {
        if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
            return false;
        }

    });

    $('.agegate_error a').bind('click', function() {

        $('.agegate_error').hide();
        return false;
    });
});




function validate() {

    var day = parseInt(document.getElementById("txtday").value);
    var month = parseInt(document.getElementById("txtmonth").value);
    var year = parseInt(document.getElementById("txtyear").value);


    if (document.getElementById("province").selectedIndex == 0) {
        showProvError();
        return false;
    }

    chosenProv = document.getElementById("province").value;

    drinkingAge = 19;

    if (chosenProv == "AB" || chosenProv == "MB" || chosenProv == "QC") { drinkingAge = 18; }

    if (checkAge(drinkingAge, day, month, year) == false) {
        showError();
        return false;
    } else {
        return true;
    }
}

function showError() {
    document.getElementById("errorMsg").style.display = "block";
}

function showProvError() {
    document.getElementById("errorMsgProvince").style.display = "block";
}

function showWhyMessage(showIt) {
    if (showIt == true) {
        document.getElementById("whyMessage").style.display = "block";
    } else {
        document.getElementById("whyMessage").style.display = "none";
    }
}