/*
var d = new Date(2007, 12, 1);
d = new Date(d - 1000);
//console.log("Date:");
//console.log(d);
alert(d.getDate());

terv:
http://wiki.deepskeye.gotdns.org/index.php/Calendar.js

HTCalendar ojjektum:
HTCalendar(vElement, descriptor);
HTCalendar.getMonthLook(year, month); -> napok, hetek száma, napok a hét napjaihoz rendelve.
HTCalendar.getMonthNames()
HTCalendar.getFirstDayOfWeek()
HTCalendar.getDayNames()
HTCalendar.getPanelPosition(w, h)
HTCalendar.formatDate(date)
HTCalendar.parseDate(date)
HTCalendar.show();
HTCalendar.hide();
HTCalendar.triggerChange(from);
HTCalendar.getDate(date);
HTCalendar.desscriptor;

HTCalendarPanelView(helper)
HTCalendarPanelView.show();
HTCalendarPanelView.hide();
HTCalendarAnchorView.setDate(date);
HTCalendarAnchorView.getDate();


HTCalendarAnchorView(helper, calElement)
HTCalendarAnchorView.setDate(date);
HTCalendarAnchorView.getDate();


*/

function HTCalendar(vElement, descriptor) {
	if(typeof descriptor != 'object') descriptor = new Object();

	var _this = this;

	this.descriptor = (function() {
		var _valid = [
			[ 'type', 'string', "YMDhms" ],
			[ 'icon', 'string', jgtc.rootImgURL + "adm3cal-icon.png" ],
			[ 'clearButton', 'boolean', false ],
			[ 'closeButton', 'boolean', true ],
			[ 'viewPanel', 'function', HTCalendarPanelView ],
			[ 'viewAnchor', 'function', HTCalendarAnchorView ],
			[ 'onchange', 'function', nop ],
			[ 'onshow', 'function', nop ],
			[ 'onhide', 'function', nop ],
			[ 'validateDay', 'function', null ],
			[ 'pin', 'boolean', false ],
			[ 'panelClass', 'string', "adm_calendar" ],
			[ 'opacity', 'number', 0.92 ],
			[ 'fancy', 'boolean', true ],
			[ 'deleteValue', 'string', false ],
			[ 'deleteIcon', 'string', jgtc.rootImgURL + 'adm3br-delete.' + (is.ie6 ? 'gif' : 'png') ]
		];
		var d = {};

		for(var i = 0; i < _valid.length; i++) {
			var v = _valid[i];
			if(v[1] === true) {
				if(typeof descriptor[v[0]] == 'undefined') d[v[0]] = v[2];
				else d[v[0]] = descriptor[v[0]];
			} else if(typeof descriptor[v[0]] != v[1]) {
				d[v[0]] = v[2];
			} else {
				d[v[0]] = descriptor[v[0]];
			}
		}

		if(d['deleteValue'] !== false) {
			d['deleteValue'] = _this.parseDate(d['deleteValue']);
		}

		return d;
	})();

	console.dir(this.descriptor);

	var _showing = false;
	var date = null;
	var eAnchor = null;
	var viewPanel = null;
	var viewAnchor = null;

	vElement = typeof vElement == "string" ? document.getElementById(vElement) : vElement;

	function __getDate() {
		return date == null ? null : new Date(date);
	}

	function __setDate(_date) {
		date = _date == null ? null : new Date(_date);
		_this.update();
	}

	function __getCalendar() {
		return _this;
	}

	function __getParam(name) {
		return _this.descriptor[name];
	}

	function __setParam(name, value) {
		_this.descriptor[name] = value;
	}

	var anchorHelper = {
		triggerChange: function() {
			function _c() {
				if(_showing) viewPanel.update();
				_this.descriptor.onchange(_this, date);
			}

			var d1 = viewAnchor.getDate();

			if(d1 == null) {
				if(date != null) {
					date = null;
					_c();
				}
			} else if(date == null || d1.getTime() != date.getTime()) {
				date = new Date(d1);
				_c();
			}
		},

		getCalendar: __getCalendar,
		getParam: __getParam,
		setParam: __setParam,
		getDate: __getDate
	}

	var panelHelper = {
		triggerChange: function() {
			function _c() {
				viewAnchor.update();
				_this.descriptor.onchange(_this, date);
			}

			var d1 = viewPanel.getDate();

//			console.log("d1: %o, date %o", d1, date);

			if(d1 == null) {
				if(date != null) {
					date = null;
					_c();
				}
			} else if(date == null || d1.getTime() != date.getTime()) {
				date = new Date(d1);
				_c();
			}
		},

		getAnchorElement: function() {
			return eAnchor;
		},

		getPanelPosition: function(w, h) {
			function _bound(min, max, v) {
				return v < min ? min : (v > max ? max : v);
			}

			function _intersects(x0, y0, w0, h0) {
				return x + w > x0 && y + h > y0 && x < x0 + w0 && y < y0 + h0;
			}

			var b = viewAnchor.getAnchorPoint();
			var b1 = false;
			if(b) {
				var minx = 0;
				var miny = 0;
				with(document.documentElement) { // ff és ie
					minx += scrollLeft;
					miny += scrollTop;
				}
				with(document.body) { // webkit
					minx += scrollLeft;
					miny += scrollTop;
				}

				var maxx = document.documentElement.clientWidth - w + minx;
				var maxy = document.documentElement.clientHeight - h + miny;

				var x = _bound(minx, maxx, b.x);
				var y = _bound(miny, maxy, b.y);

				if('exclude' in b && _intersects(b.exclude.x, b.exclude.y, b.exclude.w, b.exclude.h)) {
					x = _bound(minx, maxx, b.exclude.x - w);
				}

				b1 = { 'x': x, 'y': y };
			}

			return b1;
		},

		getCalendar: __getCalendar,
		getParam: __getParam,
		setParam: __setParam,
		getDate: function() {
			return __getDate() || new Date();
		}
	}

	viewPanel = new this.descriptor.viewPanel(panelHelper);
	viewAnchor = new this.descriptor.viewAnchor(anchorHelper, vElement);

	date = viewAnchor.getDate();
	if(date != null) date = new Date(date);

	eAnchor = viewAnchor.getAnchorElement() || document.body;

//	console.log('--- date: %o %o', date, viewAnchor);

	this.getElement = function() {
		return vElement;
	}

	this.show = function() {
		if(!_showing) {
			anchorHelper.triggerChange();
			viewPanel.show();
			_showing = true;
			_this.descriptor.onshow(_this, date);
		}
	}

	this.hide = function() {
		if(_showing) {
			viewPanel.hide();
			_showing = false;
			_this.descriptor.onhide(_this, date);
		}
	}

	this.isShowing = function() {
		return _showing;
	}

	this.update = function() {
		viewAnchor.update();
		if(_showing) viewPanel.update();

		_this.descriptor.onchange(_this, date);
	}

	this.getDate = __getDate;

	this.setDate = __setDate;

	this.descriptor.type = (function() {
		var l = _this.descriptor.type.length;
		return {
			_type: _this.descriptor.type,
			_l: l,
			hasYear: l > 0,
			hasMonth: l > 1,
			hasDay: l > 2,
			hasHour: l > 3,
			hasMinute: l > 4,
			hasSecond: l > 5
		};
	})();

	viewPanel.init();
	viewAnchor.init();

	vElement.htcSetDate = __setDate;
	vElement.htcShow = this.show;
	vElement.htcHide = this.hide;
}

