
			// depending on timezones, local settings and localization prefs, its possible for js to misinterpret the day,
			// but the humanized time is correct, so we activate the humanized time to sync the calendar

			function activate_calendars() {
				update_calendar('entry_date', document.getElementById('entry_date').value);
				update_calendar('expiration_date', document.getElementById('expiration_date').value);
}

		var format		= 'eu';
		var days		= new Array('П','В','С','Ч','П','С','В','П','В','С','Ч','П','С','В');
		var months		= new Array('Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь','Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь');
		var months_small= new Array('Янв','Фев','Мар','Апр','Май','Июн','Июл','Авг','Сен','Окт','Ноя','Дек','Янв','Фев','Мар','Апр','Май','Июн','Июл','Авг','Сен','Окт','Ноя','Дек');
		var last_click	= new Array();
		var current_month  = '';
		var current_year   = '';
		var last_date  = '';

		function calendar(id, d, highlight)
		{
			this.id			= id;
			this.highlight	= highlight;
			this.date_obj	= d;
			this.write		= build_calendar;
			this.total_days	= total_days;
			this.month		= d.getMonth();
			this.date		= d.getDate();
			this.day		= d.getDay();
			this.year		= d.getFullYear();
			this.hours		= d.getHours();
			this.minutes	= d.getMinutes();
			this.seconds	= d.getSeconds();
			this.date_str	= date_str;

			if (highlight == false)
			{
				this.selected_date = '';
			}
			else
			{
				this.selected_date = this.year + '' + this.month + '' + this.date;
			}


			//	Set the "selected date"

			// As we toggle from month to month we need a way
			// to recall which date was originally highlighted
			// so when we return to that month the state will be
			// retained.  Well set a global variable containing
			// a string representing the year/month/day

			//get the first day of the month's day
			d.setDate(1);

			this.firstDay = (d.getDay()+6)%7;

			//then reset the date object to the correct date
			d.setDate(this.date);
		}

		//	Build the body of the calendar

		function build_calendar()
		{
			var str = '';

			//	Calendar Heading

			str += '<div id="cal' + this.id + '">';
			str += '<table class="calendar" cellspacing="0" cellpadding="0" border="0">';
			str += '<tr>';
			str += '<td class="calnavleft_add" onclick="change_month(-1, \'' + this.id + '\')">&lt;&lt;<\/td>';
			str += '<td colspan="5" class="calheading_add">' + months[this.month] + ' ' + this.year + '<\/td>';
			str += '<td class="calnavright_add" onclick="change_month(1, \'' + this.id + '\')">&gt;&gt;<\/td>';
			str += '<\/tr>';

			//	Day Names

			str += '<tr>';

			for (i = 0; i < 7; i++)
			{
				str += '<td class="caldayheading_add">' + days[i] + '<\/td>';
			}

			str += '<\/tr>';

			//	Day Cells

			str += '<tr>';

			selDate = (last_date != '') ? last_date : this.date;

			for (j = 0; j < 42; j++)
			{
				var displayNum = (j - this.firstDay + 1);

				if (j < this.firstDay) // leading empty cells
				{
					str += '<td class="calblanktop_add">&nbsp;<\/td>';
				}
				else if (displayNum == selDate && this.highlight == true) // Selected date
				{
					str += '<td id="' + this.id +'selected" class="caldayselected" onclick="set_date_add(this,\'' + this.id + '\')">' + displayNum + '<\/td>';
				}
				else if (displayNum > this.total_days())
				{
					str += '<td class="calblankbot_add">&nbsp;<\/td>'; // trailing empty cells
				}
				else  // Unselected days
				{
					str += '<td id="" class="caldaycells_add" onclick="set_date_add(this,\'' + this.id + '\'); return false;"  onmouseOver="javascript:cell_highlight_add(this,\'' + displayNum + '\',\'' + this.id + '\');" onmouseOut="javascript:cell_reset_add(this,\'' + displayNum + '\',\'' + this.id + '\');" >' + displayNum + '<\/td>';
				}

				if (j % 7 == 6)
				{
					if (displayNum >= this.total_days()) break;
					str += '<\/tr><tr>';
				}
			}

			str += '<\/tr>';
			str += '<\/table>';
			str += '<\/div>';

			return str;
		}
		/* END */

		//	Total number of days in a month

		function total_days()
		{
			switch(this.month)
			{
				case 1: // Check for leap year
					if ((  this.date_obj.getFullYear() % 4 == 0
						&& this.date_obj.getFullYear() % 100 != 0)
						|| this.date_obj.getFullYear() % 400 == 0)
						return 29;
					else
						return 28;
				case 3:
					return 30;
				case 5:
					return 30;
				case 8:
					return 30;
				case 10:
					return 30
				default:
					return 31;
			}
		}
		/* END */


		//	Highlight Cell on Mouseover

		function cell_highlight(td, num, cal)
		{
			cal = eval(cal);

			if (last_click[cal.id]  != num)
			{
				td.className = "caldaycellhover";
			}
		}
		function cell_highlight_add(td, num, cal)
		{
			cal = eval(cal);

			if (last_click[cal.id]  != num)
			{
				td.className = "caldaycellhover_add";
			}
		}

		//	Reset Cell on MouseOut

		function cell_reset(td, num, cal)
		{
			cal = eval(cal);

			if (last_click[cal.id] == num)
			{
				td.className = "caldayselected";
			}
			else
			{
				td.className = "caldaycells";
			}
		}
		function cell_reset_add(td, num, cal)
		{
			cal = eval(cal);

			if (last_click[cal.id] == num)
			{
				td.className = "caldayselected_add";
			}
			else
			{
				td.className = "caldaycells_add";
			}
		}

		//	Clear Field

		function clear_field(id)
		{
			eval("document.getElementById('entryform')." + id + ".value = ''");

			document.getElementById(id + "selected").className = "caldaycells";
			document.getElementById(id + "selected").id = "";

			cal = eval(id);
			cal.selected_date = '';
		}


		//	Set date to now

		function set_to_now(id, now, raw)
		{
			eval("document.getElementById('entryform')." + id + ".value = now");

			if (document.getElementById(id + "selected"))
			{
				document.getElementById(id + "selected").className = "caldaycells";
				document.getElementById(id + "selected").id = "";
			}

			document.getElementById('cal' + id).innerHTML = '<div id="tempcal'+id+'">&nbsp;<'+'/div>';

			var nowDate = new Date();
			nowDate.setTime = raw;

			current_month	= nowDate.getMonth();
			current_year	= nowDate.getFullYear();
			current_date	= nowDate.getDate();

			oldcal = eval(id);
			oldcal.selected_date = current_year + '' + current_month + '' + current_date;

			oldcal.date_obj.setMonth(current_month);
			oldcal.date_obj.setYear(current_year);

			cal = new calendar(id, nowDate, true);
			cal.selected_date = current_year + '' + current_month + '' + current_date;

			last_date = cal.date;

			document.getElementById('tempcal'+id).innerHTML = cal.write();
		}


		//	Set date to what is in the field
		var lastDates = new Array();

		function update_calendar(id, dateValue)
		{
			cal = eval(id);

			if (lastDates[id] == dateValue) return;

			lastDates[id] = dateValue;

			var fieldString = dateValue.replace(/\s+/g, ' ');

			while (fieldString.substring(0,1) == ' ')
			{
				fieldString = fieldString.substring(1, fieldString.length);
			}

			var dateString = fieldString.split(' ');
			var dateParts = dateString[0].split('-')

			if (dateParts.length < 3) return;
			var newYear  = dateParts[0];
			var newMonth = dateParts[1];
			var newDay   = dateParts[2];

			if (isNaN(newDay)  || newDay < 1 || (newDay.length != 1 && newDay.length != 2)) return;
			if (isNaN(newYear) || newYear < 1 || newYear.length != 4) return;
			if (isNaN(newMonth) || newMonth < 1 || (newMonth.length != 1 && newMonth.length != 2)) return;

			if (newMonth > 12) newMonth = 12;

			if (newDay > 28)
			{
				switch(newMonth - 1)
				{
					case 1: // Check for leap year
						if ((newYear % 4 == 0 && newYear % 100 != 0) || newYear % 400 == 0)
						{
							if (newDay > 29) newDay = 29;
						}
						else
						{
							if (newDay > 28) newDay = 28;
						}
					case 3:
						if (newDay > 30) newDay = 30;
					case 5:
						if (newDay > 30) newDay = 30;
					case 8:
						if (newDay > 30) newDay = 30;
					case 10:
						if (newDay > 30) newDay = 30;
					default:
						if (newDay > 31) newDay = 31;
				}
			}

			if (document.getElementById(id + "selected"))
			{
				document.getElementById(id + "selected").className = "caldaycells";
				document.getElementById(id + "selected").id = "";
			}

			document.getElementById('cal' + id).innerHTML = '<div id="tempcal'+id+'">&nbsp;<'+'/div>';

			var nowDate = new Date();
			nowDate.setDate(newDay);
			nowDate.setMonth(newMonth - 1);
			nowDate.setYear(newYear);
			nowDate.setHours(12);

			cal.date_obj.setMonth(newMonth - 1);
			cal.date_obj.setYear(newYear);

			current_month	= nowDate.getMonth();
			current_year	= nowDate.getFullYear();
			last_date		= newDay;

			cal = new calendar(id, nowDate, true);
			document.getElementById('tempcal'+id).innerHTML = cal.write();
		}


		//	Set the date

		function set_date(td, cal)
		{
			cal = eval(cal);

			// If the user is clicking a cell that is already
			// selected we'll de-select it and clear the form field

			if (last_click[cal.id] == td.firstChild.nodeValue)
			{
				td.className = "caldaycells";
				last_click[cal.id] = '';
				remove_date(cal);
				cal.selected_date =  '';
				return;
			}

			// Onward!

			if (document.getElementById(cal.id + "selected"))
			{
				document.getElementById(cal.id + "selected").className = "caldaycells";
				document.getElementById(cal.id + "selected").id = "";
			}

			td.className = "caldayselected";
			td.id = cal.id + "selected";

			cal.selected_date = cal.date_obj.getFullYear() + '' + cal.date_obj.getMonth() + '' + cal.date;
			cal.date_obj.setDate(td.firstChild.nodeValue);
			cal = new calendar(cal.id, cal.date_obj, true);
			cal.selected_date = cal.date_obj.getFullYear() + '' + cal.date_obj.getMonth() + '' + cal.date;

			last_date = cal.date;

			//cal.date

			last_click[cal.id] = cal.date;

			// Insert the date into the form

			insert_date(cal);
		}
		function set_date_add(td, cal)
		{
			cal = eval(cal);

			// If the user is clicking a cell that is already
			// selected we'll de-select it and clear the form field

			if (last_click[cal.id] == td.firstChild.nodeValue)
			{
				td.className = "caldaycells_add";
				last_click[cal.id] = '';
				remove_date(cal);
				cal.selected_date =  '';
				return;
			}

			// Onward!

			if (document.getElementById(cal.id + "selected"))
			{
				document.getElementById(cal.id + "selected").className = "caldaycells_add";
				document.getElementById(cal.id + "selected").id = "";
			}

			td.className = "caldayselected_add";
			td.id = cal.id + "selected";

			cal.selected_date = cal.date_obj.getFullYear() + '' + cal.date_obj.getMonth() + '' + cal.date;
			cal.date_obj.setDate(td.firstChild.nodeValue);
			cal = new calendar(cal.id, cal.date_obj, true);
			cal.selected_date = cal.date_obj.getFullYear() + '' + cal.date_obj.getMonth() + '' + cal.date;

			last_date = cal.date;

			//cal.date

			last_click[cal.id] = cal.date;

			// Insert the date into the form

			insert_date(cal);
		}


		//	Insert the date into the form field

		function insert_date(cal)
		{
			cal = eval(cal);

			fval = eval("document.getElementById('entryform')." + cal.id);

			if (fval.value == '')
			{
				fval.value = cal.date_str('y');
			}
			else
			{
				time = fval.value.substring(10);

				new_date = cal.date_str('n') + time;

				fval.value = new_date;
			}
		}

		//	Remove the date from the form field

		function remove_date(cal)
		{
			cal = eval(cal);

			fval = eval("document.getElementById('entryform')." + cal.id);
			fval.value = '';
		}

		//	Change to a new month

		function change_month(mo, cal)
		{
			cal = eval(cal);

			if (current_month != '')
			{
				cal.date_obj.setMonth(current_month);
				cal.date_obj.setYear(current_year);

				current_month	= '';
				current_year	= '';
			}

			var newMonth = cal.date_obj.getMonth() + mo;
			var newDate  = cal.date_obj.getDate();

			if (newMonth == 12)
			{
				cal.date_obj.setYear(cal.date_obj.getFullYear() + 1)
				newMonth = 0;
			}
			else if (newMonth == -1)
			{
				cal.date_obj.setYear(cal.date_obj.getFullYear() - 1)
				newMonth = 11;
			}

			if (newDate > 28)
			{
				var newYear = cal.date_obj.getFullYear();

				switch(newMonth)
				{
					case 1: // Check for leap year
						if ((newYear % 4 == 0 && newYear % 100 != 0) || newYear % 400 == 0)
						{
							if (newDate > 29) newDate = 29;
						}
						else
						{
							if (newDate > 28) newDate = 28;
						}
					case 3:
						if (newDate > 30) newDate = 30;
					case 5:
						if (newDate > 30) newDate = 30;
					case 8:
						if (newDate > 30) newDate = 30;
					case 10:
						if (newDate > 30) newDate = 30;
					default:
						if (newDate > 31) newDate = 31;
				}
			}

			cal.date_obj.setDate(newDate);
			cal.date_obj.setMonth(newMonth);
			new_mdy	= cal.date_obj.getFullYear() + '' + cal.date_obj.getMonth() + '' + cal.date;

			highlight = (cal.selected_date == new_mdy) ? true : false;

			// Changed the highlight to false until we can determine a way for
			// the month to keep the old date value when we switch the newDate value
			// because of more days in the prior month than the month being switched
			// to:  Jan 31st => March 3rd (3 days past end of Febrary)

			cal = new calendar(cal.id, cal.date_obj, highlight);

			document.getElementById('cal' + cal.id).innerHTML = cal.write();
		}


		//	Finalize the date string

		function date_str(time)
		{
			var month = this.month + 1;
			if (month < 10)
				month = '0' + month;

			var day		= (this.date  < 10) 	?  '0' + this.date		: this.date;
			var minutes	= (this.minutes  < 10)	?  '0' + this.minutes	: this.minutes;

			if (format == 'us')
			{
				var hours	= (this.hours > 12) ? this.hours - 12 : this.hours;
				var ampm	= (this.hours > 11) ? 'PM' : 'AM'
			}
			else
			{
				var hours	= this.hours;
				var ampm	= '';
			}

			if (time == 'y')
			{
				return this.year + '-' + month + '-' + day + '  ' + hours + ':' + minutes + ' ' + ampm;
			}
			else
			{
				return this.year + '-' + month + '-' + day;
			}
		}

