function AmphCalendar(strInstanceName) {
	this.strInstanceName = strInstanceName;
	this.arrDayNames = ['Zo','Ma','Di','Wo','Do','Vr','Za'];
this.arrMonthNames = ['','Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December'];
this.arrMonthData2012_2 = [29, 3];
this.arrMonthData2012_3 = [31, 4];
this.arrMonthData2012_4 = [30, 0];
this.arrMonthData2012_5 = [31, 2];
this.arrMonthData2012_6 = [30, 5];
this.arrMonthData2012_7 = [31, 0];
this.arrMonthData2012_8 = [31, 3];
this.arrMonthData2012_9 = [30, 6];
this.arrMonthData2012_10 = [31, 1];
this.arrMonthData2012_11 = [30, 4];
this.arrMonthData2012_12 = [31, 6];
this.arrMonthData2013_1 = [31, 2];
this.arrMonthData2013_2 = [28, 5];
this.arrMonthData2013_3 = [31, 5];
this.arrMonthData2013_4 = [30, 1];
this.arrMonthData2013_5 = [31, 3];
this.arrMonthData2013_6 = [30, 6];
this.arrMonthData2013_7 = [31, 1];
this.arrMonthData2013_8 = [31, 4];
this.arrMonthData2013_9 = [30, 0];
this.arrMonthData2013_10 = [31, 2];
this.arrMonthData2013_11 = [30, 5];
this.arrMonthData2013_12 = [31, 0];
this.arrMonthData2014_1 = [31, 3];
this.arrMonthData2014_2 = [28, 6];

this.intSelectedYear = 2012;
this.intSelectedMonth = 2;
this.intSelectedDay = 6;
this.intTodayYear = 2012;
this.intTodayMonth = 2;
this.intTodayDay = 6;
this.strPastDaysStyle = '';
this.strUnselectableDaysStyle = '';
this.strSelectableDaysStyle = '';
this.strDayNamesStyle = '';
this.strMonthSelectorStyle = '';
this.arrSelectableDays = '';
this.intDayOffset = 1;
this.strClickTemplate = '';
this.blnPastSelectable = false;
this.blnShowMonthSelector = true;
this.intGMTOffset = '1';
}

AmphCalendar.prototype.setDate = function(intYear, intMonth, intDay) {
	this.intSelectedYear = intYear;
	this.intSelectedMonth = intMonth;
	this.intSelectedDay = intDay;
}

AmphCalendar.prototype.changeMonth = function(strYearMonth) {
	objDiv = new DHTMLObject('dv' + this.strInstanceName);
	if (objDiv.blnInit) {
		intUsPos = strYearMonth.indexOf('_');
		intYear = parseInt(strYearMonth.substring(0,intUsPos));
		intMonth = parseInt(strYearMonth.substring(intUsPos + 1));
		this.setDate(intYear, intMonth, 1);
		objDiv.setInnerHTML(this.getHTML());
	}
	objDiv = '';
}