HTCalendar.prototype.getMonthNames = function(abbr) {
	if(abbr) {
		return [ 'Jan', 'Febr', 'Márc', 'Ápr', 'Máj', 'Jún', 'Júl', 'Aug', 'Szept', 'Okt', 'Nov', 'Dec' ];
	} else {
		return [ 'Január', 'Február', 'Március', 'Április', 'Május', 'Június', 'Július', 'Augusztus', 'Szeptember', 'Október', 'November', 'December' ];
	}
}

HTCalendar.prototype.getDayNames = function(abbr) {
	if(abbr) {
		return [ 'V', 'H', 'K', 'Sz', 'Cs', 'P', 'Szo' ];
	} else {
		return [ 'Vasárnap', 'Hétfő', 'Kedd', 'Szerda', 'Csütörtök', 'Péntek', 'Szombat' ];
	}
}

HTCalendar.prototype.getFirstDayOfWeek = function() {
	return 1;
}

/**
 * [ { week: [ 0, 23 ], days: [ [ -1, 30 ], [ 0, 1 ], [ 0, 2 ], ... ] } ]
 */
HTCalendar.prototype.getMonthLook = function(year, month) {
	var ml = new Array();

	var d = 1 + this.getFirstDayOfWeek() - new Date(year, month, 1).getDay();
	if(d > 1) d -= 7;
	var d1 = this.getMonthLastDay(year, month);

	do {
		// week
		var wnd = new Date(year, month, d);
		var wnd0 = new Date(wnd.getTime());
		wnd0.setMonth(0);
		wnd0.setDate(1);
		var wd = wnd0.getDay();
		wnd0.setDate((wd > 4 ? 8 : 1) - wd + this.getFirstDayOfWeek());
		var wn = Math.floor((wnd.getTime() - wnd.getTimezoneOffset() * 1000*60 - wnd0.getTime() + wnd0.getTimezoneOffset() * 1000*60) / (1000*60*60*24*7)) + 1; // Az év első hetének első napjától eltelt hetek száma.
//			console.log('w: %s, %s, %d', wnd, wnd0, wn);

		var wl = { 'week': { 'num': wn }, 'days': [] };
		for(var i = 0; i < 7; i++, d++) {
			var ddescr;
			var ddate = new Date(year, month, d);
			if(d < 1) {
				ddescr = { 'month': -1, 'num': ddate.getDate() };
			} else if(d > d1) {
				ddescr = { 'month': 1, 'num': d - d1 };
			} else {
				ddescr = { 'month': 0, 'num': d };
			}
			ddescr.descr = this.descriptor.validateDay != null ? this.descriptor.validateDay(this, ddate) : true;
			wl.days.push(ddescr);
		}
		ml.push(wl);
	} while(d <= d1);

	return ml;
}

