function days_between(date1, date2) {

    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms)
    
    // Convert back to days and return
    return Math.round(difference_ms/ONE_DAY)

}


// check for valid numeric strings
function IsNumeric(strString) {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
	return blnResult;
}


function checkEligibility(month, day, year) {

	if (month.length == 0 || day.length == 0 || year.length == 0){
		document.getElementById('result').setAttribute('class','alert');
		document.getElementById('result').setAttribute('className','alert');
		document.getElementById('result').innerHTML = "All fields are required.";
		document.getElementById('result').style.display = 'block';
		return 0;
	}
	
	// set cutoff day
	var cutoff = new Date(2010,6,1);
	// set up DOB date object
	var dob = new Date(year,month,day);
	
	if (days_between(dob,cutoff) > 8036) {
		document.getElementById('result').setAttribute('class','alert');
		document.getElementById('result').setAttribute('className','alert');
		var result = "Sorry, you are over the maximum age limit to march in a Drum Corps International corps.";
	}
	else if (days_between(dob,cutoff) < 5479) {
		document.getElementById('result').setAttribute('class','alert_green');
		document.getElementById('result').setAttribute('className','alert_green');
		var result = "Congratulations, you are below the maximum age limit to march in a Drum Corps International corps. Please check with the corps you are interested in for any minimum age requirements.";
	}
	else {
		document.getElementById('result').setAttribute('class','alert_green');
		document.getElementById('result').setAttribute('className','alert_green');
		var result = "Congratulations, you are within the eligible age limit to march in a Drum Corps International corps.";
	}
	
	document.getElementById('result').innerHTML = result;
	document.getElementById('result').style.display = 'block';
}
