function dateInPast(object, params)
{
    /* Validate a smarty html_select_date */
    var val = params['prefix'] + 'Day';
    var day = document.getElementById(val);
	val = params['prefix'] + 'Month';
    var month = document.getElementById(val);
	val = params['prefix'] + 'Year';
    var year = document.getElementById(val);

    if(params['allow_empty'])
	{
		if(year.value == "" && month.value == "" && day.value == "")
		{
			return true;
		}
	}


    if(day.value == '')
	{
		return false;
	}

	if(month.value == '')
	{
		return false;
	}

	if(year.value == '')
	{
		return false;
	}

    var last_day_of_month = get_last_day_of_month(month.value, year.value);
    if(day.value > last_day_of_month)
    {
        return false;
    }


    // date is valid here
    var today = new Date();
    var formDate = new Date(year.value, month.value-1, day.value)

    var result = false;
    if(formDate.getTime() <= today.getTime())
		result = true;

	return result;
}


function get_last_day_of_month(month, year)
{
    var last_day_of_month;
    if((month == 4) || (month == 6) || (month == 9) || (month == 11))
    {
        last_day_of_month = 30;
    }
    else if(month == 2)
    {
        last_day_of_month = is_leap_year(year) ? 29 : 28;
    }
    else
    {
        last_day_of_month = 31;
    }

    return last_day_of_month;
}

// function to check leap year
function is_leap_year(year)
{
    if (year % 4 != 0)
    {
        return false;
    }
    else if (year % 400 == 0)
    {
        return true;
    }
    else if (year % 100 == 0)
    {
        return false;
    }
    else
    {
        return true;
    }
}