/*
IMPORTANT - This script request the 'common.js' script file.
*/

var visibleDropListId = '';
var calendarCallback = null;
var calendarMinYear = 0;
var calendarMinMonth = 0;
var calendarMinDay = 0;
var calendarMaxYear = 0;
var calendarMaxMonth = 0;
var calendarMaxDay = 0;
var calendarDate = new Date();
var dropListTimer = 0;

function echo(s) {
	var jsOutput = $('jsOutput');
	if (jsOutput == null) { alert(s); }
	else { jsOutput.innerHTML = s; }
}

// Mouse & Keys events
// --------------------------------------------------------------------------------------

var mousePos = new Point(0, 0);
var mousePosMax = new Point(0, 0);

function getMousePos(e) {
	var scrollPos = getScrollPos();
	if (browser.isExplorer()) {
		mousePos.setX(window.event.x + scrollPos.x);
		mousePos.setY(window.event.y + scrollPos.y);
		mousePosMax.setX(document.body.clientWidth + scrollPos.x);
		mousePosMax.setY(document.body.clientHeight + scrollPos.y);
	} else {
		mousePos.setX(e.pageX);
		mousePos.setY(e.pageY);
		mousePosMax.setX(window.innerWidth + window.pageXOffset);
		mousePosMax.setY(window.innerHeight + window.pageYOffset);
	}
}

function getMouseDown(e) {
	var dropList = null;
	if (visibleDropListId == 'page-calendar-wrap') {
		dropList = $('page-calendar-wrap');
	} else if (visibleDropListId != '') {
		dropList = $(visibleDropListId + '_list');
	}
	if (dropList != null) {

		var objlayout = getObjLayout(dropList);
		if (browser.isExplorer(8)) {
			var scrollPos = getScrollPos();
			objlayout.top = objlayout.top + scrollPos.y;
			objlayout.bottom = objlayout.bottom + scrollPos.y;
		} else {

		}
		objlayout.setTop(objlayout.top - 28);
		if (!pointInRect(mousePos, objlayout)) {
			doHideDrop(visibleDropListId);
			return false;
		}
	}
}

if (browser.isNetscape()) {
	document.captureEvents(Event.MOUSEMOVE);
	document.captureEvents(Event.MOUSEDOWN);
}

addEvent(window, 'load', function() {
	document.onmousemove = getMousePos;
	document.onmousedown = getMouseDown;
});

// Function: addListElement(listId [string])
// --------------------------------------------------------------------------------------
function addListElement(listId) {
	if (browser.isExplorer()) {
		var holder = document.getElementById('ddListsControl');
		holder.innerHTML = holder.innerHTML + '<div id="' + listId + '_list" class="ddList"><div id="' +
			listId + '_content" style="visibility:hidden;display:none;height:250px"></div></div>';
		return;
	}
	var b = document.body;
	var newDivList = document.createElement('div');
	newDivList.setAttribute('id', listId + '_list');
	newDivList.setAttribute('class', 'ddList');
	newDivList.innerHTML = '<div id="' + listId +
		'_content" style="visibility:hidden;display:none;height:250px"></div>';
	b.appendChild(newDivList);
}

// Function: fillListItems(listId [string])
// --------------------------------------------------------------------------------------
function fillListItems(listId) {
	var listContent = $(listId + '_content');
	var listSelect = $(listId + '_sel');
	var lText = '', itemClass = '';
	var lCode = '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tbody>';
	if (listContent == null || listSelect == null) { return; }
	for (var i = 0; i < listSelect.options.length; i++) {
		lText = listSelect.options[i].text;
		if (lText == '') { continue; }
		if (listSelect.options[i].selected) { itemClass = 'ddListItemSel'; }
		else { itemClass = 'ddListItem'; }
		lCode += '<tr><td id="' + listId + '_selitem' + i + '" class="' + itemClass +
			'" onmouseover="this.className=\'ddListItemHover\'" onmouseout="this.className=\'' +
			itemClass + '\'" onclick="selectListItem(\'' + listId + '\',' + i +')"';
		if (!listSelect.options[i].selected) { lCode += '>' + lText + '</td></tr>'; }
		else { lCode += ' style="font-weight:bold">' + lText + '</td></tr>'; }
	}
	lCode += '</tbody></table>';
	listContent.innerHTML = lCode;
}