AmphCalendar.prototype.getHTML = function() {
	intIdToday = (10000 * this.intTodayYear) + (100 * this.intTodayMonth) + this.intTodayDay;
	intIdSelMonth = (10000 * this.intSelectedYear) + (100 * this.intSelectedMonth);
	intIdSelDate = (10000 * this.intSelectedYear) + (100 * this.intSelectedMonth) + this.intSelectedDay;
	strCalendar = '<form name="frmCalendar' + this.strInstanceName + '"><table cellspacing="0" cellpadding="3" border="0" class="caltable">';
	if (this.blnShowMonthSelector) {
		strCalendar += '<tr><td colspan="7"' + (this.strMonthSelectorStyle != ''?' class="' + this.strMonthSelectorStyle + '"':'') + '><select name="ddMonthYear" onchange="objCalendarInstance = eval(\'' + this.strInstanceName + '\'); objCalendarInstance.changeMonth(this.value);">';
		
		intCurMonth = this.intTodayMonth;
		intCurYear = this.intTodayYear;
		intSelMonthIndex = 0;
		for (i = 0; i < 12; i++) {
			if ((intCurMonth == this.intSelectedMonth) && (intCurYear == this.intSelectedYear)) intSelMonthIndex = i;
			strCalendar += '<option value="' + intCurYear + '_' + intCurMonth + '"' + ((intCurMonth == this.intSelectedMonth) && (intCurYear == this.intSelectedYear)?' selected':'') + '>' + this.arrMonthNames[intCurMonth] + ' ' + intCurYear + '\n';
			intCurMonth++;
			if (intCurMonth > 12) {
				intCurMonth = 1;
				intCurYear++;
			}
		}
		strCalendar += '</select></td></tr>\n';
	}
	strCalendar += '<tr>';
	for (i = 0; i < 7; i++) {
		intDay = i + this.intDayOffset;
		if (intDay > 6) intDay -= 7;
		if (intDay < 0) intDay += 7;
		strCalendar += '<td' + (this.strDayNamesStyle != ''?' class="' + this.strDayNamesStyle + '"':'') + '>' + this.arrDayNames[intDay] + '</td>';
	}
	strCalendar += '</tr>\n<tr>';
	arrMonthData = eval('this.arrMonthData' + this.intSelectedYear + '_' + this.intSelectedMonth);
	intEmptySpaces = arrMonthData[1] - this.intDayOffset;
	if (intEmptySpaces > 6) intEmptySpaces -= 7;
	if (intEmptySpaces < 0) intEmptySpaces += 7;
	for (i = 0; i < intEmptySpaces; i++) {
		strCalendar += '<td style="cursor: default;">&nbsp;</td>';
	}
	intCurCell = intEmptySpaces;
	blnUseSelectables = (typeof(this.arrSelectableDays) != 'string');
	for (i = 1; i <= arrMonthData[0]; i++) {
		blnSelectable = (!blnUseSelectables) || (blnUseSelectables && this.isSelectableDay(this.intSelectedYear, this.intSelectedMonth, i));
		blnToday = (intIdSelMonth + i == intIdToday);
		blnPast = (intIdSelMonth + i < intIdToday);
		blnSelectedDate = (intIdSelDate == (intIdSelMonth + i));
		if (blnPast && (!this.blnPastSelectable) && blnSelectable) blnSelectable = false;
		if (blnPast) {
			strClass = this.strPastDaysStyle;
		} else if (!blnSelectable) {
			strClass = this.strUnselectableDaysStyle;
		} else {
			strClass = this.strSelectableDaysStyle;
		}
		strClick = this.strClickTemplate;
		strClick = strClick.replace(/{year}/, this.intSelectedYear);
		strClick = strClick.replace(/{month}/, this.intSelectedMonth);
		strClick = strClick.replace(/{day}/, i);
		strClick = strClick.replace(/{ts}/, this.getEpochSeconds(this.intSelectedYear, this.intSelectedMonth, i));
		strHoverClass = strClass + 'Hover';
		if (blnToday) {
			strHoverClass += ' today';
			strClass += ' today';
		} else if (blnSelectedDate) {
			strHoverClass += ' selectedday';
			strClass += ' selectedday';
		}
		strCalendar += '<td' + (strClass != ''?' class="' + strClass + '"':'') + (blnSelectable && (strClass != '')?' onmouseover="this.className=\'' + strHoverClass + '\'" onmouseout="this.className=\'' + strClass + '\'"':'') + (blnSelectable?' onclick="' + strClick + '; return false;"':'') + '>' + (blnSelectable?'<a href="javascript:' + strClick + '">':'') + i + (blnSelectable?'</a>':'') + '</td>';
		intCurCell++;
		if ((intCurCell % 7) == 0) {
			strCalendar += '</tr>\n';
			if (i != arrMonthData[0]) strCalendar += '<tr>';
		}
	}
	if ((intCurCell % 7) != 0) {
		while ((intCurCell % 7) != 0) {
			strCalendar += '<td style="cursor: default;">&nbsp;</td>';
			intCurCell++;
		}
		strCalendar += '</tr>';
	}
	strCalendar += '</table></form>';
	// Firefox workaround
	//if (this.blnShowMonthSelector) strCalendar += '<script language="JavaScript">document.frmCalendar' + this.strInstanceName + '.ddMonthYear.selectedIndex = \'' + intSelMonthIndex + '\';</script>';
	return strCalendar;
}

AmphCalendar.prototype.getDIVHTML = function() {
	strReturn = '<div id="dv' + this.strInstanceName + '">';
	strReturn += this.getHTML();
	strReturn += '</div>';
	return strReturn;
}

AmphCalendar.prototype.setStyle = function(strItem, strClass) {
	switch (strItem) {
		case 'pastdays':
			this.strPastDaysStyle = strClass;
			break;
		case 'selectabledays':
			this.strSelectableDaysStyle = strClass;
			break;
		case 'unselectabledays':
			this.strUnselectableDaysStyle = strClass;
			break;
		case 'daynames':
			this.strDayNamesStyle = strClass;
			break;
		case 'monthselector':
			this.strMonthSelectorStyle = strClass;
			break;
	}
}
AmphCalendar.prototype.setSelectableDays = function(arrSelectableDays) {
	this.arrSelectableDays = arrSelectableDays;
}

AmphCalendar.prototype.isSelectableDay = function(intYear, intMonth, intDay) {
	if (typeof(this.arrSelectableDays) == 'string') return false;
	for (j = 0; j < this.arrSelectableDays.length; j++) {
		if ((this.arrSelectableDays[j][0] == intYear) && (this.arrSelectableDays[j][1] == intMonth) && (this.arrSelectableDays[j][intDay + 1]) && (this.arrSelectableDays[j][intDay + 1] == 1)) {
			return true;
		}
	}
	return false;
}

AmphCalendar.prototype.setClickTemplate = function(strTemplate) {
	this.strClickTemplate = strTemplate;
}

AmphCalendar.prototype.getEpochSeconds = function(intYear, intMonth, intDay) {
	intDays = 0;
	if (intYear > 1970) {
		for (k = 1970; k < intYear; k++) {
			if ((((k % 4) == 0) && ((k % 100) != 0)) || ((k % 400) == 0)) {
				intDays += 366;
			} else {
				intDays += 365;
			}
		}
	}
	arrMonthLengths = [31,28,31,30,31,30,31,31,30,31,30,31];
	if ((((intYear % 4) == 0) && ((intYear % 100) != 0)) || ((intYear % 400) == 0)) arrMonthLengths[1] = 29;
	if (intMonth >= 1) {
		for (k = 0; k < intMonth - 1; k++) {
			intDays += arrMonthLengths[k];
		}
	}
	intDays += intDay - 1;
	intSeconds = (intDays * 86400) - (this.intGMTOffset * 3600);
	return intSeconds;
}

AmphCalendar.prototype.setMonthSelectorVisibility = function(blnVisible) {
	this.blnShowMonthSelector = (blnVisible?true:false);
}

