    function leapyear(a) {
	if(((a % 4 == 0) && (a % 100 != 0)) || (a % 400 == 0))
	    return true;
	else 
	    return false;
    }
    function lyear(a) {
	if(((a % 4 == 0) && (a % 100 != 0)) || (a % 400 == 0)) return true;
	else return false;
    }


function get_age(dd, mm, yy)
{
    var main = true;
    if (((mm == 4) || (mm == 6) || (mm == 9) || (mm == 11)) && (dd > 30))
	main = false;
    else if (mm == 2) {
	if (dd > 29)
	    main = false;
	else if((dd > 28) && (!lyear(yy)))
	    main = false;
    }

    if (!main) 
	{	
	    alert("Please enter a valid date");
	    age = false;
	}
    else 
	{
	    days = new Date();
	    gdate = days.getDate();
	    gmonth = days.getMonth();
	    gyear = days.getYear();
	    if (gyear < 2000) gyear += 1900;
	    age = gyear - yy;
	    if((mm == (gmonth + 1)) && (dd <= parseInt(gdate))) 
		{
		    age = age;
		}
	    else {
		if(mm <= (gmonth)) 
		    {
			age = age;
		    }
		else 
		    {
			age = age - 1; 
		    }
	    }
	    
	}
    return age;    
}

function denyAccess()
{

} 

function checkUser(form)
{
    
    var country_val = form.country.value;
    var day_val = form.day.value;
    var month_val = form.month.value;
    var year_val = form.year.value;
    
    if (country_val == "00") alert("Please select a Country");
    else if (country_val == "999") denyAccess();
    else if (day_val == "00") alert("Please select a Day");
    else if (month_val == "00") alert("Please select a Month");
    else if (year_val == "00") alert("Please select a Year");
    else {
	var age_val = get_age(day_val, month_val, year_val);
	if (age_val)
	    {
		if (country_val > age_val)
		    denyAccess();
		else
		    document.location="home.html";
	    }
    }
    return false;
}

function denyAccess()
{
    alert("We're sorry we can't let you in because your country's law prohibits access to this site.");
    
}

window.onload = function () { document.getElementById('submitbutton').disabled=false; }