HTCalendar.prototype.getMonthLastDay = function(year, month) {
	return new Date(new Date(year, month + 1, 1) - 1000).getDate();
}


HTCalendar.prototype.formatDate = function(date) {
	if(date == null) return '';

	var fmt = [ '%04d', '-%02d', '-%02d', ' %02d', ':%02d', ':%02d' ].slice(0, this.descriptor.type._l).join('');
	return fmt.printf(date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds());
}

HTCalendar.prototype.parseDate = function(dateStr) {
	var re = /^([^0-9]*)([0-9]{1,4})(?:([^0-9]+)([0-9]{1,2})(?:([^0-9]+)([0-9]{1,2})(?:([^0-9]+)([0-9]{1,2})(?:([^0-9]+)([0-9]{1,2})(?:([^0-9]+)([0-9]{1,2}))?)?)?)?)?([^0-9]*)$/;
	var di = re.exec(dateStr);

	if(!di) return null;

//	console.dir(di);

	function _v(v, min, max, def) {
		if(typeof v == "undefined" || v < min || v > max) return def;
		return new Number(v).valueOf();
	}

	var now = new Date();
	var year = _v(di[2], 1, 30000, now.getFullYear());
	var month = _v(di[4], 1, 12, now.getMonth() + 1) - 1;
	var day = _v(di[6], 1, this.getMonthLastDay(year, month), now.getDate());
	var hour = _v(di[8], 0, 23, now.getHours());
	var minute = _v(di[10], 0, 59, now.getMinutes());
	var second = _v(di[12], 0, 59, now.getSeconds());

	return new Date(year, month, day, hour, minute, second);
}

/**
 *
 */
function HTCalAbstractAnchorView(helper, element) {
	this.helper = helper;
	this.element = element;
}

HTCalAbstractAnchorView.prototype.update = function() {
}

HTCalAbstractAnchorView.prototype.getDate = function() {
	return null;
}

HTCalAbstractAnchorView.prototype.getAnchorPoint = function() {
	return false;
}

HTCalAbstractAnchorView.prototype.getAnchorElement = function() {
	return false;
}

HTCalAbstractAnchorView.prototype.init = function() {
}

/**
 * Az input.
 */
function HTCalendarAnchorView(helper, element) {
	HTCalAbstractAnchorView.call(this, helper, element);

	var _this = this;
	var delValue = helper.getParam('deleteValue');

	if(delValue !== false) {
		var jdel = [ "img",
			{ 'src': helper.getParam('deleteIcon'), 'alt': "Törlés", 'class': "adm_calendar_link", 'onclick': function() { _this.helper.getCalendar().setDate(delValue); return false; } }
		];

		this.eDeleteButton = jsonML(jdel);
		element.parentNode.insertBefore(this.eDeleteButton, element.nextSibling);
	}

	var jopen = [ "img",
		{ 'src': helper.getParam('icon'), 'alt': "Calendar", 'class': "adm_calendar_link", 'onclick': function() { _this.helper.getCalendar().show(); return false; } }
	];

	this.eButton = jsonML(jopen);
	element.parentNode.insertBefore(this.eButton, element.nextSibling);

	if(this.helper.getParam('pin')) {
		element.onkeyup = function() { _this.helper.triggerChange(); };
	} else {
		element.onfocus = function() { _this.helper.getCalendar().hide(); };
		element.onchange = function() { _this.helper.triggerChange(); };
	}
}

