var AgeGate = {
	validate: function() {
		var day=Trim($("day").value);
		var month=Trim($("month").value);
		var year=Trim($("year").value);
		
		var error = false;
		var str = "";

		//Check for null or empty
		error = (month==null || year == null || day==null || !this.monthClicked || !this.dayClicked || !this.yearClicked);
		error = error||(month.length==0 || year.length==0 || day.length==0);
		
		if (error){
			alert("Enter all fields.");
			return false;
		}
		
		var d = new Date();
		
		if (!checknumber(month) || (month<0) || (month>12)){
			alert("problem with month");
			return false;
		}
		
		if (!checknumber(day) || (day<0) || (day>31)){
			alert("problem with day");
			return false;
		}
		
		if (!checknumber(year) || (year>=d.getFullYear())){
			alert("problem with year");
			return false;
		}
		
		document.birthdate.submit();
	},
	clear: function(obj) {
		if (eval("this."+obj.id+"Clicked")==false){
			obj.value = "";
			eval("this."+obj.id+"Clicked=true;");
		}
	},
	monthClicked:false,
	dayClicked:false,
	yearClicked:false
}

function Trim(str){
	while(str.charAt(0) == (" ") ){
		str = str.substring(1);
	}
	while(str.charAt(str.length-1) == " " ){
		str = str.substring(0,str.length-1);
	}
	return str;
}


function checknumber(x){
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	return anum.test(x);
}




// This page is used only in the Get Birthday Page
function CheckAgeGateOK(IndexPage, SorryPage, NoCookiePage){
 // return 0 : The user is under age or an error occured
 // return 1 : The user has the right to see the page or there is no AgeGate
 // return 2 : The user browser refuse cookie
 	return;
	
	switch(isAgeOK()){
		case 0: location.href = SorryPage;break;
		case 1 : location.href = IndexPage;break;
		case 2 : location.href = NoCookiePage;	break;
	}
}