// Function: selectListItem(listId [string], index [integer])
// --------------------------------------------------------------------------------------
function selectListItem(listId, index) {
	var listSelect = $(listId + '_sel');
	var listEdit = $(listId + '_edit');
	listSelect.options[index].selected = true;
	listEdit.value = listSelect.options[index].text;
	if (listSelect.onchange) { listSelect.onchange(); }
	doHideDrop(listId);
}

// Function: animateDropList(listId [string])
// --------------------------------------------------------------------------------------
function animateDropList(listId, maxHeight) {
	if (dropListTimer) {
		clearTimeout(dropListTimer);
		dropListTimer = 0;
	}
	var listCtrl = $(listId + '_list');
	if (listCtrl == null) { return; }
	var listHeight = listCtrl.offsetHeight;
	if (listHeight < maxHeight) {
		listHeight = listHeight + 10;
		if (listHeight > maxHeight) { listHeight = maxHeight; }
		listCtrl.style.height = listHeight + 'px';
		if (listHeight < maxHeight) {
			dropListTimer = setTimeout('animateDropList("' + listId + '", ' + maxHeight + ')', 25);
		}
	}
	if (!dropListTimer) {
		var listContent = $(listId + '_content');
		if (listContent == null) { return; }
		listContent.style.visibility = 'visible';
		listContent.style.display = 'inline';
		var listSelect = $(listId + '_sel');
		if (listSelect != null) {
			var selScroll = listSelect.selectedIndex * 20;
			listCtrl.scrollTop = selScroll;
		}
	}
}

// Function: doDrop(listId [string], (deltaX [integer], deltaY [integer]))
// --------------------------------------------------------------------------------------
function doDrop(listId, deltaX, deltaY) {
	if (listId == visibleDropListId) {
		doHideDrop(listId);
		return;
	}
	if (visibleDropListId != '') { doHideDrop(visibleDropListId); }
	var editCtrl = $(listId + '_edit');
	var listCtrl = $(listId + '_list');
	if (listCtrl == null) {
		addListElement(listId);
		listCtrl = $(listId + '_list');
	}
	fillListItems(listId);
	if (editCtrl != null && listCtrl != null) {
		editCtrl.onKeyUp = doDropKeyDown;
		var epos = getObjLayout(editCtrl);
		if (browser.isOpera()) { epos.top = epos.top + 23; }
		else { epos.top = epos.top + 24; }
		epos.left = epos.left - 1;
		if (browser.isOpera()) { epos.width = epos.width + 22; }
		else { epos.width = epos.width + 24; }
		if (browser.isExplorer() && deltaX && deltaY) {
			if (deltaX != 0) { epos.left = epos.left + deltaX; }
			if (deltaY != 0) { epos.top = epos.top + deltaY; }
		}
		listCtrl.style.left = epos.left + "px";
		listCtrl.style.top = epos.top + "px";
		listCtrl.style.height = '1px';
		listCtrl.style.width = epos.width + "px";
		listCtrl.style.zIndex = 1000;
		listCtrl.style.visibility = 'visible';
		listCtrl.style.display = 'inline';
		editCtrl.focus();
		var listSelect = $(listId + '_sel');
		var maxHeight = 100;
		if (listSelect != null) {
			var listItem = $(listId + '_selitem0');
			if (listSelect.options.length > 6) {
				maxHeight = (6 * 20) + 2;
			} else if (listSelect.options.length < 3) {
				maxHeight = (2 * 20) + 2;
			} else {
				maxHeight = (listSelect.options.length * 20) + 2;
			}
		}
		dropListTimer = setTimeout('animateDropList("' + listId + '", ' + maxHeight + ')', 25);
		visibleDropListId = listId;
	}
}

