/*
clearDropDown(dDown)
and the extra blank <option></option>s on the html page
are simply for netscape display corrections and may be removed if that is not a issue
*/

var allowBlankDay = false;
function populateDays(yearSelect, monthSelect, daySelect) {
	var monthLength = new Array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	
	// month length for feb in a leap year is 29
	var year = parseInt(yearSelect.options[yearSelect.selectedIndex].value);
	if (year % 4 == 0 && (year % 100 != 0 && year % 400 != 0)) monthLength[2] = 29;
	
	// get last day in days dropdown
	var currentNumDays = 0;
	for (var i = daySelect.options.length-1; i >= 0; i--) {
		var numValue = parseInt(daySelect.options[i].value);
      if (!isNaN(numValue) && numValue > currentNumDays) currentNumDays = numValue;
	}

	var currentMonth = parseInt(monthSelect.options[monthSelect.selectedIndex].value);
	
	// repopulate days dropdown if number of days should change
	if (!isNaN(currentMonth) && monthLength[currentMonth] != currentNumDays) {
	
		// remember current day selection
		var currentSelectedDay = daySelect.options[daySelect.selectedIndex].value;
		
		// repopulate days
		daySelect.options.length = 0;
      daySelect.selectedIndex = -1;
      if (allowBlankDay) daySelect.options[0] = new Option('--', '');
		for (var i = 1; i <= monthLength[currentMonth]; i++) {
			//status = i;
         var day = daySelect.options.length;
         var isSelected = (i == currentSelectedDay);
			daySelect.options[day] = new Option(i, i, isSelected, isSelected);
		}
	}
}

function isValidAge(years, yearSelect, monthSelect, daySelect) {
         
   var today = new Date();
   var todayYear = today.getFullYear();
   var todayMonth = today.getMonth() + 1;
   var todayDay = today.getDate();
   
   if (todayYear - yearSelect.options[yearSelect.selectedIndex].value > years) {   
      return true;
   }
   else if (todayYear - yearSelect.options[yearSelect.selectedIndex].value == years) {
      //alert(todayDay - daySelect.options[daySelect.selectedIndex].value >= 0)
      
      if (todayMonth - monthSelect.options[monthSelect.selectedIndex].value > 0) {    
         return true;
      }
      else if (todayMonth - monthSelect.options[monthSelect.selectedIndex].value == 0 && todayDay - daySelect.options[daySelect.selectedIndex].value >= 0) {
         return true;
      }
   }
   return false;
}

function checkedAge(form) {
   if (isValidAge(13, form.startDate_year, form.startDate_month, form.startDate_day)) {
      setCookie('passed', 'oldenough','','/');
      top.location = 'shoutout.shtml';
      }
      else {
         top.location = 'shoutout_sorry.shtml';
      }
}  