jgtc.__extends(HTCalendarAnchorView, HTCalAbstractAnchorView);

HTCalendarAnchorView.prototype.update = function() {
	console.log("HTCalendarAnchorView.prototype.update()");

	this.element.value = this.helper.getCalendar().formatDate(this.helper.getDate());
}

HTCalendarAnchorView.prototype.getDate = function() {
	console.log("HTCalendarAnchorView.prototype.getDate()");

	return this.helper.getCalendar().parseDate(this.element.value);
}

HTCalendarAnchorView.prototype.getAnchorPoint = function() {
	var b = jgtc.getBounds(this.eButton);
	return { 'x': b.x, 'y': b.y, 'exclude': jgtc.getBounds(this.element) };
}

/**
 *
 */
function HTCalendarEmbedView(helper, element) {
	HTCalAbstractAnchorView.call(this, helper, element);

	this.date = new Date();
}

jgtc.__extends(HTCalendarEmbedView, HTCalAbstractAnchorView);

HTCalendarEmbedView.prototype.init = function() {
	this.helper.setParam('closeButton', false);
	this.helper.setParam('opacity', 1);
	this.helper.setParam('fancy', false);
	this.helper.getCalendar().show();
}

HTCalendarEmbedView.prototype.getAnchorElement = function() {
	return this.element;
}

HTCalendarEmbedView.prototype.update = function() {
	this.date = this.helper.getDate();
}

HTCalendarEmbedView.prototype.getDate = function() {
	return this.date;
}


/**
 * Az absztrakt panel
 */
function HTCalAbstractPanelView(helper) {
	this.helper = helper;
}

HTCalAbstractPanelView.prototype.init = function() {
}

HTCalAbstractPanelView.prototype.show = function() {
}

HTCalAbstractPanelView.prototype.hide = function() {
}

HTCalAbstractPanelView.prototype.update = function() {
}

HTCalAbstractPanelView.prototype.getDate = function() {
	return null;
}


/**
 * A panel
 */
function HTCalendarPanelView(helper) {
	HTCalAbstractPanelView.call(this, helper)
	this.ePanel = null;
	this.eMonthPanel = null;
}

jgtc.__extends(HTCalendarPanelView, HTCalAbstractPanelView);

HTCalendarPanelView.prototype.createPanelElement = function() {
}

