function setHiddenDate(ddMonthYear, ddDay, hiddenDate, timeDirect)
{
	var ddMonth;
	var ddYear;
	var ddDayValue;
	var thisDate = new Date();
	var thisMonth = thisDate.getMonth() + 1;
	var thisYear = thisDate.getFullYear();
	// need to increment Month and day b/c they are arrays
	var ddMonthYearVal = (ddMonthYear.options[ddMonthYear.selectedIndex].value - 0) + 1;
	
//	if (String(ddMonthYearVal).length > 4) {
//	  var ddYear = String(ddMonthYearVal).substr((String(ddMonthYearVal).length - 4), 4)
//	  var ddMonthYearVal = String(ddMonthYearVal).substr(0, (String(ddMonthYearVal).length - 4))
//	  alert (ddMonthYearVal);
//	  alert (ddYear);
//	}
		
	ddDayValue = (ddDay.options[ddDay.selectedIndex].value - 0)
	if (timeDirect > 0)
	{
		ddMonth = getActualMonthVal(ddMonthYearVal)
		ddYear = thisYear + getMyYear(thisMonth, ddMonthYearVal);
	}
	else
	{
		ddMonth = ddMonthYearVal;
		ddYear = thisYear + getMyPastYear(thisMonth, ddMonthYearVal);
	}
	if (ddMonth < 10)
	{
		ddMonth = "0" + ddMonth;
	}
	if (ddDayValue < 10)
	{
		ddDayValue = "0" + ddDayValue ;
	}
	if (ddYear < 10)
	{
		ddYear = "0" + ddYear
	}
	newDate = ddMonth + "/" + ddDayValue + "/" + ddYear;
	
	//alert(newDate);
	setDate(hiddenDate, newDate)
}
function getActualMonthVal(curMonth)
{
	var actualMonthVal = curMonth;
	if (actualMonthVal > 12)
	{
		actualMonthVal = actualMonthVal - 12
		actualMonthVal = getActualMonthVal(actualMonthVal)
	}
	return actualMonthVal;
}
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();
	// need to increment Month and day b/c they are arrays
	var ddMonthYearVal = (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;
	}
}

function setDaysDropDownMMYYYY(selectBoxMonthYear, selectDay, timeDirect)
{
	var f = selectBoxMonthYear.form;
	var curDays;
	var totalDays;
	var myMonth;
	var myYear;
	
	var ddMonthYearVal = (selectBoxMonthYear.options[selectBoxMonthYear.selectedIndex].value - 0);
	var selectDayIndex = selectDay.selectedIndex;

	var ddYear = String(ddMonthYearVal).substr((String(ddMonthYearVal).length - 4), 4)
	var ddMonthYearVal = String(ddMonthYearVal).substr(0, (String(ddMonthYearVal).length - 4))

	if (timeDirect > 0)
	{
		myMonth = getActualMonthVal(ddMonthYearVal)
		myYear = ddYear;
	}
	else
	{
		myMonth = ddMonthYearVal;
		myYear = ddYear;
	}
	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;
	}
}

function getActualYearVal(curMonth, curYear)
{
	if (curMonth > 12) 
	{
		curMonth = curMonth - 12
		curYear = curYear + 1
		curYear = getActualYearVal(curMonth, curYear)
	}
	return curYear;
}
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;
}
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;
}
function getMyMonth(startMonth, dateIndex)
{
// this function gets the month from the 12 mo drop down
	var myMonth = startMonth + dateIndex;
	if (myMonth > 12)
	{
		myMonth = myMonth - 12;
	}
	return myMonth;
}
function getMonthIndex(startMonth, selMonth)
{
//	alert (startMonth)
//	alert (selMonth)
	var myIndex;
	if (selMonth < startMonth)
	{
		selMonth = selMonth + 12;
	}
	myIndex = selMonth - startMonth;
//	alert(myIndex);
	return myIndex;
}
function setDate(hdDate, value)
{
	hdDate.value = value;
}
// 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);
}

// 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);
    }
}
    function setIntlDate(dateId){
        
        var dateUS = document.getElementById(dateId).value;
        var dateEuro = "";
        var  temp = new Array();
        
        // split the US date(mm/dd/yyyy) and rearrange into a European date(dd/mm/yyyy)
        temp = dateUS.split("/");
        dateEuro = temp[1] + "/" + temp[0] + "/" + temp[2];

        //alert (dateEuro);

        document.getElementById(dateId).value = dateEuro;
    }