//----------------------------------------------------------------------------------------
function get_date_limit(which,d1,d2) {
//----------------------------------------------------------------------------------------

	var today = new Date();

	date1 = today;
	date2 = today;

	/* Test dates */

	//today = new Date(2000,2,29);
	//today = new Date(1999,1,14);
	/*************/

	var MonthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

	theYear = today.getYear();
	if (theYear < 1000) theYear +=1900;

	if (which == 'Today') {
		date1 = today;
		date2 = today;
	} else if (which == 'Yesterday') {
		var milliseconds = Date.UTC(today.getYear(),today.getMonth(),today.getDate());
		milliseconds -= 86400000;
		date1 = new Date(milliseconds);
		date2 = new Date(milliseconds);
	} else if (which == 'LastYear') {
		date1 = new Date(theYear-1,0,1);
		date2 = new Date(theYear-1,11,31);
	} else if (which == '-Year') {
		date1 = new Date(parseInt(d1.value.substr(6,4))-1,0,1);
		date2 = new Date(parseInt(d2.value.substr(6,4))-1,11,31);
	} else if (which == '+Year') {
		date1 = new Date(parseInt(d1.value.substr(6,4))+1,0,1);
		date2 = new Date(parseInt(d2.value.substr(6,4))+1,11,31);
	} else if (which == 'ThisYear') {
		date1 = new Date(theYear,0,1);
		date2 = new Date(theYear,11,31);
	} else if (which == 'NextYear') {
		date1 = new Date(theYear+1,0,1);
		date2 = new Date(theYear+1,11,31);
	} else if (which == 'LastMonth') {

		if (today.getMonth()==0) {
			  date1 = new Date(theYear-1,11,1);
			  date2 = new Date(theYear-1,11,MonthDays[11]);
		}
		else {
			 date1 = new Date(theYear,today.getMonth()-1,1);
			 LastMonth = today.getMonth()-1;
			 DaysInLastMonth = MonthDays[LastMonth];
			 if (LastMonth == 1) {
				  // February
				  if (theYear%400==0 || (theYear%4 == 0 && theYear%100!=0) )
						DaysInLastMonth +=1;
			}
			date2 = new Date(theYear,today.getMonth()-1,DaysInLastMonth);
		}
	} else if (which == 'ThisMonth') {

		 date1 = new Date(theYear,today.getMonth(),1);
		 LastMonth = today.getMonth();
		 DaysInLastMonth = MonthDays[LastMonth];
		 if (LastMonth == 1) {
			  // February
			  if (theYear%400==0 || (theYear%4 == 0 && theYear%100!=0) )
					DaysInLastMonth +=1;
		}
		date2 = new Date(theYear,today.getMonth(),DaysInLastMonth);

	} else if (which == 'NextMonth') {

		if (today.getMonth()==11) {
			theYear++;
			date1 = new Date(theYear,0,1);
			date2 = new Date(theYear,0,MonthDays[11]);
		}
		else {
			 date1 = new Date(theYear,today.getMonth()+1,1);
			 LastMonth = today.getMonth()+1;
			 DaysInLastMonth = MonthDays[LastMonth];
			 if (LastMonth == 1) {
				  // February
				  if (theYear%400==0 || (theYear%4 == 0 && theYear%100!=0) )
						DaysInLastMonth +=1;
			}
			date2 = new Date(theYear,today.getMonth()+1,DaysInLastMonth);
		}
	} else if (which == '-Month') {

		var xd1 = new Date(d1.value.substr(6,4),d1.value.substr(3,2)-1,d1.value.substr(0,2));
		var xd2 = new Date(d2.value.substr(6,4),d2.value.substr(3,2)-1,d2.value.substr(0,2));

		theYear1 = xd1.getYear();
		if (theYear1 < 1000) theYear1 +=1900;

		theYear2 = xd2.getYear();
		if (theYear2 < 1000) theYear2 +=1900;

		if (xd1.getMonth()==0) {
			  date1 = new Date(theYear1-1,11,1);
		}
		else {
			 date1 = new Date(theYear1,xd1.getMonth()-1,1);
			 LastMonth = xd1.getMonth()-1;
			 DaysInLastMonth = MonthDays[LastMonth];
			 if (LastMonth == 1) {
				  // February
				  if (theYear1%400==0 || (theYear1%4 == 0 && theYear1%100!=0) )
						DaysInLastMonth +=1;
			}
		}
		if (xd2.getMonth()==0) {
			date2 = new Date(theYear2-1,11,MonthDays[11]);
		} else {
			LastMonth = xd2.getMonth()-1;
			DaysInLastMonth = MonthDays[LastMonth];
			date2 = new Date(theYear2,xd2.getMonth()-1,DaysInLastMonth);
		}
	} else if (which == '+Month') {

		var xd1 = new Date(d1.value.substr(6,4),d1.value.substr(3,2)-1,d1.value.substr(0,2));
		var xd2 = new Date(d2.value.substr(6,4),d2.value.substr(3,2)-1,d2.value.substr(0,2));

		theYear1 = xd1.getYear();
		if (theYear1 < 1000) theYear1 +=1900;

		theYear2 = xd2.getYear();
		if (theYear2 < 1000) theYear2 +=1900;

		if (xd1.getMonth()==11) {
			date1 = new Date(theYear1+1,0,1);
		}
		else {
			date1 = new Date(theYear1,xd1.getMonth()+1,1);
		}
		if (xd2.getMonth()==11) {
			date2 = new Date(theYear2+1,0,MonthDays[0]);
		}
		else {
			LastMonth2 = xd2.getMonth()+1;
			DaysInLastMonth2 = MonthDays[LastMonth2];
			date2 = new Date(theYear2,xd2.getMonth()+1,DaysInLastMonth2);
		}
	} else if (which == 'LastWeek') {
		StartOfLastWeekMS = today.getTime() - ( 24*60*60*1000*(today.getDay()+6));
		date1 = new Date(StartOfLastWeekMS);
		date2 = new Date(StartOfLastWeekMS+24*60*60*1000*6);
	} else if (which == 'ThisWeek') {
		StartOfLastWeekMS = today.getTime() - ( 24*60*60*1000*(today.getDay()-1));
		date1 = new Date(StartOfLastWeekMS);
		date2 = new Date(StartOfLastWeekMS+24*60*60*1000*6);
	} else if (which == 'NextWeek') {
		StartOfLastWeekMS = today.getTime() + ( 24*60*60*1000*(today.getDay()-1));
		date1 = new Date(StartOfLastWeekMS);
		date2 = new Date(StartOfLastWeekMS+24*60*60*1000*6);
	}

	date1 = ((date1.getDate() < 10) ? '0' + date1.getDate() : date1.getDate()) +
				'.' + (((date1.getMonth() + 1) < 10) ? '0' + (date1.getMonth() + 1) : (date1.getMonth() + 1)) +
				'.' + ((date1.getFullYear() < 1000) ? date1.getFullYear() + 1900 : date1.getFullYear());

	date2 = ((date2.getDate() < 10) ? '0' + date2.getDate() : date2.getDate()) +
				'.' + (((date2.getMonth() + 1) < 10) ? '0' + (date2.getMonth() + 1) : (date2.getMonth() + 1)) +
				'.' + ((date2.getFullYear() < 1000) ? date2.getFullYear() + 1900 : date2.getFullYear());
	//date1 = date1.getDate() + '.' + (date1.getMonth() + 1) + '.' + date1.getFullYear();
	//date2 = date2.getDate() + '.' + (date2.getMonth() + 1) + '.' + date2.getFullYear();

	d1.value = date1;
	d2.value = date2;
}
