	function createDate(dateParts) {

		var theDate = new Date(parseInt(dateParts[2],10), parseInt(dateParts[0],10), parseInt(dateParts[1],10) );

		return theDate;

	}

	function getYear(now) {

		//This function, and the reasoning behind it, was obtained at http://www.quirksmode.org/js/date.html.

		var x = now.getYear();
		var y = x % 100;
		y += (y < 38) ? 2000 : 1900;
		return y;

	}

	function getMonth(now) {

		var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

		return months[now.getMonth()];		

	}

	function getDaysRow() {

		var daysOfTheWeek = new Array('S','M','T', 'W', 'T', 'F', 'S');

		var html = '';

		html += '  <tr>\n';

		for (var i = 0; i < daysOfTheWeek.length; i++) {

			html += '    <th width="10" style="font-size: 11;">' + daysOfTheWeek[i] + '</th>\n';

		}

		html += '  </tr>\n';

		return html;

	}

	function getCalendarBody(now, dateParts, dtStartDate, dtEndDate) {

		//An array corresponding to the number of days in each month.  Note alteration on daysInMonth[1], February, if a leap year.

		var daysInMonth = new Array('31','28','31','30','31','30','31','31','30','31','30','31');

		if ( ( (getYear(now) % 4 == 0) && (getYear(now) % 100 != 0) ) || (getYear(now) % 400 == 0) ) {

			daysInMonth[1] = 29;
		}

		var calendarDays = new Array();  //Set blank array of possible date slots.

		var firstDay = new Date(getYear(now), now.getMonth(), 1);  //Create a date object corresponding to the first day of the month.

		var lastDay = new Date(getYear(now), now.getMonth(), daysInMonth[now.getMonth()]);  //Create a date object corresponding to the last day of the month (technically, the day before the first day of the next month).

		firstDay = firstDay.getDay();  //Should now equal the day of the week for use as an offset when populating the calendarDays array.

		lastDay = lastDay.getDate();  //Should now equal 28, 29, 30, or 31.

		//Get number of rows to be displayed.

		var weekRows = 6 - (Math.floor( ((42 - ((firstDay) + lastDay)) / 7) ) ); //Up to six weeks and 42 days, depending on the calendar.

		//Clear the calendarDays array.

		for (var i = 1; i <= 42; i++) {

			calendarDays[i] = '';

		}

		//Populate the calendarDays array, offsetting for the day of the week corresponding to the first day of the month.

		for (var i = 1; i <= lastDay; i++) {

			calendarDays[firstDay + i] = i;  //And here's the offset.

		}

		//Build the actual calendar output.

		var html = '';

		for (var i = 1; i <= weekRows; i++) {

			html += '  <tr>\n';

			for (var j = 1; j <= 7; j++) {

				if (calendarDays[((i - 1) * 7) + j] == '') {

					html += '    <td bgcolor="#FFFFFF">&nbsp;</td>\n';

				} else {

					dateParts[1] = calendarDays[((i - 1) * 7) + j];

					var dtCurrentDate = createDate(dateParts);

					if (dtCurrentDate >= dtStartDate && dtCurrentDate <= dtEndDate) {

						html += '    <td bgcolor="#FFCCCC" style="background-color: #FFCCCC; text-align: center; font-size: 11;">' + calendarDays[((i - 1) * 7) + j] + '</td>\n';

					} else {

						html += '    <td bgcolor="#FFFFFF" style="background-color: #FFFFFF; text-align: center; font-size: 11;">' + calendarDays[((i - 1) * 7) + j] + '</td>\n';

					}

				}

			}

			html += '  </tr>\n'

		}

		return html;

	}

	function showCalendar(simname, level, simnum, startDate, endDate) {  //Receive startDate and endDate as strings with format mm/dd/yyyy.

		//Create date objects corresponding to startDate and endDate.

		var startDateParts = startDate.split('/');

		for (var i = 0; i < startDateParts.length; i++) {

			startDateParts[i] = parseInt(startDateParts[i],10);

		}

		var endDateParts = endDate.split('/');

		for (var i = 0; i < endDateParts.length; i++) {

			endDateParts[i] = parseInt(endDateParts[i],10);

		}

		startDateParts[0] = startDateParts[0] - 1;

		var startMonth = startDateParts[0];

		endDateParts[0] = endDateParts[0] - 1;

		var endMonth = endDateParts[0];

		var dtStartDate = createDate(startDateParts);

		var dtEndDate = createDate(endDateParts);

		//Begin html output.

		var html = '';
		html += '<html>\n';
		html += '<head>\n';
		html += '<title>' + simname + '</title>\n';
		html += '<link rel="stylesheet" type="text/css" href="http://www.icons.umd.edu/redesign/icons.css">\n';
		html += '</head>\n';
		html += '<body>\n';
		html += '<p align="right" style="font-size: 10; text-align: right;"><a href="javascript:window.close();">Close Window</a></p>\n';
		html += '<h1 align="center" style="font-size: 14; text-align: center;">ICONS<br />' + simname + '</h1>\n';

		if (dtStartDate.getMonth() != dtEndDate.getMonth()) {  //This will do for now.  If we were including the year(s) in the date string, We'd send dtStartDate and dtEndDate to a separate function for tests and proper formatting.

			html += '<p align="center" style="font-size: 11; text-align: center;"><strong>' + level + '-level, #' + simnum + '<br />' + getMonth(dtStartDate) + ' ' + dtStartDate.getDate() + ' - ' + getMonth(dtEndDate) + ' ' + dtEndDate.getDate() + '</strong></p>\n';

		} else {

			html += '<p align="center" style="font-size: 11; text-align: center;"><strong>' + level + '-level, #' + simnum + '<br />' + getMonth(dtStartDate) + ' ' + dtStartDate.getDate() + ' - ' + dtEndDate.getDate() + '</strong></p>\n';

		}

		html += '<p align="center" style="font-size: 11; text-align: center;">Areas highlighted in pink indicate simulation days.</p>\n';

		//Loop through months to display.

		for (var i = startMonth; i <= endMonth; i++) {

			var dateParts = startDate.split('/');

			dateParts[0] = i;

			var now = new Date( parseInt(dateParts[2],10), parseInt(dateParts[0],10), 1 );  //Date specified by user.

			html += '<table align="center" cellspacing="0" cellpadding="3" border="0">\n';
			html += '<thead>\n';
			html += '  <tr>\n';
			html += '    <th  colspan="7" bgcolor="#C0C0C0" style="font-size: 12;">' + getMonth(now) + '&nbsp;' + getYear(now) + '</th>\n';
			html += '  </tr>\n';
			html += '</thead>\n';
			html += '<tbody>\n';
			html += getDaysRow();
			html += getCalendarBody(now, dateParts, dtStartDate, dtEndDate);
			html += '</tbody>\n';
			html += '</table>\n';
			html += '<br />\n';

		}

		html += '</body>\n';
		html += '</html>\n';

		var newWin = window.open('','','width=350,height=525,resizable,scrollbars,screenX=25,screenY=25,left=25,top=25');

		newWin.document.open();
		newWin.document.write(html);
		newWin.document.close();

	}
