//###########################################################
//  Begin Arrays
//###########################################################
var $aryAllMonths = new Array('Prefer Not to Answer','January','February','March','April','May','June','July','August','September','October','November','December');
var January = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");
var March = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");
var July = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");
var August = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");
var October = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");
var December = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");
var May = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");
var April = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30");
var June = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30");
var September = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30");
var November = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30");
var February = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29");

//########### END ARRAYS  ####################################
//`````````````````````````````````````````````````````````````

/*############################################################
// Begin Functions
//############################################################ */


function enableDisablePair($item){
    var $pairid = $item.id + '-specific';
    var $pair = document.getElementById($pairid);    
    
    if($item.checked){
        $pair.disabled = false;
        $pair.focus();
    } else {
        $pair.disabled = true;
    }
}

function SetUpCheckboxes($checkboxes){
    for($i=0;$i<$checkboxes.length;$i++){
        enableDisablePair(document.getElementById($checkboxes[$i]));
    }  
}

/**
*  Populates the day element for a selected month
*  
*  the purpose of this functi0n is to take the selected month then 
*  evaluate the array that matches the month, then add each element 
*  in that months array into the EffdtDay select form component.
*
*  @param string month_chosen
*  @param string chosengroup
*  @returns void
*/
function chooseMonth (month_chosen,chosengroup)
{
    if(month_chosen == ""){
        return false;
    } else {
        var chosenmonth = document.getElementById(chosengroup + '-month');
        var adjustday = document.getElementById(chosengroup + '-day');
        var chosenyear = document.getElementById(chosengroup + '-year');
        
        if(chosenmonth.length > 13) {
            chosenmonth[0] = null;
        }

        if(month_chosen == "Prefer Not to Answer"){
            adjustday.disabled = true;
            chosenyear.disabled = true;
        } else {
            var this_month = eval(month_chosen);
            
            if(adjustday.disabled == true || chosenyear.disabled == true){
                adjustday.disabled = false;
                chosenyear.disabled = false;    
            }
            
            setOptionText(adjustday, this_month);
            
            if(month_chosen == 'February' && TestForLeapYear(chosenyear.value) && this_month.length < 29){
                var j = adjustday.options.length;
                adjustday.options.length = j + 1;
                adjustday.options[j].text = "29";
                adjustday.options[j].value = "29";
            }
            
            adjustday.options[0].select;        
        }
    } 
}


/**
*    the purpose of this function is to find the length of the
*    the months array (total number of days) and set the number
*    of select options to the same.  then for each element in
*    the months array, create an option in the select. 
*/
function setOptionText(the_select, the_array)
{
  the_select.options.length = the_array.length;
  for (i=0; i < the_array.length; i++)
  {
    the_select.options[i].text = the_array[i];
    the_select.options[i].value = the_array[i];
  }
}

function TestForLeapYear(chosen_year){ 
    var testyear = chosen_year/4; 
    testyear = testyear.toString(); 
    testyear = testyear.split("."); 
    
    if(testyear.length == 1){ 
        return true; 
    } else { 
        return false; 
    } 
}

function resetDays(day_element){
    $days = document.getElementById(day_element + '-day');
    $days.options.length = 0;
    $days.options.length = 1;
    $days.options[0].text = "<-------";
    $days.options[0].value = "";
}

function resetMonths(month_element){
    $month = document.getElementById(month_element + '-month');
    $month.options.length = 0;
    $month.options.length = 12;
    $month.options[0] = new Option('Please Choose a Month','');
    
    for($i=1;$i<=$aryAllMonths.length;$i++){
        $j = $i - 1;
        $month.options[$i] = new Option($aryAllMonths[$j],$aryAllMonths[$j]); 
    }
}
