/*
This script makes some assumptions:
- This page is to be included with any and all pages that require a certain minimum age, inclding index.jsp
- index.jsp serves as the age gateway page, home.jsp serves as the home page
- two javascript variables must be defined as follows prior to inclusion of this file
- var requiredAge = 18; // int value defining the minimum age to view this site
- var cookieName = "myGameTitleAge"; // string value defining the cookie name to use (to avoid disambiguities between titles)
- index.jsp must have a div with id="ageGate" and style="display:none;" which this script will use to display the birthday selector.
The selector will be appended to any existing content in that div
- index.jsp must have a div with id="underAge" and style="display:none;". If the user is underage, this div
will be made visible. It should hence contain the underage message (e.g. "You are too young to view this site")
This is the behaviour of this page
- If no age has been selected (no age cookie present), then redirect to index.jsp (unless we're already there of course)
once at index.jsp, display the birthday selector
- If an an age cookie was already set...
* if older then the required age, and we are at index.jsp, redirect to home.jsp
* if older then the required age, and we are at anywhere else, do nothing
* if younger then the required age, redirect to index.jsp, unless we're already there,
once at index.jsp, display the underage message
Omniture
The following events are logged:
- when the user comes to the index page and has no age cookie set (AgeGatePrompt)
- when the user selects a non-qualifying age from the drop down (AgeGateUnderAge)
- when the user comes to the index page and has a non-qualifying age cookie set (AgeGateUnderAge)
- when the user either selects a qualifying age or has the cookie set with a qualifying age, *no* omni call
is made, and the user is redirected to home.jsp.
*/
var displayTimer=null;
window.omniTimer=null;
var isIndex = (top.location.href.indexOf("/index.jsp") != -1 || top.location.href.charAt(top.location.href.length-1) == "/" ) ? true : false;
var cstart = document.cookie.indexOf(cookieName+"=");
if(cstart==-1){
if(!isIndex){
// redirect to the index page where an age must be selected
location.replace("index.jsp");
}else{
// this is the index page. Show the age selector
makeOmniCall("AgeGatePrompt");
displayAgeSelector();
}
}else{
// age cookie present. extract age and act accordingly
var cend=document.cookie.indexOf(";",cstart);
if(cend==-1) cend = document.cookie.length;
checkAndActOnAge(document.cookie.substring(cstart+cookieName.length+1,cend));
}
/*
* subPage={"AgeGatePrompt"|"AgeGateUnderAge"|"AgeGatePass"}
* intervalId=null always!
*/
function makeOmniCall(subPage){
if(window.omniTimer!=null) clearInterval(window.omniTimer);
if(window.s_ea!=undefined && window.setOmniValues){
var pageName = window.s_ea.pageName.substr(0, window.s_ea.pageName.lastIndexOf(":"))+":"+subPage;
window.setOmniValues('','','','','','',1,'','',pageName);
}else{
// the omni script may not have been executed yet. Defer the call.
window.omniTimer = setInterval("makeOmniCall('"+subPage+"');",1000,"JavaScript");
}
}
function onAgeSelect(){
// assemble the birthdate
var bdM = document.getElementById("ageSelector_month").value;
var bdD = document.getElementById("ageSelector_day").value;
var bdY = document.getElementById("ageSelector_year").value;
if(bdD.length>0 && bdM.length>0 && bdY.length>0){
// set the cookie with this birtday info
var dtExp = new Date();
var dtToday = new Date();
dtExp.setFullYear(dtToday.getFullYear()+3);
var cookieValue = escape( bdM +"/"+bdD+"/"+bdY);
document.cookie = cookieName + "=" + cookieValue + "; expires=" + dtExp.toGMTString();
// hide the selector
var container = document.getElementById("ageGate");
container.style.visibility="hidden";
container.style.display="none";
container.innerHTML=" ";
// now check the date
checkAndActOnAge(cookieValue);
}
}
function checkAndActOnAge(ageCookieValue){
dtNow = new Date();
dtBD = new Date(unescape(ageCookieValue));
age = dtNow.getFullYear() - dtBD.getFullYear();
if(dtNow.getMonth() < dtBD.getMonth()) age--;
else if(dtNow.getMonth() == dtBD.getMonth() && dtNow.getDate() < dtBD.getDate()) age--;
if(age < requiredAge){
if(!isIndex){
// redirect to the index page, where an underage msg will be displayed
location.replace("index.jsp");
}else{
// we are at the index page. Display the underage message
makeOmniCall("AgeGateUnderAge");
displayUnderAgeMsg();
}
}else if(isIndex){
// the person is old enough, no need to deal with age -> go to home page
//makeOmniCall("AgeGatePass"); /* decided not to log this. the user will first be logged at the home page, which implied this call */
document.location = "home.jsp";
} // fyi, if the person is old enough and is not at the index page, do nothing
}
function displayUnderAgeMsg(){
if(displayTimer!=null) clearInterval(displayTimer);
var container = document.getElementById("underAge");
var container2 = document.getElementById("ageGate");
if(container==null || container2==null){
// the required div may not have loaded yet. Wait for a while
displayTimer = setInterval("displayUnderAgeMsg();",500,"JavaScript");
}else{
container2.style.visibility = "hidden";
container2.style.display = "none";
container.style.visibility="visible";
container.style.display="block";
}
}
function displayAgeSelector(){
var container = document.getElementById("ageGate");
var container2 = document.getElementById("underAge");
if(displayTimer!=null) clearInterval(displayTimer);
if(container==null || container2==null){
// the required div may not have loaded yet. Wait for a while
displayTimer = setInterval("displayAgeSelector();",500,"JavaScript");
}else{
container2.style.visibility = "hidden";
container2.style.display = "none";
var htmlMonth = "";
var htmlDay = "";
var htmlYear = "";
container.innerHTML += htmlMonth + " " + htmlDay + " " + htmlYear + " ";
container.style.visibility = "visible";
container.style.display = "block";
}
}