 
function initialCheck(){
    // check if they have cookies enabled by creating and reading a test cookie
    var rightnow = new Date();
    var expireTimeOnTest = new Date(rightnow.getTime() + 30 * 60 * 1000 ); // plus 30 minutes
    document.cookie = "vugCookieTest=test;expires=" + expireTimeOnTest.toGMTString() + ";"
    if (document.cookie.indexOf('vugCookieTest') == -1){
        window.location = '/publish/sierra/en/home/age_gate.cookieerror.html';
    }
    //check to see if they have already failed. If they have redirect them.
    if(document.cookie.indexOf("fail") > 0){
        window.location = 'http://www.thebehemoth.com';
    }
}

submitClicked = 0;

function gateCheck(theForm, ageGate){
	// check if user has hit Submit already
	if (submitClicked == 1){
        alert("Please Click Submit Only Once");
        return false;
	}

	// check if their month/date combo is acceptable
	var daysInMonth = new Array(0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	selectedMonth = theForm.Birth_Month[theForm.Birth_Month.selectedIndex].value;
	selectedDay = theForm.Birth_Day[theForm.Birth_Day.selectedIndex].value;
	selectedYear = theForm.Birth_Year[theForm.Birth_Year.selectedIndex].value;
	if ((selectedMonth != "MM") && (selectedDay != "DD")){
		if ((selectedDay > daysInMonth[selectedMonth]) || ((selectedMonth == 2) && (selectedDay == 29) && (selectedYear % 4 != 0))){
            alert("Please Enter A Valid Birth Date");
			return false;
		}
	}

	var ageCookie = 0;
	var sysDate = new Date();
	sysDate.setYear(sysDate.getFullYear() - ageGate);
	var age = true;

	// see if a bad age has already been entered
	if(document.cookie.indexOf("fail") > 0){
		age = false;
        window.location = 'http://www.thebehemoth.com';
		ageCookie = 1;
	}

	if (ageCookie != 1){
		if ( (theForm.Birth_Month[theForm.Birth_Month.selectedIndex].value == "") || (theForm.Birth_Day[theForm.Birth_Day.selectedIndex].value == "") || (theForm.Birth_Year[theForm.Birth_Year.selectedIndex].value == "" ) ) {
            alert("Please Enter Your Birth Date To Continue");
			return false;
		}
		if (age == true){
			submittedDate = new Date();
			submittedDate.setDate( theForm.Birth_Day[theForm.Birth_Day.selectedIndex].value );
			submittedDate.setMonth( theForm.Birth_Month[theForm.Birth_Month.selectedIndex].value - 1 );
			submittedDate.setYear( theForm.Birth_Year[theForm.Birth_Year.selectedIndex].value );

			var today = new Date();
			var expireTimeOnFail = new Date(today.getTime() + 30 * 60 * 1000 ); // plus 30 min
			var expireTimeOnPass = new Date(today.getTime() + 24 * 60 * 60 * 1000 ); // plus 24 hours
			if (sysDate.valueOf() < submittedDate.valueOf()) {
				document.cookie = "ageGate=fail;expires=" + expireTimeOnFail.toGMTString() + ";path=/;"
				age=false;
                window.location = 'http://www.thebehemoth.com';
                return false;
			} else {
				document.cookie = "ageGate=pass;expires=" + expireTimeOnPass.toGMTString() + ";path=/;"
				submitClicked = 1;		//stop user from submitting 2x
				window.location = theForm.successurl.value;
                return false;
			}
		} else {
            window.location = 'http://www.thebehemoth.com';
			return false;
		}
	} else {
		return false;
	}
}
