function determineSubmit() { // driver
	var isFilled = allFilled();
	var isLegal = giveWarning();
	if( isFilled != "" ) {
		return isFilled;
	}
	else {
		return isLegal;
	}
}

function allFilled () { // when necessary fields are empty, return an error message to alert user
	var error = "";
	if( document.miller.email.value == "" ) { error = "Please enter email address"; }
	else if( document.miller.fname.value == "" ) { error = "Please enter first name"; }
	else if( document.miller.lname.value == "" ) { error = "Please enter last name"; }
	else if( document.miller.dobm.value == "" ) { error = "Please enter month of birth"; }
	else if( document.miller.dobd.value == "" ) { error = "Please enter day of birth"; }
	else if( document.miller.doby.value == "" ) { error = "Please enter year of birth"; }
	else if( document.miller.addr1.value == "" ) { error = "Please enter address"; }
	else if( document.miller.city.value == "" ) { error = "Please enter city"; }
	else if( document.miller.state.selectedIndex == 0 ) { error = "Please select a state"; }
	else if( document.miller.zip.value == "" ) { error = "Please enter zip code"; }
	else if( document.miller.daytimephone.value == "" ) { error = "Please enter daytime phone number"; }
	else if( isDate() != "" ) { error = isDate(); }
	return error;
}
function isDate( ) { // determines if the birthdate is a legal date
	var result = ""
	var month = document.miller.dobm.value;
	var day = document.miller.dobd.value;
	var year = document.miller.doby.value;
	if ((month <= 0) || (month > 12)) { result = "Invalid month"; }
	if ((day <= 0) || (day > 31)) { result = "Invalid date"; }
	if ((month == 2) && (day > 29)) { result = "Invalid date"; }             // February can't be greater than 29 (leap year calculation comes later)
	if ((month == 4) || (month == 6) || (month == 9) || (month == 11)) {     // check for months with only 30 days
		if (day > 30) { result = "Invalid date"; }
	}
	if ((year <= 0) || (year > 9999)) { result = "Invalid year"; }           // check for leap year if the month and day is Feb 29
	if ((month == 2) && (day == 29)) {
		var div4 = year % 4;
		var div100 = year % 100;
		var div400 = year % 400;
		if (div4 != 0) { result = "Invalid date"; }                      // if not divisible by 4, then not a leap year so Feb 29 is invalid
		if ((div100 == 0) && (div400 != 0)) { result = "Invalid Date"; } // if year is divisible by 100 and not 400, then it's not a leap year so Feb 29 is invalid
	}
	return result;
}

function giveWarning () { // determines if the applicant is eligible
	var result = "";
	today = new Date();
	age21 = new Date();
	age21.setYear( today.getYear() - 21 );
	givenDOB = new Date();
	givenDOB.setYear( document.miller.doby.value );
	givenDOB.setDate( document.miller.dobd.value );
	givenDOB.setMonth( document.miller.dobm.value - 1 ); // months start with 0
	     if(   ( givenDOB.getYear()  ) >  ( age21.getYear()  )   ) { result = "We're so sorry. You must be 21 years of age or older to participate in the Miller Lite Exclusive Photo Shoot Sweepstakes."; }
	else if( ( ( givenDOB.getYear()  ) == ( age21.getYear()  ) )   &&
	         ( ( givenDOB.getMonth() ) >  ( age21.getMonth() ) ) ) { result = "We're so sorry. You must be 21 years of age or older to participate in the Miller Lite Exclusive Photo Shoot Sweepstakes."; }
	else if( ( ( givenDOB.getYear()  ) == ( age21.getYear()  ) )   &&
	         ( ( givenDOB.getMonth() ) == ( age21.getMonth() ) )   &&
	         ( ( givenDOB.getDate()  ) >  ( age21.getDate()  ) ) ) { result = "We're so sorry. You must be 21 years of age or older to participate in the Miller Lite Exclusive Photo Shoot Sweepstakes."; }
	if( document.miller.state.value == "CA" ) { result = "We're so sorry. Due to state of California legal restrictions, California residents are not eligible to participate in the Miller Lite Exclusive Photo Shoot Sweepstakes."; }
	return result;
}
function ZeroFill(num) {
	return ((num <= 9) ? ("0" + num) : num);
}

