﻿function clearApproximateAgeField(pickerID)
{
    var approximateAgeField = jQuery("#approximateAgeField_" + pickerID).get(0);
    var birthDateMonthList = jQuery("#birthDateMonthList_" + pickerID).get(0);
    var birthDateDayField = jQuery("#birthDateDayField_" + pickerID).get(0);
    var birthDateYearList = jQuery("#birthDateYearList_" + pickerID).get(0);        
    
    if (approximateAgeField && birthDateMonthList && birthDateDayField && birthDateYearList)
    {
        approximateAgeField.value = "";
        birthDateMonthList.style.color = "";
        birthDateDayField.style.color = "";
        birthDateYearList.style.color = "";
    } 
}

function checkApproximateFields(pickerID, currentYear)
{
    var approximateAgeField = jQuery("#approximateAgeField_" + pickerID).get(0);
    var approximateYearCheckbox = jQuery("#approximateYearCheckbox_" + pickerID).get(0);
    var birthDateMonthList = jQuery("#birthDateMonthList_" + pickerID).get(0);
    var birthDateDayField = jQuery("#birthDateDayField_" + pickerID).get(0);
    var birthDateYearList = jQuery("#birthDateYearList_" + pickerID).get(0);
    
    if (approximateAgeField && approximateYearCheckbox && birthDateMonthList && birthDateDayField && birthDateYearList)
    {    
        if (approximateAgeField.value.length > 0 && !isNaN(approximateAgeField.value))
        {
            // use approximate age
            approximateYearCheckbox.checked = false;
            var approximateAge = parseInt(approximateAgeField.value);
            var approximateYear = currentYear - approximateAge;
            for (var i = 0; i < birthDateYearList.length; i++)
            {
                if (birthDateYearList.options[i].value == approximateYear)
                {
                    birthDateYearList.selectedIndex = i;
                    break;
                }
            }
            
            birthDateMonthList.style.color = "#999999";
            birthDateDayField.style.color = "#999999";
            birthDateYearList.style.color = "#999999";
        }
        else if (approximateYearCheckbox.checked)
        {
            // use approximate year
            approximateAgeField.value = "";
            birthDateYearList.style.fontStyle = "italic";
            birthDateYearList.style.color = "#999999";
            
        }
        else
        {
            // use full birth date
            birthDateMonthList.style.color = "";
            birthDateDayField.style.color = "";
            birthDateYearList.style.color = "";
            birthDateYearList.style.fontStyle = "";
        }
        
    }
    
}