// Function: doDropKey
// --------------------------------------------------------------------------------------
function doDropKeyUp(e, listId) {
	document.defaultAction = true;

	var evt = e || window.event;
	var keyCode = 0;
	if (typeof(evt.keyCode) == 'number') { keyCode = evt.keyCode; }
	else if (typeof(evt.which) == 'number') { keyCode = evt.which; }
	else if (typeof(evt.charCode) == 'number') { keyCode = evt.charCode; }
	else { return; }
	if (visibleDropListId == '' && listId != null) {
		if (keyCode == 38 || keyCode == 40) {
			var dropEdit = $(listId + '_edit');
			if (dropEdit != '') {
				document.defaultAction = false;
				dropEdit.click();
			}
		}
		return false;
	}
	var dropSel = $(visibleDropListId + '_sel');
	var dropList = $(visibleDropListId + '_list');
	var dropEdit = $(visibleDropListId + '_edit');
	if (dropSel == null || dropList == null || dropEdit == null) {
		document.defaultAction = true;
		return false;
	}

	switch (keyCode) {
		case 27:
		case 13:
			doHideDrop(visibleDropListId);
			document.defaultAction = false;
			return false;
			break;
		case 38:
			var selItemIndex = dropSel.selectedIndex;
			if (dropSel.selectedIndex == 0) {
				document.defaultAction = false;
				return false;
			}
			var prevItemIndex = selItemIndex - 1;
			var selItem = $(dropSel.id + 'item' + selItemIndex);
			var prevItem = $(dropSel.id + 'item' + prevItemIndex);
			if (prevItem == null || selItem == null) {
				document.defaultAction = false;
				return false;
			}
			dropSel.selectedIndex = prevItemIndex;
			selItem.className = 'ddListItem';
			prevItem.className = 'ddListItemSel';
			selItem.style.fontWeight = 'normal';
			prevItem.style.fontWeight = 'bold';
			dropEdit.value = dropSel.options[dropSel.selectedIndex].text;
			var selScroll = prevItemIndex * 20;
			dropList.scrollTop = selScroll;
			document.defaultAction = false;
			return false;
			break;
		case 40:
			var selItemIndex = dropSel.selectedIndex;
			if (dropSel.selectedIndex == dropSel.options.length - 1) {
				document.defaultAction = false;
				return false;
			}
			var nextItemIndex = selItemIndex + 1;
			var selItem = $(dropSel.id + 'item' + selItemIndex);
			var nextItem = $(dropSel.id + 'item' + nextItemIndex);
			if (nextItem == null || selItem == null) {
				document.defaultAction = false;
				return false;
			}
			dropSel.selectedIndex = nextItemIndex;
			selItem.className = 'ddListItem';
			nextItem.className = 'ddListItemSel';
			selItem.style.fontWeight = 'normal';
			nextItem.style.fontWeight = 'bold';
			dropEdit.value = dropSel.options[dropSel.selectedIndex].text;
			var selScroll = nextItemIndex * 20;
			dropList.scrollTop = selScroll;
			document.defaultAction = false;
			return false;
			break;
	}
	return true;
}

function doDropKeyDown(e) {
	document.defaultAction = false;
	return false;

}


// Function: doHideDrop(listId [string])
// --------------------------------------------------------------------------------------
function doHideDrop(listId) {
	if (dropListTimer) {
		clearTimeout(dropListTimer);
		dropListTimer = 0;
	}
	var listCtrl = $(listId + '_list');
	var listContent = $(listId + '_content');
	var listCtrlExt = $(listId);
	if (listCtrl != null) {
		listCtrl.style.zIndex = 1;
		listCtrl.style.visibility = 'hidden';
		listCtrl.style.display = 'none';
	}
	if (listContent != null) {
		listContent.style.visibility = 'hidden';
		listContent.style.display = 'none';
	}
	if (listCtrlExt != null) {
		if (visibleDropListId == 'page-calendar-wrap' && calendarCallback != null) {
			calendarCallback = null;
		}
		listCtrlExt.style.visibility = 'hidden';
		listCtrlExt.style.display = 'none';
	}
	if (visibleDropListId == listId) { visibleDropListId = ''; }
}

