function calcAge(birthDate, birthMonth, birthYear){

if(birthDate=='bad' || birthMonth=='bad'){
yearsOld = 'bad';
}
else{
	dDate = parseInt(birthDate,10);
	dMonth = parseInt(birthMonth,10);
	dYear = parseInt(birthYear,10);

	if (ageForm.monthField.selectedIndex<1) return 'badMonth';
	if (ageForm.dateField.selectedIndex<1) return 'badDate';
	if (isNaN(dYear) || (birthYear.length!=4) || ((dYear + "").length!=birthYear.length)) return 'badYear';

	curDate = new Date();
	yearsOld = curDate.getFullYear() - dYear;
	monthsOld = (curDate.getMonth() + 1) - dMonth;
	daysOld = curDate.getDate() - dDate;

	if ((monthsOld < 0) || (monthsOld == 0 && daysOld < 0)) yearsOld --;
	if (yearsOld < 0) yearsOld = 'badYear';
}	
	return yearsOld;
}


function theCheck(){
	ageForm = document.forms.theForm;

	birthMonth = ageForm.monthField.options[ageForm.monthField.selectedIndex].value;
	birthDate = ageForm.dateField.value;
	birthYear = "19" + ageForm.yearField.value;
	
	lda = ageForm.locationField.value;

	dAge = calcAge(birthDate, birthMonth, birthYear);
	
	    	if(dAge=='bad' || dAge=='badYear' || dAge=='badMonth' || dAge=='badDate' || ageForm.locationField.value=='bad'){
				if(dAge=='bad' || ageForm.locationField.value=='bad'){
				alert("Please complete the required fields");
				}				
				if (dAge == 'badMonth'){
				//ageForm.monthField.focus();
				alert("Please enter a valid month");
				}
				if (dAge == 'badDate'){
				//ageForm.dayField.focus();
				alert("Please enter a valid day");
				}
				if (dAge == 'badYear'){
				//ageForm.yearField.focus();
				alert("Please enter a valid year");
				ageForm.yearField.value=''
				}	
		}			
		else {	
				if (dAge >=lda){
				//alert("Welcome");
				document.location.href="site/sub/intro.php"
				}
				else if (dAge < lda && dAge > 0){
				alert("YOU MUST BE OF LEGAL DRINKING AGE TO ENTER THIS WEB SITE.");
				//document.location.href="";
				return;
			 	}
		}
}
