// Module to handle age verification on brand pages
if (!window.sab) sab = {};
sab.AgeVerification = function() {
    var self;
    
    function constructorFn() {
        self = this;
        registerOnLoad(self.init);
    }
    
    // called once documetn has loaded
    constructorFn.prototype.init = function() {
        var c = getCookie("age_verification");
        self.applyVal(c);
        
        var theForm = document.forms['frmAgeVerify'];
        if (theForm != null) {
            theForm.b_age_verify.onclick = function(e) {
                var radio = theForm.verify_age;
                var radioVal = null;
                for (var i=0; i < radio.length; i++) {
                    if (radio[i].checked) radioVal = radio[i].value;
                }
                
                if (radioVal != null) setCookie("age_verification", radioVal);
                self.applyVal(radioVal);
            }
        }
    }

    // take the value and apply to the restricted content
    constructorFn.prototype.applyVal = function(val) {
        var rc = $('restricted_content');
        var da = $('age_verification_display_area');
        
        rc.style.display="none";
        if (val == null || val == '') {
            da.innerHTML = $('age_verify').value; 
        } else if (val == "0"){
            da.innerHTML = $('under_age').value; 
        } else {
            da.style.display="none";
            rc.style.display="block";
        }

    }
    
    return new constructorFn();
}

sab.ageVerification = new sab.AgeVerification();