// Function: checkRadio(idPrefix [string], id [integer])
// --------------------------------------------------------------------------------------
function checkRadio(idPrefix, id) {
	var radioImg = null;
	var radioObj = null;
	for (var i = 1; i < 100; i++) {
		radioImg = document.getElementById(idPrefix + i + 'f');
		radioObj = document.getElementById(idPrefix + i);
		if (radioImg == null || radioObj == null) {
			break;
		} else {
			radioImg.src = '/images/frmTRadio.png';
			radioObj.checked = false;
		}
	}
	radioImg = document.getElementById(idPrefix + id + 'f');
	radioObj = document.getElementById(idPrefix + id);
	if (radioImg == null || radioObj == null) { return; }
	radioImg.src = '/images/frmTRadioChk.png';
	radioObj.checked = true;
}

// Function: toggleCheckbox(id [string])
// --------------------------------------------------------------------------------------
function toggleCheckbox(id) {
	var checkImg = document.getElementById(id + 'f');
	var checkObj = document.getElementById(id);
	if (checkImg == null || checkObj == null) { return; }
	if (checkObj.checked) {
		checkImg.src = '/images/frmTCheck.png';
		checkObj.checked = false;
	} else {
		checkImg.src = '/images/frmTCheckChk.png';
		checkObj.checked = true;
	}
}

// Function: focusElement(param [mixed - object or string])
// --------------------------------------------------------------------------------------
function focusElement(param) {
	if (typeof(param) == 'string') { var element = $(param); }
	else if (typeof(param) == 'object') { var element = param; }
	else { return; }
	if (element == null) { return; }
	var id = element.id;
	var v = element.value;
	switch (id) {
		case 'lgusr':
		case 'lgusr2':
			if (v.trim() == 'Nume utilizator') { element.value = ''; }
			break;
		case 'lgpwd':
		case 'lgpwd2':
			if (v.trim() == '******') { element.value = ''; }
			break;
		case 'nleml':
			if (v.trim() == 'Adresa ta de email') { element.value = ''; }
			break;
		case 'srcterm':
			if (v.trim() == 'Cauta termeni...') { element.value = ''; }
			break;
		case 'party':
			if (v.trim() == 'Persoane...') { element.value = ''; }
			break;
	}
}

// Function: focusElementEn(param [mixed - object or string])
// --------------------------------------------------------------------------------------
function focusElementEn(param) {
	if (typeof(param) == 'string') { var element = $(param); }
	else if (typeof(param) == 'object') { var element = param; }
	else { return; }
	if (element == null) { return; }
	var id = element.id;
	var v = element.value;
	switch (id) {
		case 'lgusr':
		case 'lgusr2':
			if (v.trim() == 'Username') { element.value = ''; }
			break;
		case 'lgpwd':
		case 'lgpwd2':
			if (v.trim() == '******') { element.value = ''; }
			break;
		case 'nleml':
			if (v.trim() == 'Your email address') { element.value = ''; }
			break;
		case 'srcterm':
			if (v.trim() == 'Search terms...') { element.value = ''; }
			break;
		case 'party':
			if (v.trim() == 'Seats...') { element.value = ''; }
			break;
	}
}

// Function: blurElement(param [mixed - object or string])
// --------------------------------------------------------------------------------------
function blurElement(param) {
	if (typeof(param) == 'string') { var element = $(param); }
	else if (typeof(param) == 'object') { var element = param; }
	else { return; }
	if (element == null) { return; }
	var id = element.id;
	var v = element.value;
	switch (id) {
		case 'lgusr':
		case 'lgusr2':
			if (v.trim() == '') { element.value = 'Nume utilizator'; }
			break;
		case 'lgpwd':
		case 'lgpwd2':
			if (v.trim() == '') { element.value = '******'; }
			break;
		case 'nleml':
			if (v.trim() == '') { element.value = 'Adresa ta de email'; }
			break;
		case 'srcterm':
			if (v.trim() == '') { element.value = 'Cauta termeni...'; }
			break;
		case 'party':
			if (v.trim() == '') { element.value = 'Persoane...'; }
			break;
	}
}

