﻿function loadBirthdayDays(){
	// Get the month dropdownlist
	var ddlBirthdayMonth = $get(ddlBirthdayMonthClientID);

	if (ddlBirthdayMonth){
		// Get the selected month
		var Month = ddlBirthdayMonth.options[ddlBirthdayMonth.selectedIndex].value;
		
		// Get the day dropdownlist
		var ddlBirthdayDay = $get(ddlBirthdayDayClientID);
		
		// Store the selected day
		var selectedDay = (ddlBirthdayDay.selectedIndex == 0) ? null : ddlBirthdayDay.options[ddlBirthdayDay.selectedIndex].value;

		// If the user selected the initial item, clear out the days dropdownlist
		if (Month == ''){
			resetBirthdayDropDownList(ddlBirthdayDay, 'Day');
		}
		else{
			var intLastDayOfMonth;
			switch(Month){
				case '1':
				case '3':
				case '5':
				case '7':
				case '8':
				case '10':
				case '12':
					intLastDayOfMonth = 31;
					break;
				case '4':
				case '6':
				case '9':
				case '11':
					intLastDayOfMonth = 30;
					break;
				case '2':
					intLastDayOfMonth = 29;
					break;
			}
			// Clear out the existing days
			ddlBirthdayDay.length = 0;
			
			// Add the first item
			objOption = new Option('Day', '', false, false);

			//	Add the option to the destination SELECT
			ddlBirthdayDay.options[0] = objOption;
	
			// Create a variable to day the index of the previously selected item
			var index = -1;
			
			for (i=1;i<=intLastDayOfMonth;i++){
				//	Create a new option with the value and text of the current option
				objOption = new Option(i, i, false, false);

				//	Add the option to the destination SELECT
				ddlBirthdayDay.options[ddlBirthdayDay.options.length] = objOption;
				
				// Update the index variable if this is the previously selected item
				if (selectedDay == i) {
					index = i;
				}
			}
			// Set the selected value
			ddlBirthdayDay.selectedIndex = (index == -1) ? 0 : index;

			ddlBirthdayDay.disabled = false;
		}
	}
}

function setBirthdayMonth(value){
	var hdnBirthdayMonth = $get(hdnBirthdayMonthClientID);
	hdnBirthdayMonth.value = value;
}

function setBirthdayDay(value){
	var hdnBirthdayDay = $get(hdnBirthdayDayClientID);
	hdnBirthdayDay.value = value;
}

function resetBirthdayDropDownList(ddlDropDownList, strFirstOptionText){
	// Clear out the existing stores
	ddlDropDownList.length = 0;
	// Disable the store dropdownlist
	ddlDropDownList.disabled = true;
	// Add the first item
	objOption = new Option(strFirstOptionText, '', false, false);
	ddlDropDownList.options[0] = objOption;
}

