function getActualMonthVal(curMonth)
{
	var actualMonthVal = curMonth;
	if (actualMonthVal > 12)
	{
		actualMonthVal = actualMonthVal - 12
		actualMonthVal = getActualMonthVal(actualMonthVal)
	}
	return actualMonthVal;
} //getActualMonthVal
function setDaysDropDown(selectBoxMonthYear, selectDay, timeDirect)
{
	//var f = selectBoxMonthYear.form;
	var curDays;
	var thisDate = new Date();
	var totalDays;
	var myMonth;
	var myYear;
	
	var thisMonth = thisDate.getMonth() + 1;
	//var thisYear = thisDate.getFullYear();
	var thisYear = $(selectBoxMonthYear).val().split(",")[1];
		
	// need to increment Month and day b/c they are arrays
	var ddMonthYearVal = $(selectBoxMonthYear).val().split(",")[0]; //(selectBoxMonthYear.options[selectBoxMonthYear.selectedIndex].value - 0) + 1;
	var selectDayIndex = selectDay.selectedIndex;
	if (timeDirect > 0)
	{
		myMonth = getActualMonthVal(ddMonthYearVal)
		myYear = thisYear + getMyYear(thisMonth, ddMonthYearVal);
	}
	else
	{
		myMonth = ddMonthYearVal;
		myYear = thisYear + getMyPastYear(thisMonth, ddMonthYearVal);
	}
	totalDays = getTotalDaysInMonth(myMonth, myYear);
	//alert(totalDays)
	// find out how many days currently
	curDays = selectDay.options.length;
	if (curDays	> totalDays)
	{
		selectDay.options.length = totalDays;
	}
	else if (curDays < totalDays)
	{
		var myNewOpt; 
		for (i=curDays+1; i<=totalDays; i++)
		{
			myNewOpt = new Option(i, i)
			selectDay.options[selectDay.options.length] = myNewOpt;
		}
	}
	// if the total number of days in the new month is > previous selected month
	// select the top one
	//alert("for " + selectDay.name + "\ntotalDays " + totalDays + "\nselectDayIndex " + selectDayIndex);
	if (totalDays <= selectDayIndex)
	{
		//alert("should set selectedIndex = " + (totalDays - 1))
		selectDay.selectedIndex = (totalDays - 1);
		//alert(selectDay.selectedIndex);
	}
	else
	{
		// otherwise select the previously selected one
		selectDay.selectedIndex = selectDayIndex;
	}
} //setDaysDropDown


function getActualYearVal(curMonth, curYear)
{
	if (curMonth > 12) 
	{
		curMonth = curMonth - 12
		curYear = curYear + 1
		curYear = getActualYearVal(curMonth, curYear)
	}
	return curYear;
} //getActualYearVal

function getMyYear(startMonth, dateIndex)
{
	// this function gets the year from the 12 mo drop down
	var myYear = 0;
	//	alert ("startMonth = " + startMonth)
	//	alert ("dateIndex = " + dateIndex)
	if (dateIndex > 12)
	{
		myYear = getActualYearVal(dateIndex, myYear)
	}
/*	old code

	if (startMonth > dateIndex)
	{
		myYear = myYear + 1;
	}
*/
//	alert (myYear);
	return myYear;
} //getMyYear

function getMyPastYear(startMonth, dateIndex)
{
	// this function gets the year from the 12 mo drop down
	var myYear = 0;
	//alert (startMonth)
	//alert (dateIndex)
	if (startMonth < dateIndex)
	{
		myYear = myYear - 1;
	}
	//alert ("myYear = " + myYear);
	return myYear;
} //getMyPastYear



// GET NUMBER OF DAYS IN MONTH
function getTotalDaysInMonth(month,year)  
{
    var days = 0;
    if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
    {
    	days=31;
    }
    else if (month==4 || month==6 || month==9 || month==11) 
	{
		days=30;
	}
    else if (month==2)  
    {
        if (isALeapYear(year)) 
        {
            days=29;
        } 
        else 
        {
            days=28;
        }
    }
    return (days);
} //getTotalDaysInMonth

// CHECK TO SEE IF YEAR IS A LEAP YEAR
function isALeapYear (Year) 
{
    if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) 
    {
        return (true);
    } 
    else 
    {
        return (false);
    }
} //isALeapYear