// Function: blurElementEn(param [mixed - object or string])
// --------------------------------------------------------------------------------------
function blurElementEn(param) {
	if (typeof(param) == 'string') { var element = $(param); }
	else if (typeof(param) == 'object') { var element = param; }
	else { return; }
	if (element == null) { return; }
	var id = element.id;
	var v = element.value;
	switch (id) {
		case 'lgusr':
		case 'lgusr2':
			if (v.trim() == '') { element.value = 'Username'; }
			break;
		case 'lgpwd':
		case 'lgpwd2':
			if (v.trim() == '') { element.value = '******'; }
			break;
		case 'nleml':
			if (v.trim() == '') { element.value = 'Your email address'; }
			break;
		case 'srcterm':
			if (v.trim() == '') { element.value = 'Search terms...'; }
			break;
		case 'party':
			if (v.trim() == '') { element.value = 'Seats...'; }
			break;
	}
}

// Function: doDropCalendar((deltaX [integer], deltaY [integer]))
// --------------------------------------------------------------------------------------
function doDropCalendar(objs, funcCallback, deltaX, deltaY, minYear, minMonth, minDay) {
	if (visibleDropListId == 'page-calendar-wrap') {
		doHideDrop(visibleDropListId);
		return;
	}
	if (visibleDropListId != '') { doHideDrop(visibleDropListId); }
	if (objs == null) { return; }

	var listCtrl = $('page-calendar-wrap');
	if (listCtrl == null) { return; }

	var x = 0, y = 0, w = 0, h = 0;
	var editCtrl = null;

	if (typeof(objs) == 'object') {

		var epos;
		for (var i = 0; i < objs.length; i++) {
			editCtrl = $(objs[i] + '_edit');
			if (editCtrl != null) {
				epos = getObjLayout(editCtrl);
				if (x == 0 && y == 0) {
					x = epos.left;
					y = epos.top;
				}
				if (w > 0) { w = w + 32; }
				w = w + epos.width;
				h = epos.height;
			}
		}
	} else if (typeof(objs) == 'string') {
		editCtrl = $(objs + '_edit');
		if (editCtrl != null) {
			epos = getObjLayout(editCtrl);
			x = epos.left;
			y = epos.top;
			w = epos.width;
			h = epos.height;
		}
	} else { return; }

	editCtrl.onKeyUp = doDropKeyDown;
	if (browser.isOpera()) { y = y + 23; }
	else { y = y + 24; }
	x = x - 1;
	if (browser.isOpera()) { w = w + 56; }
	else { w = w + 58; }
	if (browser.isExplorer() && deltaX && deltaY) {
		if (deltaX != 0) { x = x + deltaX; }
		if (deltaY != 0) { y = y + deltaY; }
	}

	if (funcCallback != null) { calendarCallback = funcCallback; }
	if (minYear != null) { calendarMinYear = minYear; }
	else { calendarMinYear = 0; }
	if (minMonth != null) { calendarMinMonth = minMonth - 1; }
	else { calendarMinMonth = 0; }
	if (minDay != null) { calendarMinDay = minDay; }
	else { calendarMinDay = 0; }

	var calendarHdr = $('calendar-header');
	if (calendarHdr != null) { calendarHdr.style.width = w + 'px'; }
	drawCalendar(calendarDate);

	listCtrl.style.left = x + "px";
	listCtrl.style.top = y + "px";
	if (browser.isExplorer()) { listCtrl.style.height = '180px'; }
	else { listCtrl.style.height = '173px'; }
	listCtrl.style.width = w + "px";
	listCtrl.style.zIndex = 1000;
	listCtrl.style.visibility = 'visible';
	listCtrl.style.display = 'inline';
	var monthCalendarTable = $('month-calendar-table');
	if (monthCalendarTable != null) {
		if (monthCalendarTable.offsetHeight > 0) {
			listCtrl.style.height = (28 + monthCalendarTable.offsetHeight) + 'px';
		}
	}
	editCtrl.focus();
	visibleDropListId = 'page-calendar-wrap';
}