HTCalendarPanelView.prototype.createPanel = function() {
	var _this = this;
	this.panel = new Object();

//	console.log("date: %o", this.date);

	function _year(y) {
		_this.date.setFullYear(_this.panel.eYear.value = y);
		_month_tab();
		_this.triggerChange();
	}

	function _month(m) {
		_this.date.setMonth(m);

		_this.panel.eYear.value = _this.date.getFullYear();
		_this.panel.eMonth.replaceChild(jsonML(_this.helper.getCalendar().getMonthNames(false)[_this.date.getMonth()]), _this.panel.eMonth.firstChild);
		_month_tab();
		_this.triggerChange();
	}

	function _close() {
		_this.helper.getCalendar().hide();
		return false;
	}

	function _year_l() {
		_year(Math.max(_this.date.getFullYear() - 1, 1900));
		return false;
	}

	function _year_r() {
		_year(Math.min(_this.date.getFullYear() + 1, 5000));
		return false;
	}

	function _year_c() {
		_year(_this.panel.eYear.value);
		return false;
	}

	function _month_l() {
		_month(_this.date.getMonth() - 1);
		return false;
	}

	function _month_r() {
		_month(_this.date.getMonth() + 1);
		return false;
	}

	function _month_c() {
		return false;
	}

	function _c_day(d) {
		return function(e) {
			if(!e) e = event;
			jgtc.discardEvent(e);

//			console.log("event: ", e);
			if(e.detail > 1) {
				if(_this.helper.descriptor.closeButton) {
					_close();
				}
			} else {
				_this.date.setDate(d);

				_month_tab();
				_this.triggerChange();
			}
			return false;
		}
	}

	function _hour() {
		_this.date.setHours(_this.panel.eHour.value);
		_this.triggerChange();
		return false;
	}

	function _minute() {
		_this.date.setMinutes(_this.panel.eMinute.value);
		_this.triggerChange();
		return false;
	}

	function _second() {
		_this.date.setSeconds(_this.panel.eSecond.value);
		_this.triggerChange();
		return false;
	}

	function _month_tab() {
		var jsonWeekHead = [ "tr", [ "th", " " ] ];
		var wnl = _this.helper.getCalendar().getDayNames(true);
		for(var id = 0; id < 7; id++) {
			var d = (id + _this.helper.getCalendar().getFirstDayOfWeek()) % 7;
			if(d == 0) {
				jsonWeekHead.push([ "th", { 'class': "u" }, wnl[d] ]);
			} else {
				jsonWeekHead.push([ "th", wnl[d] ]);
			}
		}

		var jsonMonthTab = [ "tbody", jsonWeekHead ];
//		var month = new Object();

		var day = _this.date.getDate();
		var ml = _this.helper.getCalendar().getMonthLook(_this.date.getFullYear(), _this.date.getMonth());
		for(var iw = 0; iw < ml.length; iw++) {
			var w = ml[iw];
			var jsonWeek = [ "tr", [ "td", { 'class': 'w' }, w.week.num ] ];
			for(var iwd = 0; iwd < w.days.length; iwd++) {
				var dd = w.days[iwd];
				var ddj;
				if(dd.month != 0) {
					ddj = [ "td", " " ];
				} else {
					var ddescr = dd.descr;
					if(ddescr === true) ddescr = {};
					else if(ddescr === false) ddescr = { 'disabled': true };

					var dclass = day == dd.num ? "s" : "d";
					if(ddescr.disabled) dclass += " dis";
					if(ddescr.className) dclass += ' ' + ddescr.className;

					var djson = ('face' in ddescr) ? ddescr.face : dd.num;

					ddj = [ "td", { 'class': dclass /*, 'element': month, 'elementId': dd[1] */ }, djson ];
					if(!ddescr.disabled) ddj[1]['onclick'] = _c_day(dd.num);
					if(ddescr.tip) ddj[1]['c:tip'] = ddescr.tip;
				}
				jsonWeek.push(ddj);
			}
			jsonMonthTab.push(jsonWeek);
		}

		jsonMonthTab = [ "table", jsonMonthTab ];

		var eMonthTab = jgtc.jsonML().addUserAttribute('c', _c_attr).build(jsonMonthTab);
		with(_this.panel) {
			if(eDays.firstChild != null) {
				eDays.replaceChild(eMonthTab, eDays.firstChild);
			} else {
				eDays.appendChild(eMonthTab);
			}
		}
	}

	function _c_attr(e, prefix, attr, value) {
		if(attr == 'tip') {
			if(typeof HTTip != 'undefined') {
				HTTip.create(e, { 'tip': value });
			}
		} else {
			console.warn("Invalid calendar attribute: %s", attr);
		}
	}

	var ePanel = (function() {
		var jsonPanel = [ "div", { 'class': _this.helper.getParam('panelClass'), 'style': "-moz-transform-origin: left top; -webkit-transform-origin: left top; -o-transform-origin: left top; -ms-transform-origin: left top; transform-origin: left top;" } ];
		if(_this.helper.getParam('closeButton')) {
			jsonPanel.push([ "a", { 'class': "close", 'href': "javascript:nop();", "onclick": _close } ]);
		}
		jsonPanel.push(
			[ "h1",
				[ "a", { 'class': "l", 'href': "javascript:nop();", "onclick": _year_l } ],
				[ "input", { 'type': 'text', 'value': _this.date.getFullYear(), 'onchange': _year_c, 'onkeyup': _year_c, 'element': _this.panel, 'elementId': 'eYear' } ],
				[ "a", { 'class': "r", 'href': "javascript:nop();", "onclick": _year_r } ]
			],
			[ "h2",
				[ "a", { 'class': "l", 'href': "javascript:nop();", "onclick": _month_l } ],
				[ "a", { 'href': "javascript:nop();", 'class': "month", 'onclick': _month_c, 'element': _this.panel, 'elementId': 'eMonth' }, _this.helper.getCalendar().getMonthNames(false)[_this.date.getMonth()] ],
				[ "a", { 'class': "r", 'href': "javascript:nop();", "onclick": _month_r } ]
			],
			[ "div", { 'element': _this.panel, 'elementId': 'eDays', 'class': "days" } ]
		);

		var jsonTime = [ "h3" ];

		with(_this.helper.getParam('type')) {
			if(hasHour) {
				jsonTime.push([ "input", { 'type': "text", 'value': "%02d".printf(_this.date.getHours()), 'onchange': _hour, 'onkeyup': _hour, 'element': _this.panel, 'elementId': 'eHour' } ]);
			}
			if(hasMinute) {
				jsonTime.push(" : ");
				jsonTime.push([ "input", { 'type': "text", 'value': "%02d".printf(_this.date.getMinutes()), 'onchange': _minute, 'onkeyup': _minute, 'element': _this.panel, 'elementId': 'eMinute' } ]);
			}
			if(hasSecond) {
				jsonTime.push(" : ");
				jsonTime.push([ "input", { 'type': "text", 'value': "%02d".printf(_this.date.getSeconds()), 'onchange': _second, 'onkeyup': _second, 'element': _this.panel, 'elementId': 'eSecond' } ]);
			}
		}
		if(jsonTime.length > 1) jsonPanel.push(jsonTime);

		return jgtc.jsonML().build(jsonPanel);
	})();

	_month_tab();

	return ePanel;
}