/************* New code 19.04.2009 ******************************/
		function date_format(format, year, month, day) {
			return format.replace('[d]', day)
						 .replace('[D]', day < 10 ? "0" + day : day)
						 .replace('[m]', month)
						 .replace('[M]', month< 10 ? "0" + month : month)
						 .replace('[y]', year);
		}

		/**
		 * Calendar with links
		 *
		 * @param string id Id of HTML element with calendar
         * @param date d Calendar date
         * @param string format URL like http://www.google.com/search?q={d}.{m}.{y}
         */
		function link_calendar(id, d, format) {
			var highlight = false;
			this.format     = format;
			this.id			= id;
			this.highlight	= highlight;
			this.date_obj	= d;
			this.write      = write_link;
			this.total_days	= total_days;
			this.month		= d.getMonth();
			this.date		= d.getDate();
			this.day		= d.getDay();
			this.year		= d.getFullYear();
			this.hours		= d.getHours();
			this.minutes	= d.getMinutes();
			this.seconds	= d.getSeconds();
			this.date_str	= date_str;

			if (highlight == false)
			{
				this.selected_date = '';
			}
			else
			{
				this.selected_date = this.year + '' + this.month + '' + this.date;
			}


			//	Set the "selected date"

			// As we toggle from month to month we need a way
			// to recall which date was originally highlighted
			// so when we return to that month the state will be
			// retained.  Well set a global variable containing
			// a string representing the year/month/day

			//get the first day of the month's day
			d.setDate(1);

			this.firstDay = (d.getDay()+6)%7;

			//then reset the date object to the correct date
			d.setDate(this.date);
		}

		function write_link() {
			var str = '';
			//	Calendar Heading

			str += '<div id="cal' + this.id + '">';
			str += '<table class="calendar" cellspacing="1" cellpadding="0" border="0" style="margin: 2px 3px 2px 3px;">';
			str += '<tr>';
			str += '<td class="calnavleft" onclick="change_month_link(-1, \'' + this.id + '\')">&nbsp<\/td>';
			str += '<td colspan="5" class="calheading">' + months[this.month] + ' ' + this.year + '<\/td>';
			str += '<td class="calnavright" onclick="change_month_link(1, \'' + this.id + '\')">&nbsp<\/td>';
			str += '<\/tr>';

			//	Day Names

			str += '<tr>';

			for (i = 0; i < 7; i++)
			{
				str += '<td class="caldayheading">' + days[i] + '<\/td>';
			}

			str += '<\/tr>';

			//	Day Cells

			str += '<tr>';

			selDate = (last_date != '') ? last_date : this.date;

			for (j = 0; j < 42; j++)
			{
				var displayNum = (j - this.firstDay + 1);
				var displayNum_link	= (displayNum>10?'':'0')+displayNum;
				var href = date_format(this.format, this.year, this.month+1, displayNum_link);


				if (j < this.firstDay) // leading empty cells
				{
					str += '<td class="calblanktop">_<\/td>';
				}
				else if (displayNum == selDate && this.highlight == true) // Selected date
				{
					str += '<td id="' + this.id +'selected" class="caldayselected" onclick="location.href=\'' + href +'\'">' + displayNum + '<\/td>';
				}
				else if (displayNum > this.total_days())
				{
					str += '<td class="calblankbot">_<\/td>'; // trailing empty cells
				}
				else  // Unselected days
				{
					str += '<td id="" class="caldaycells" onclick="location.href=\'' + href +'\'" onmouseOver="javascript:cell_highlight(this,\'' + displayNum + '\',\'' + this.id + '\');" onmouseOut="javascript:cell_reset(this,\'' + displayNum + '\',\'' + this.id + '\');">' + displayNum + '<\/td>';
				}



				if (j % 7 == 6)
				{
					if (displayNum >= this.total_days()) break;
					str += '<\/tr><tr>';
				}

			}

			str += '<\/tr>';
			str += '<\/table>';
			str += '<\/div>';

			return str;
		}

		function change_month_link(mo, cal)
		{
			cal = eval(cal);

			if (current_month != '')
			{
				cal.date_obj.setMonth(current_month);
				cal.date_obj.setYear(current_year);

				current_month	= '';
				current_year	= '';
			}

			var newMonth = cal.date_obj.getMonth() + mo;
			var newDate  = cal.date_obj.getDate();

			if (newMonth == 12)
			{
				cal.date_obj.setYear(cal.date_obj.getFullYear() + 1)
				newMonth = 0;
			}
			else if (newMonth == -1)
			{
				cal.date_obj.setYear(cal.date_obj.getFullYear() - 1)
				newMonth = 11;
			}

			if (newDate > 28)
			{
				var newYear = cal.date_obj.getFullYear();

				switch(newMonth)
				{
					case 1: // Check for leap year
						if ((newYear % 4 == 0 && newYear % 100 != 0) || newYear % 400 == 0)
						{
							if (newDate > 29) newDate = 29;
						}
						else
						{
							if (newDate > 28) newDate = 28;
						}
					case 3:
						if (newDate > 30) newDate = 30;
					case 5:
						if (newDate > 30) newDate = 30;
					case 8:
						if (newDate > 30) newDate = 30;
					case 10:
						if (newDate > 30) newDate = 30;
					default:
						if (newDate > 31) newDate = 31;
				}
			}

			cal.date_obj.setDate(newDate);
			cal.date_obj.setMonth(newMonth);
			new_mdy	= cal.date_obj.getFullYear() + '' + cal.date_obj.getMonth() + '' + cal.date;

			highlight = (cal.selected_date == new_mdy) ? true : false;

			// Changed the highlight to false until we can determine a way for
			// the month to keep the old date value when we switch the newDate value
			// because of more days in the prior month than the month being switched
			// to:  Jan 31st => March 3rd (3 days past end of Febrary)

			cal = new link_calendar(cal.id, cal.date_obj, cal.format);

			document.getElementById('cal' + cal.id).innerHTML = cal.write();
		}

		/**
		 * Calendar with months
		 *
		 * @param string id Id of HTML element with calendar
         * @param date d Calendar date
         * @param bool highlight Highlight current month
         */
		function month_calendar(id, d, highlight)
		{
			this.id			= id;
			this.highlight	= highlight;
			this.date_obj	= d;
			this.write		= write_month;
			this.total_days	= total_days;
			this.month		= d.getMonth();
			this.date		= d.getDate();
			this.day		= d.getDay();
			this.year		= d.getFullYear();
			this.hours		= d.getHours();
			this.minutes	= d.getMinutes();
			this.seconds	= d.getSeconds();
			this.date_str	= date_month;

			if (highlight == false)
			{
				this.selected_date = '';
			}
			else
			{
				this.selected_date = this.year + '' + this.month + '' + this.date;
			}


			//	Set the "selected date"

			// As we toggle from month to month we need a way
			// to recall which date was originally highlighted
			// so when we return to that month the state will be
			// retained.  Well set a global variable containing
			// a string representing the year/month/day

			//get the first day of the month's day
			d.setDate(1);

			this.firstDay = (d.getDay()+6)%7;

			//then reset the date object to the correct date
			d.setDate(this.date);
		}

		function write_month()
		{
			var str = '';

			//	Calendar Heading

			str += '<div id="cal' + this.id + '">';
			str += '<table class="calendar" cellspacing="0" cellpadding="0" border="0" style="margin-left: 20px;">';
			str += '<tr>';
			str += '<td class="calnavleft" onclick="change_year(-1, \'' + this.id + '\')">&lt;&lt;<\/td>';
			str += '<td class="calheading" colspan="2">' + this.year + '<\/td>';
			str += '<td class="calnavright" onclick="change_year(1, \'' + this.id + '\')">&gt;&gt;<\/td>';
			str += '<\/tr>';

			str += '<tr>';
			for (i = 0; i < 12; i++)
			{
				if (i % 4 == 0) str += '<tr>';
				str += '<td class="caldaycells" onclick="set_date_year(this,\'' + this.id + '\','+ i +');" onmouseOver="javascript:cell_highlight(this,\'' + i + '\',\'' + this.id + '\');" onmouseOut="javascript:cell_reset(this,\'' + i + '\',\'' + this.id + '\');">' + months[i] + '</td>';
				if ((i + 1) % 4 == 0) str += '</tr>';
			}


			str += '<\/tr>';
			str += '<\/table>';
			str += '<\/div>';

			return str;
		}

		function change_year(ye, cal)
		{
			cal = eval(cal);

			if (current_year != '')
			{
				cal.date_obj.setYear(current_year);
				current_year	= '';
			}

			cal.date_obj.setYear(cal.date_obj.getFullYear() + ye);
			var highlight = true;
			cal = new month_calendar(cal.id, cal.date_obj, highlight)
			document.getElementById('cal' + cal.id).innerHTML = cal.write();
		}

		function set_date_year(td, cal, month) {
			cal = eval(cal);

			// If the user is clicking a cell that is already
			// selected we'll de-select it and clear the form field

			if (last_click[cal.id] == td.firstChild.nodeValue)
			{
				td.className = "caldaycells";
				last_click[cal.id] = '';
				remove_date(cal);
				cal.selected_date =  '';
				return;
			}

			// Onward!

			if (document.getElementById(cal.id + "selected"))
			{
				document.getElementById(cal.id + "selected").className = "caldaycells";
				document.getElementById(cal.id + "selected").id = "";
			}

			td.className = "caldayselected";
			td.id = cal.id + "selected";

			cal.selected_date = cal.date_obj.getFullYear() + '' + cal.date_obj.getMonth() + '' + cal.date;
			cal.date_obj.setMonth(month);
			cal = new month_calendar(cal.id, cal.date_obj, true);
			cal.selected_date = cal.date_obj.getFullYear() + '' + cal.date_obj.getMonth() + '' + cal.date;

			last_date = cal.date;

			//cal.date

			last_click[cal.id] = cal.date;

			// Insert the date into the form

			insert_month(cal);
		}

		function update_month_calendar(id, dateValue)
		{
			cal = eval(id);

			if (lastDates[id] == dateValue) return;

			lastDates[id] = dateValue;

			var fieldString = dateValue.replace(/\s+/g, ' ');

			while (fieldString.substring(0,1) == ' ')
			{
				fieldString = fieldString.substring(1, fieldString.length);
			}

			var dateString = fieldString.split(' ');
			var dateParts = dateString[0].split('-')

			if (dateParts.length < 3) return;
			var newYear  = dateParts[0];
			var newMonth = dateParts[1];
			var newDay   = dateParts[2];

			if (isNaN(newDay)  || newDay < 1 || (newDay.length != 1 && newDay.length != 2)) return;
			if (isNaN(newYear) || newYear < 1 || newYear.length != 4) return;
			if (isNaN(newMonth) || newMonth < 1 || (newMonth.length != 1 && newMonth.length != 2)) return;

			if (newMonth > 12) newMonth = 12;

			if (newDay > 28)
			{
				switch(newMonth - 1)
				{
					case 1: // Check for leap year
						if ((newYear % 4 == 0 && newYear % 100 != 0) || newYear % 400 == 0)
						{
							if (newDay > 29) newDay = 29;
						}
						else
						{
							if (newDay > 28) newDay = 28;
						}
					case 3:
						if (newDay > 30) newDay = 30;
					case 5:
						if (newDay > 30) newDay = 30;
					case 8:
						if (newDay > 30) newDay = 30;
					case 10:
						if (newDay > 30) newDay = 30;
					default:
						if (newDay > 31) newDay = 31;
				}
			}

			if (document.getElementById(id + "selected"))
			{
				document.getElementById(id + "selected").className = "caldaycells";
				document.getElementById(id + "selected").id = "";
			}

			document.getElementById('cal' + id).innerHTML = '<div id="tempcal'+id+'">&nbsp;<'+'/div>';

			var nowDate = new Date();
			nowDate.setDate(newDay);
			nowDate.setMonth(newMonth - 1);
			nowDate.setYear(newYear);
			nowDate.setHours(12);

			cal.date_obj.setMonth(newMonth - 1);
			cal.date_obj.setYear(newYear);

			current_month	= nowDate.getMonth();
			current_year	= nowDate.getFullYear();
			last_date		= newDay;

			cal = new month_calendar(id, nowDate, true);
			document.getElementById('tempcal'+id).innerHTML = cal.write();
		}

		function insert_month(cal)
		{
			cal = eval(cal);

			fval = eval("document.getElementById('entryform')." + cal.id);

			if (fval.value == '')
			{
				fval.value = cal.date_str('y');
			}
			else
			{
				time = fval.value.substring(10);

				new_date = cal.date_str('n');

				fval.value = new_date;
			}
		}

		function date_month(time)
		{
			var month = this.month + 1;
			if (month < 10)
				month = '0' + month;

			var day		= (this.date  < 10) 	?  '0' + this.date		: this.date;
			var minutes	= (this.minutes  < 10)	?  '0' + this.minutes	: this.minutes;

			if (format == 'us')
			{
				var hours	= (this.hours > 12) ? this.hours - 12 : this.hours;
				var ampm	= (this.hours > 11) ? 'PM' : 'AM'
			}
			else
			{
				var hours	= this.hours;
				var ampm	= '';
			}

			if (time == 'y')
			{
				return this.year + '-' + month;
			}
			else
			{
				return this.year + '-' + month;
			}
		}

		/**
		 * Calendar with months links
		 *
		 * @param string id Id of HTML element with calendar
         * @param date d Calendar date
         * @param bool highlight Highlight current month
         */
		function month_link_calendar(id, d, format)
		{
			var highlight = false;
			this.id			= id;
			this.format     = format;
			this.highlight	= highlight;
			this.date_obj	= d;
			this.write		= write_link_month;
			this.total_days	= total_days;
			this.month		= d.getMonth();
			this.date		= d.getDate();
			this.day		= d.getDay();
			this.year		= d.getFullYear();
			this.hours		= d.getHours();
			this.minutes	= d.getMinutes();
			this.seconds	= d.getSeconds();
			this.date_str	= date_month;

			if (highlight == false)
			{
				this.selected_date = '';
			}
			else
			{
				this.selected_date = this.year + '' + this.month + '' + this.date;
			}


			//	Set the "selected date"

			// As we toggle from month to month we need a way
			// to recall which date was originally highlighted
			// so when we return to that month the state will be
			// retained.  Well set a global variable containing
			// a string representing the year/month/day

			//get the first day of the month's day
			d.setDate(1);

			this.firstDay = (d.getDay()+6)%7;

			//then reset the date object to the correct date
			d.setDate(this.date);
		}

		function write_link_month()
		{
			var str = '';

			//	Calendar Heading

			str += '<div id="cal' + this.id + '">';
			str += '<table class="calendar" cellspacing="0" cellpadding="0" border="0" style="margin-left: 20px; width: 150px;">';
			str += '<tr>';
			str += '<td class="calnavleft" onclick="change_link_year(-1, \'' + this.id + '\')">&lt;&lt;<\/td>';
			str += '<td class="calheading" colspan="2">' + this.year + '<\/td>';
			str += '<td class="calnavright" onclick="change_link_year(1, \'' + this.id + '\')">&gt;&gt;<\/td>';
			str += '<\/tr>';

			str += '<tr>';
			for (i = 0; i < 12; i++)
			{
				var href = date_format(this.format, this.year, i+1);
				if (i % 4 == 0) str += '<tr>';
				str += '<td class="caldaycells" onclick="location.href=\'' + href + '\'" onmouseOver="javascript:cell_highlight(this,\'' + i + '\',\'' + this.id + '\');" onmouseOut="javascript:cell_reset(this,\'' + i + '\',\'' + this.id + '\');">' + months_small[i] + '</td>';
				if ((i + 1) % 4 == 0) str += '</tr>';
			}


			str += '<\/tr>';
			str += '<\/table>';
			str += '<\/div>';

			return str;
		}

		function change_link_year(ye, cal)
		{
			cal = eval(cal);

			if (current_year != '')
			{
				cal.date_obj.setYear(current_year);
				current_year	= '';
			}

			cal.date_obj.setYear(cal.date_obj.getFullYear() + ye);
			var highlight = true;
			cal = new month_link_calendar(cal.id, cal.date_obj, cal.format)
			document.getElementById('cal' + cal.id).innerHTML = cal.write();
		}

		/**
		 * Calendar with links (week to monday)
		 *
		 * @param string id Id of HTML element with calendar
         * @param date d Calendar date
         * @param string format URL like http://www.google.com/search?q={d}.{m}.{y}
         */
		function link_calendar_first(id, d, format) {
			var highlight = false;
			this.format     = format;
			this.id			= id;
			this.highlight	= highlight;
			this.date_obj	= d;
			this.write      = write_link_fd;
			this.total_days	= total_days;
			this.month		= d.getMonth();
			this.date		= d.getDate();
			this.day		= d.getDay();
			this.year		= d.getFullYear();
			this.hours		= d.getHours();
			this.minutes	= d.getMinutes();
			this.seconds	= d.getSeconds();
			this.date_str	= date_str;

			if (highlight == false)
			{
				this.selected_date = '';
			}
			else
			{
				this.selected_date = this.year + '' + this.month + '' + this.date;
			}


			//	Set the "selected date"

			// As we toggle from month to month we need a way
			// to recall which date was originally highlighted
			// so when we return to that month the state will be
			// retained.  Well set a global variable containing
			// a string representing the year/month/day

			//get the first day of the month's day
			d.setDate(1);

			this.firstDay = (d.getDay()+6)%7;

			//then reset the date object to the correct date
			d.setDate(this.date);
		}

		function write_link_fd() {
			var str = '';
			//	Calendar Heading

			str += '<div id="cal' + this.id + '">';
			str += '<table class="calendar" cellspacing="0" cellpadding="0" border="0" style="margin-left: 20px;">';
			str += '<tr>';
			str += '<td class="calnavleft" onclick="change_month_first_link(-1, \'' + this.id + '\')">&lt;&lt;<\/td>';
			str += '<td colspan="5" class="calheading">' + months[this.month] + ' ' + this.year + '<\/td>';
			str += '<td class="calnavright" onclick="change_month_first_link(1, \'' + this.id + '\')">&gt;&gt;<\/td>';
			str += '<\/tr>';

			//	Day Names

			str += '<tr>';

			for (i = 0; i < 7; i++)
			{
				str += '<td class="caldayheading">' + days[i] + '<\/td>';
			}

			str += '<\/tr>';

			//	Day Cells

			str += '<tr>';

			selDate = (last_date != '') ? last_date : this.date;
			if (this.firstDay == 0) {
				var href = date_format(this.format, this.year, this.month+1, 1);
			} else {
				var inFeb = (((this.year % 4 == 0) && (this.year % 100 != 0)) || (this.year % 400 == 0)) ? 29 : 28;
				var monthCountDay = [31,inFeb,31,30,31,30,31,31,30,31,30,31];
				if (this.month == 0) {
					var m = 11;
					var y = this.year - 1;
				} else {
					var m = this.month - 1;
					y = this.year;
				}

				var d = monthCountDay[m];
				for (i = 0; i < 7; i++) {
					d--;
					dt = new Date();
					dt.setDate(d);
					dt.setMonth(m);
					dt.setYear(y);
					if (dt.getDay() == 1) {
						break;
					}
				}
				var href = date_format(this.format, y, m+1, d);
			}

			for (j = 0; j < 42; j++)
			{
				var displayNum = (j - this.firstDay + 1);

				if (j < this.firstDay) // leading empty cells
				{
					str += '<td class="calblanktop">&nbsp;<\/td>';
				}
				else if (displayNum == selDate && this.highlight == true) // Selected date
				{
					str += '<td id="' + this.id +'selected" class="caldayselected" onclick="location.href=\'' + href +'\'">' + displayNum + '<\/td>';
				}
				else if (displayNum > this.total_days())
				{
					str += '<td class="calblankbot">&nbsp;<\/td>'; // trailing empty cells
				}
				else  // Unselected days
				{
					str += '<td id="" class="caldaycells" onclick="location.href=\'' + href +'\'" onmouseOver="javascript:cell_highlight(this,\'' + displayNum + '\',\'' + this.id + '\');" onmouseOut="javascript:cell_reset(this,\'' + displayNum + '\',\'' + this.id + '\');">' + displayNum + '<\/td>';
				}

				if (j % 7 == 6)
				{
					if (displayNum >= this.total_days()) break;
					href = date_format(this.format, this.year, this.month+1, displayNum+1);
					str += '<\/tr><tr>';
				}

			}

			str += '<\/tr>';
			str += '<\/table>';
			str += '<\/div>';

			return str;
		}

		function change_month_first_link(mo, cal)
		{
			cal = eval(cal);

			if (current_month != '')
			{
				cal.date_obj.setMonth(current_month);
				cal.date_obj.setYear(current_year);

				current_month	= '';
				current_year	= '';
			}

			var newMonth = cal.date_obj.getMonth() + mo;
			var newDate  = cal.date_obj.getDate();

			if (newMonth == 12)
			{
				cal.date_obj.setYear(cal.date_obj.getFullYear() + 1)
				newMonth = 0;
			}
			else if (newMonth == -1)
			{
				cal.date_obj.setYear(cal.date_obj.getFullYear() - 1)
				newMonth = 11;
			}

			if (newDate > 28)
			{
				var newYear = cal.date_obj.getFullYear();

				switch(newMonth)
				{
					case 1: // Check for leap year
						if ((newYear % 4 == 0 && newYear % 100 != 0) || newYear % 400 == 0)
						{
							if (newDate > 29) newDate = 29;
						}
						else
						{
							if (newDate > 28) newDate = 28;
						}
					case 3:
						if (newDate > 30) newDate = 30;
					case 5:
						if (newDate > 30) newDate = 30;
					case 8:
						if (newDate > 30) newDate = 30;
					case 10:
						if (newDate > 30) newDate = 30;
					default:
						if (newDate > 31) newDate = 31;
				}
			}

			cal.date_obj.setDate(newDate);
			cal.date_obj.setMonth(newMonth);
			new_mdy	= cal.date_obj.getFullYear() + '' + cal.date_obj.getMonth() + '' + cal.date;

			highlight = (cal.selected_date == new_mdy) ? true : false;

			// Changed the highlight to false until we can determine a way for
			// the month to keep the old date value when we switch the newDate value
			// because of more days in the prior month than the month being switched
			// to:  Jan 31st => March 3rd (3 days past end of Febrary)

			cal = new link_calendar_first(cal.id, cal.date_obj, cal.format);

			document.getElementById('cal' + cal.id).innerHTML = cal.write();
		}