function drawCalendar(calDate) {
	var calendarMonWrap = $('calendar-month-wrap');
	if (calendarMonWrap == null || calDate == null) { return; }
		var monthCode = '<table border="0" cellpadding="0" cellspacing="0" width="100%" id="month-calendar-table"><tbody>' +
			'<tr><td class="calendarWDay">L</td><td class="calendarWDay">M</td><td class="calendarWDay">M</td>' +
			'<td class="calendarWDay">J</td><td class="calendarWDay">V</td><td class="calendarWDay" ' +
			'style="color:#CE2565">S</td><td class="calendarWDay" style="color:#CE2565;border-right:0 none">D</td></tr>';

	var month = calDate.getMonth();
	var weekday = calDate.getDay();
	weekday = weekday - 1;
	if (weekday < 0) { weekday = 6; }
	var day = calDate.getDate();
	var year = calDate.getFullYear();
	var daysInMonth = getDaysInMonth(month, year);

	var firstMonthDay = new Date();
	firstMonthDay.setFullYear(year, month, 1);
	var firstWeekday = firstMonthDay.getDay();
	firstWeekday = firstWeekday - 1;
	if (firstWeekday < 0) { firstWeekday = 6; }

	var monyear = $('calendar-monyear');
	if (monyear != null) {
		monyear.innerHTML = month_names[month] + ' ' + year;
	}

	var weekdayCol = 0;
	var noClick = false;
	var noPrevMonth = false;
	var noNextMonth = false;
	var isSelected = false;
	var isWeekend = false;

	for (var d = 1; d <= daysInMonth; d++) {
		if (weekdayCol == 0) { monthCode += '<tr>'; }
		if (d == 1) {
			while (weekdayCol < firstWeekday) {
				monthCode += '<td class="calendarDay">&nbsp;</td>';
				weekdayCol++;
			}
		}

		isSelected = false;
		isWeekend = false;

		monthCode += '<td ';
		if (d == day) {
			monthCode += 'class="calendarDaySel"';
			isSelected = true;
			if (weekdayCol == 6) { monthCode += ';border-right:0 none'; }
		} else if (weekdayCol == 5 || weekdayCol == 6) {
			monthCode += 'class="calendarWEDay"';
			isWeekend = true;
		} else {
			monthCode += 'class="calendarDay"';
		}

		noClick = false;
		if (calendarMinYear == year && calendarMinMonth == month) {
			if (calendarMinDay > d) {
				monthCode += ' style="cursor:default;background-image:url(\'/images/calNoClick.gif\')"';
				noClick = true;
			}
			noPrevMonth = true;
		} else if (calendarMinYear == year && calendarMinMonth > month) {
			monthCode += ' style="cursor:default;background-image:url(\'/images/calNoClick.gif\')"';
			noClick = true;
			noPrevMonth = true;
		} else if (calendarMinYear > year) {
			monthCode += ' style="cursor:default;background-image:url(\'/images/calNoClick.gif\')"';
			noClick = true;
			noPrevMonth = true;
		}

		if (calendarMaxYear == year && calendarMaxMonth > 0 && calendarMaxMonth == month) {
			if (calendarMaxDay > 0 && calendarMaxDay < d) {
				monthCode += ' style="cursor:default;background-image:url(\'/images/calNoClick.gif\')"';
				noClick = true;
			}
			noNextMonth = true;
		} else if (calendarMaxYear == year && calendarMaxMonth > 0 && calendarMaxMonth < month) {
			monthCode += ' style="cursor:default;background-image:url(\'/images/calNoClick.gif\')"';
			noClick = true;
			noNextMonth = true;
		} else if (calendarMaxYear > 0 && calendarMaxYear < year) {
			monthCode += ' style="cursor:default;background-image:url(\'/images/calNoClick.gif\')"';
			noClick = true;
			noNextMonth = true;
		}

		monthCode += '"';
		if (!noClick) {
			monthCode += ' onclick="calendarSet(' + year + ',' + month + ',' + d + ')" ' +
				'onmouseover="this.className=\'calendarDayHover\'" onmouseout="this.className=\'';
			if (isSelected) { monthCode += 'calendarDaySel'; }
			else if (isWeekend) { monthCode += 'calendarWEDay'; }
			else { monthCode += 'calendarDay'; }
			monthCode += '\'"';
		}
		monthCode += '>' + d + '</td>';

		weekdayCol++;
		if (weekdayCol > 6) {
			monthCode += '</tr>';
			weekdayCol = 0;
		}
	}

	if (weekdayCol > 0) {
		while (weekdayCol <= 6) {
			monthCode += '<td class="calendarDay"';
			if (weekdayCol == 6) { monthCode += ' style="border-right:0 none"'; }
			monthCode += '>&nbsp;</td>';
			weekdayCol++;
		}
		monthCode += '</tr>';
	}

	today = new Date();
	monthCode += '<tr><td colspan="7" class="uiTextSm" align="center" ' +
		'style="height:20px;background-color:#EAEAEA;cursor:pointer" onclick="' +
		'calendarToday();calendarSet(' + today.getFullYear() + ',' + today.getMonth() + ',' + today.getDate() +
		')" onmouseover="this.style.color=\'#CE3974\'" onmouseout="this.style.color=\'#707070\'">Azi este ' +
		today.getDate() + ' ' + month_names[today.getMonth()] + ' ' + today.getFullYear() + '</td></tr></tbody></table>';
	today = null;
	calendarMonWrap.innerHTML = monthCode;

	var monthNav = $('calendar-prev');
	if (monthNav != null) {
		if (noPrevMonth) { monthNav.src = '/images/btnTPrevDis.png'; }
		else { monthNav.src = '/images/btnTPrev.png'; }
	}
	monthNav = $('calendar-next');
	if (monthNav != null) {
		if (noNextMonth) { monthNav.src = '/images/btnTNextDis.png'; }
		else { monthNav.src = '/images/btnTNext.png'; }
	}
	var monthCalendarTable = $('month-calendar-table');
	if (monthCalendarTable != null) {
		if (monthCalendarTable.offsetHeight > 0) {
			var listCtrl = $('page-calendar-wrap');
			var newH = 28 + monthCalendarTable.offsetHeight;
			if (listCtrl != null) { listCtrl.style.height = newH + 'px'; }
		}
	}
}