HTCalendarPanelView.prototype.destroyPanel = function() {
	this.helper.getAnchorElement().removeChild(this.ePanel);
	this.ePanel = null;
}

HTCalendarPanelView.prototype.setupPanel = function(ePanel) {
	if(this.ePanel != null) {
		this.helper.getAnchorElement().replaceChild(ePanel, this.ePanel);
	} else {
		this.helper.getAnchorElement().appendChild(ePanel);
	}

	var b0 = jgtc.getBounds(ePanel);
	var b1 = this.helper.getPanelPosition(b0.w, b0.h);
	if(b1) {
		with(ePanel.style) {
			position = "absolute";
			left = b1.x + "px";
			top = b1.y + "px";
		}
	}

	this.ePanel = ePanel;
}

HTCalendarPanelView.prototype.animatePanel = function(x) {
	var o = this.helper.getParam('opacity');

	if(is.ie && !is.ie9) {
		var x1 = Math.round(x * o * 100);
		if(x1 != 100) this.ePanel.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + x1 + ")";
		else this.ePanel.style.filter = "";
	} else {
		var s = 'scale(' + x + ')';
		this.ePanel.style.opacity = x * o;
		this.ePanel.style.transform = s;
		this.ePanel.style.msTransform = s;
		this.ePanel.style.MozTransform = s;
		this.ePanel.style.WebkitTransform = s;
		this.ePanel.style.OTransform = s;
	}
}

HTCalendarPanelView.prototype.show = function() {
	if(this.date != null) {
		this.tw_opacity.cancel();
	}
	this.date = this.helper.getDate();
	this.setupPanel(this.createPanel());

	var _this = this;

	if(this.helper.getParam('fancy')) {
		this.tw_opacity = new HTTween(function(x, mode) {
			if(x == 0 && mode == 2) {
				_this.destroyPanel();
			} else {
				_this.animatePanel(x);
			}
		}, 'sinoidal', 400).start(0, 1);
	} else {
		this.animatePanel(1);
	}
}

HTCalendarPanelView.prototype.hide = function() {
	if(this.helper.getParam('fancy')) {
		this.tw_opacity.start(1, 0);
	} else {
		this.destroyPanel();
	}
}

HTCalendarPanelView.prototype.update = function() {
	this.date = this.helper.getDate();
	this.setupPanel(this.createPanel());
}

HTCalendarPanelView.prototype.getDate = function() {
	return this.date;
}

HTCalendarPanelView.prototype.triggerChange = function() {
	return this.helper.triggerChange();
}

/*
 * Init.
 */
jgtc.captureEvent(window, "load", function() {
	var tags = document.getElementsByTagName("*");
	for(var i = 0; i < tags.length; i++) {
		var cal = jgtc.safeGetAttribute(tags[i], "ht:calendar");
		if(cal != null) {
			if("YMDhms".indexOf(cal) == 0) {
				new HTCalendar(tags[i], { 'type' : cal });
			} else {
				var d;
				try {
					eval('d = {' + cal + '};');
				} catch(err) {
					console.warn("Hibás kalendár descriptor: %s, %o", cal, err);
					continue;
				}
				new HTCalendar(tags[i], d);
			}
		}
	}
}, true);