function calendarPrev() {
	var month = calendarDate.getMonth();
	var year = calendarDate.getFullYear();
	month = month - 1;
	if (month < 0) {
		month = 11;
		year = year - 1;
	}
	if (year == calendarMinYear && month < calendarMinMonth) { return; }
	if (year < calendarMinYear) { return; }
	var day = getDaysInMonth(month, year);
	calendarDate.setFullYear(year, month, day);
	drawCalendar(calendarDate);
}

function calendarNext() {
	var month = calendarDate.getMonth();
	var year = calendarDate.getFullYear();
	month = month + 1;
	if (month > 11) {
		month = 0;
		year = year + 1;
	}
	if (calendarMaxYear > 0 && year == calendarMaxYear &&
		calendarMaxMonth > 0 && month > calendarMaxMonth) { return; }
	if (calendarMaxYear > 0 && year > calendarMaxYear) { return; }
	var day = 1;
	calendarDate.setFullYear(year, month, day);
	drawCalendar(calendarDate);
}

function calendarSet(year, month, day) {
	if (calendarCallback) { calendarCallback(year, month, day); }
	calendarDate.setFullYear(year, month, day);
	doHideDrop('page-calendar-wrap');
}

function calendarToday() {
	calendarDate = null;
	calendarDate = new Date();
	drawCalendar(calendarDate);
}

function setMaxCalendar(maxYear, maxMonth, maxDay) {
	calendarMaxYear = maxYear;
	calendarMaxMonth = maxMonth;
	calendarMaxDay = maxDay;
}
