/************************************************************************************************************
JS Calendar
Copyright (C) September 2006  DTHMLGoodies.com, Alf Magne Kalleland

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

Dhtmlgoodies.com., hereby disclaims all copyright interest in this script
written by Alf Magne Kalleland.

Alf Magne Kalleland, 2006
Owner of DHTMLgoodies.com

************************************************************************************************************/
var doc = document;
var block = 'block';
var none = 'none';
var visible = 'visible';
var FALSE = false;
var TRUE = true;
var nav = navigator.userAgent;

var turnOffYearSpan = FALSE;
var weekStartsOnSunday = FALSE;
var showWeekNumber = TRUE;

var languageCode = 'ge';

var calendar_display_time = TRUE;

var todayStringFormat = '[todayString] [UCFdayString]. [day]. [monthString] [year]';
var pathToImages = '/vweb/img/calendar/';

var speedOfSelectBoxSliding = 200;
var intervalSelectBox_minutes = 5;
var calendar_offsetTop = 0;
var calendar_offsetLeft = 0;
var calendarDiv = FALSE;

var MSIE = FALSE;
var Opera = FALSE;
if(nav.indexOf('MSIE')>=0 && nav.indexOf('Opera')<0)MSIE=TRUE;
if(nav.indexOf('Opera')>=0)Opera=TRUE;


switch(languageCode){
	case "en":	/* English */
		var monthArray = ['January','February','March','April','May','June','July','August','September','October','November','December'];
		var monthArrayShort = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
		var dayArray = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'];
		var weekString = 'Week';
		var todayString = '';
		break;
	case "ge":	/* German */
		var monthArray = ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'];
		var monthArrayShort = ['Jan','Feb','Mar','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'];
		var dayArray = ['Mo','Di','Mi','Do','Fr','Sa','So'];
		var weekString = 'Woche';
		var todayString = 'Heute';
		break;
}

if (weekStartsOnSunday){
	var tempDayName = dayArray[6];
	for(var theIx = 6; theIx > 0; theIx--) {
		dayArray[theIx] = dayArray[theIx-1];
	}
	dayArray[0] = tempDayName;
}

var daysInMonthArray = [31,28,31,30,31,30,31,31,30,31,30,31];
var currentMonth;
var currentYear;
var currentHour;
var currentMinute;
var calendarContentDiv;
var returnDateTo;
var returnFormat;
var activeSelectBoxMonth;
var activeSelectBoxYear;
var activeSelectBoxHour;
var activeSelectBoxMinute;

var iframeObj = FALSE;
var iframeObj2 =FALSE;
function EIS_FIX_EI1(where2fixit){
	if(!iframeObj2)return;
	iframeObj2.style.display = block;
	iframeObj2.style.height =getElem(where2fixit).offsetHeight+1;
	iframeObj2.style.width=getElem(where2fixit).offsetWidth;
	iframeObj2.style.left=getleftPos(getElem(where2fixit))+1-calendar_offsetLeft;
	iframeObj2.style.top=getTopPos(getElem(where2fixit))-getElem(where2fixit).offsetHeight-calendar_offsetTop;
}

function EIS_Hide_Frame(){if(iframeObj2)iframeObj2.style.display = none;}

var returnDateToYear;
var returnDateToMonth;
var returnDateToDay;
var returnDateToHour;
var returnDateToMinute;

var inputYear;
var inputMonth;
var inputDay;
var inputHour;
var inputMinute;
var calendarDisplayTime = FALSE;

var selectBoxHighlightColor = '#D60808'; // Highlight color of select boxes
var selectBoxRolloverBgColor = '#f1f1f1'; // Background color on drop down lists(rollover)

var selectBoxMovementInProgress = FALSE;
var activeSelectBox = FALSE;

function cancelCalendarEvent(){
	return FALSE;
}
function isLeapYear(inputYear){
	if(inputYear%400==0||(inputYear%4==0&&inputYear%100!=0)) return TRUE;
	return FALSE;

}
var activeSelectBoxMonth = FALSE;
var activeSelectBoxDirection = FALSE;

function highlightMonthYear(){
	var t = this;

	if(activeSelectBoxMonth)activeSelectBoxMonth.className='';
	activeSelectBox = t;


	if(t.className=='monthYearActive'){
		t.className='';
	}else{
		t.className = 'monthYearActive';
		activeSelectBoxMonth = t;
	}

	if(t.innerHTML.indexOf('-')>=0 || t.innerHTML.indexOf('+')>=0){
		if(t.className=='monthYearActive'){
			selectBoxMovementInProgress = TRUE;
		}else{
			selectBoxMovementInProgress = FALSE;
		}
		if(t.innerHTML.indexOf('-')>=0){activeSelectBoxDirection = -1;}else{activeSelectBoxDirection = 1;}
	}else{
		selectBoxMovementInProgress = FALSE;
	}

}

function showMonthDropDown(){
	var fnDD = getElem('monthDropDown');
	if(fnDD.style.display==block){
		fnDD.style.display=none;
		EIS_Hide_Frame();
	}else{
		fnDD.style.display=block;
		getElem('yearDropDown').style.display=none;
		getElem('hourDropDown').style.display=none;
		getElem('minuteDropDown').style.display=none;
		if(MSIE){EIS_FIX_EI1('monthDropDown')}
	}
}

function showYearDropDown(){
	var fnDD = getElem('yearDropDown');
	if(fnDD.style.display==block){
		fnDD.style.display=none;
		EIS_Hide_Frame();
	}else{
		fnDD.style.display=block;
		getElem('monthDropDown').style.display=none;
		getElem('hourDropDown').style.display=none;
		getElem('minuteDropDown').style.display=none;
		if(MSIE){EIS_FIX_EI1('yearDropDown')}
	}

}
function showHourDropDown(){
	var fnDD = getElem('hourDropDown');
	if(fnDD.style.display==block){
		fnDD.style.display=none;
		EIS_Hide_Frame();
	}else{
		fnDD.style.display=block;
		getElem('monthDropDown').style.display=none;
		getElem('yearDropDown').style.display=none;
		getElem('minuteDropDown').style.display=none;
		if(MSIE){EIS_FIX_EI1('hourDropDown')}
	}

}
function showMinuteDropDown(){
	var fnDD = getElem('minuteDropDown');
	if(fnDD.style.display==block){
		fnDD.style.display=none;
		EIS_Hide_Frame();
	}else{
		fnDD.style.display=block;
		getElem('monthDropDown').style.display=none;
		getElem('yearDropDown').style.display=none;
		getElem('hourDropDown').style.display=none;
		if(MSIE){EIS_FIX_EI1('minuteDropDown')}
	}

}

function selectMonth(){
	getElem('calendar_month_txt').innerHTML = this.innerHTML
	currentMonth = this.id.replace(/[^\d]/g,'');

	getElem('monthDropDown').style.display=none;
	EIS_Hide_Frame();
	for(var no=0;no<monthArray.length;no++){
		getElem('monthDiv_'+no).style.color='';
	}
	this.style.color = selectBoxHighlightColor;
	activeSelectBoxMonth = this;
	writeCalendarContent();
}

function selectHour(){
	getElem('calendar_hour_txt').innerHTML = this.innerHTML
	currentHour = this.innerHTML.replace(/[^\d]/g,'');
	getElem('hourDropDown').style.display=none;
	EIS_Hide_Frame();
	if(activeSelectBoxHour){
		activeSelectBoxHour.style.color='';
	}
	activeSelectBoxHour=this;
	this.style.color = selectBoxHighlightColor;
}

function selectMinute(){
	getElem('calendar_minute_txt').innerHTML = this.innerHTML
	currentMinute = this.innerHTML.replace(/[^\d]/g,'');
	getElem('minuteDropDown').style.display=none;
	EIS_Hide_Frame();
	if(activeSelectBoxMinute){
		activeSelectBoxMinute.style.color='';
	}
	activeSelectBoxMinute=this;
	this.style.color = selectBoxHighlightColor;
}


function selectYear(){
	var t = this;
	getElem('calendar_year_txt').innerHTML = t.innerHTML
	currentYear = t.innerHTML.replace(/[^\d]/g,'');
	getElem('yearDropDown').style.display=none;
	EIS_Hide_Frame();
	if(activeSelectBoxYear){
		activeSelectBoxYear.style.color='';
	}
	activeSelectBoxYear=t;
	t.style.color = selectBoxHighlightColor;
	writeCalendarContent();

}

function switchMonth(){
	if(this.src.indexOf('left')>=0){
		currentMonth=currentMonth-1;;
		if(currentMonth<0){
			currentMonth=11;
			currentYear=currentYear-1;
		}
	}else{
		currentMonth=currentMonth+1;;
		if(currentMonth>11){
			currentMonth=0;
			currentYear=currentYear/1+1;
		}
	}
	writeCalendarContent();
}

function createMonthDiv(){
	var div = doc.createElement('DIV');
	div.className='monthYearPicker';
	div.id = 'monthPicker';

	for(var no=0;no<monthArray.length;no++){
		var subDiv = doc.createElement('DIV');
		subDiv.innerHTML = monthArray[no];
		subDiv.onmouseover = highlightMonthYear;
		subDiv.onmouseout = highlightMonthYear;
		subDiv.onclick = selectMonth;
		subDiv.id = 'monthDiv_' + no;
		subDiv.style.width = '56px';
		subDiv.onselectstart = cancelCalendarEvent;
		div.appendChild(subDiv);
		if(currentMonth && currentMonth==no){
			subDiv.style.color = selectBoxHighlightColor;
			activeSelectBoxMonth = subDiv;
		}
	}
	return div;
}

function changeSelectBoxYear(e,inputObj){
	if(!inputObj)inputObj =this;
	var yearItems = inputObj.parentNode.getElementsByTagName('DIV');
	if(inputObj.innerHTML.indexOf('-')>=0){
		var startYear = yearItems[1].innerHTML/1 -1;
		if(activeSelectBoxYear){
			activeSelectBoxYear.style.color='';
		}
	}else{
		var startYear = yearItems[1].innerHTML/1 +1;
		if(activeSelectBoxYear){
			activeSelectBoxYear.style.color='';

		}
	}

	for(var no=1;no<yearItems.length-1;no++){
		yearItems[no].innerHTML = startYear+no-1;
		yearItems[no].id = 'yearDiv' + (startYear/1+no/1-1);

	}
	if(activeSelectBoxYear){
		activeSelectBoxYear.style.color='';
		if(getElem('yearDiv'+currentYear)){
			activeSelectBoxYear = getElem('yearDiv'+currentYear);
			activeSelectBoxYear.style.color=selectBoxHighlightColor;;
		}
	}
}

function changeSelectBoxHour(e,inputObj){
	if(!inputObj)inputObj = this;

	var hourItems = inputObj.parentNode.getElementsByTagName('DIV');
	if(inputObj.innerHTML.indexOf('-')>=0){
		var startHour = hourItems[1].innerHTML/1 -1;
		if(startHour<0)startHour=0;
		if(activeSelectBoxHour){
			activeSelectBoxHour.style.color='';
		}
	}else{
		var startHour = hourItems[1].innerHTML/1 +1;
		if(startHour>14)startHour = 14;
		if(activeSelectBoxHour){
			activeSelectBoxHour.style.color='';

		}
	}
	var prefix = '';
	for(var no=1;no<hourItems.length-1;no++){
		if((startHour/1 + no/1) < 11)prefix = '0'; else prefix = '';
		hourItems[no].innerHTML = prefix + (startHour+no-1);

		hourItems[no].id = 'hourDiv' + (startHour/1+no/1-1);

	}
	if(activeSelectBoxHour){
		activeSelectBoxHour.style.color='';
		if(getElem('hourDiv'+currentHour)){
			activeSelectBoxHour = getElem('hourDiv'+currentHour);
			activeSelectBoxHour.style.color=selectBoxHighlightColor;;
		}
	}
}

function updateYearDiv(){
	var yearSpan = 5;
	if (turnOffYearSpan){
		yearSpan = 0;
	}
	var div = getElem('yearDropDown');
	var yearItems = div.getElementsByTagName('DIV');
	for(var no=1;no<yearItems.length-1;no++){
		yearItems[no].innerHTML = currentYear/1 -yearSpan + no;
		if(currentYear==(currentYear/1 -yearSpan + no)){
			yearItems[no].style.color = selectBoxHighlightColor;
			activeSelectBoxYear = yearItems[no];
		}else{
			yearItems[no].style.color = '';
		}
	}
}

function updateMonthDiv(){
	for(no=0;no<12;no++){
		getElem('monthDiv_' + no).style.color = '';
	}
	getElem('monthDiv_' + currentMonth).style.color = selectBoxHighlightColor;
	activeSelectBoxMonth = 	getElem('monthDiv_' + currentMonth);
}


function updateHourDiv(){
	var div = getElem('hourDropDown');
	var hourItems = div.getElementsByTagName('DIV');

	var addHours = 0;
	if((currentHour/1 -6 + 1)<0){
		addHours = 	(currentHour/1 -6 + 1)*-1;
	}
	for(var no=1;no<hourItems.length-1;no++){
		var prefix='';
		if((currentHour/1 -6 + no + addHours) < 10)prefix='0';
		hourItems[no].innerHTML = prefix +  (currentHour/1 -6 + no + addHours);
		if(currentHour==(currentHour/1 -6 + no)){
			hourItems[no].style.color = selectBoxHighlightColor;
			activeSelectBoxHour = hourItems[no];
		}else{
			hourItems[no].style.color = '';
		}
	}
}

function updateMinuteDiv(){
	for(no=0;no<60;no+=intervalSelectBox_minutes){
		var prefix = '';
		if(no<10)prefix = '0';

		getElem('minuteDiv_' + prefix + no).style.color = '';
	}
	if(getElem('minuteDiv_' + currentMinute)){
		getElem('minuteDiv_' + currentMinute).style.color = selectBoxHighlightColor;
		activeSelectBoxMinute = getElem('minuteDiv_' + currentMinute);
	}
}



function createYearDiv(){
	if(!getElem('yearDropDown')){
		var div = doc.createElement('DIV');
		div.className='monthYearPicker';
	}else{
		var div = getElem('yearDropDown');
		var subDivs = div.getElementsByTagName('DIV');
		for(var no=0;no<subDivs.length;no++){
			subDivs[no].parentNode.removeChild(subDivs[no]);
		}
	}

	var d = new Date();
	if(currentYear){
		d.setFullYear(currentYear);
	}

	var startYear = d.getFullYear()/1 - 5;

	var yearSpan = 10;
	if (! turnOffYearSpan){
		var subDiv = doc.createElement('DIV');
		subDiv.innerHTML = '&nbsp;&nbsp;- ';
		subDiv.onclick = changeSelectBoxYear;
		subDiv.onmouseover = highlightMonthYear;
		subDiv.onmouseout = function(){ selectBoxMovementInProgress = FALSE;};
		subDiv.onselectstart = cancelCalendarEvent;
		div.appendChild(subDiv);
	}else{
		startYear = d.getFullYear()/1 - 0;
		yearSpan = 2;
	}

	for(var no=startYear;no<(startYear+yearSpan);no++){
		var subDiv = doc.createElement('DIV');
		subDiv.innerHTML = no;
		subDiv.onmouseover = highlightMonthYear;
		subDiv.onmouseout = highlightMonthYear;
		subDiv.onclick = selectYear;
		subDiv.id = 'yearDiv' + no;
		subDiv.onselectstart = cancelCalendarEvent;
		div.appendChild(subDiv);
		if(currentYear && currentYear==no){
			subDiv.style.color = selectBoxHighlightColor;
			activeSelectBoxYear = subDiv;
		}
	}

	if (! turnOffYearSpan){
		var subDiv = doc.createElement('DIV');
		subDiv.innerHTML = '&nbsp;&nbsp;+ ';
		subDiv.onclick = changeSelectBoxYear;
		subDiv.onmouseover = highlightMonthYear;
		subDiv.onmouseout = function(){ selectBoxMovementInProgress = FALSE;};
		subDiv.onselectstart = cancelCalendarEvent;
		div.appendChild(subDiv);
	}
	return div;
}


function slideCalendarSelectBox(){
	if(selectBoxMovementInProgress){
		if(activeSelectBox.parentNode.id=='hourDropDown'){
			changeSelectBoxHour(FALSE,activeSelectBox);
		}
		if(activeSelectBox.parentNode.id=='yearDropDown'){
			changeSelectBoxYear(FALSE,activeSelectBox);
		}

	}
	setTimeout('slideCalendarSelectBox()',speedOfSelectBoxSliding);
}

function createHourDiv(){
	if(!getElem('hourDropDown')){
		var div = doc.createElement('DIV');
		div.className='monthYearPicker';
	}else{
		var div = getElem('hourDropDown');
		var subDivs = div.getElementsByTagName('DIV');
		for(var no=0;no<subDivs.length;no++){
			subDivs[no].parentNode.removeChild(subDivs[no]);
		}
	}

	if(!currentHour)currentHour=0;
	var startHour = currentHour/1;
	if(startHour>14)startHour=14;

	var subDiv = doc.createElement('DIV');
	subDiv.innerHTML = '&nbsp;&nbsp;- ';
	subDiv.onclick = changeSelectBoxHour;
	subDiv.onmouseover = highlightMonthYear;
	subDiv.onmouseout = function(){ selectBoxMovementInProgress = FALSE;};
	subDiv.onselectstart = cancelCalendarEvent;
	div.appendChild(subDiv);

	for(var no=startHour;no<startHour+10;no++){
		var prefix = '';
		if(no/1<10)prefix='0';
		var subDiv = doc.createElement('DIV');
		subDiv.innerHTML = prefix + no;
		subDiv.onmouseover = highlightMonthYear;
		subDiv.onmouseout = highlightMonthYear;
		subDiv.onclick = selectHour;
		subDiv.id = 'hourDiv' + no;
		subDiv.onselectstart = cancelCalendarEvent;
		div.appendChild(subDiv);
		if(currentYear && currentYear==no){
			subDiv.style.color = selectBoxHighlightColor;
			activeSelectBoxYear = subDiv;
		}
	}
	var subDiv = doc.createElement('DIV');
	subDiv.innerHTML = '&nbsp;&nbsp;+ ';
	subDiv.onclick = changeSelectBoxHour;
	subDiv.onmouseover = highlightMonthYear;
	subDiv.onmouseout = function(){ selectBoxMovementInProgress = FALSE;};
	subDiv.onselectstart = cancelCalendarEvent;
	div.appendChild(subDiv);

	return div;
}

function createMinuteDiv(){
	if(!getElem('minuteDropDown')){
		var div = doc.createElement('DIV');
		div.className='monthYearPicker';
	}else{
		var div = getElem('minuteDropDown');
		var subDivs = div.getElementsByTagName('DIV');
		for(var no=0;no<subDivs.length;no++){
			subDivs[no].parentNode.removeChild(subDivs[no]);
		}
	}
	var startMinute = 0;
	var prefix = '';
	for(var no=startMinute;no<60;no+=intervalSelectBox_minutes){

		if(no<10)prefix='0'; else prefix = '';
		var subDiv = doc.createElement('DIV');
		subDiv.innerHTML = prefix + no;
		subDiv.onmouseover = highlightMonthYear;
		subDiv.onmouseout = highlightMonthYear;
		subDiv.onclick = selectMinute;
		subDiv.id = 'minuteDiv_' + prefix +  no;
		subDiv.onselectstart = cancelCalendarEvent;
		div.appendChild(subDiv);
		if(currentYear && currentYear==no){
			subDiv.style.color = selectBoxHighlightColor;
			activeSelectBoxYear = subDiv;
		}
	}
	return div;
}

function highlightSelect(){
	var t = this;
	if(t.className=='selectBoxTime'){
		t.className = 'selectBoxTimeOver';
		t.getElementsByTagName('IMG')[0].src = pathToImages + 'down_time_over.png';
	}else if(t.className=='selectBoxTimeOver'){
		t.className = 'selectBoxTime';
		t.getElementsByTagName('IMG')[0].src = pathToImages + 'down_time.png';
	}

	if(this.className=='selectBox'){
		this.className = 'selectBoxOver';
		this.getElementsByTagName('IMG')[0].src = pathToImages + 'down_over.png';
	}else if(this.className=='selectBoxOver'){
		this.className = 'selectBox';
		this.getElementsByTagName('IMG')[0].src = pathToImages + 'down.png';
	}
}

function highlightArrow(){
	var fnSrc = this.src;
	if(fnSrc.indexOf('over')>=0){
		if(fnSrc.indexOf('left')>=0)fnSrc = pathToImages + 'left.png';
		if(fnSrc.indexOf('right')>=0)fnSrc = pathToImages + 'right.png';
	}else{
		if(fnSrc.indexOf('left')>=0)fnSrc = pathToImages + 'left_over.png';
		if(fnSrc.indexOf('right')>=0)fnSrc = pathToImages + 'right_over.png';
	}
}

function highlightClose(){
	var fnSrc = this.src;
	if(fnSrc.indexOf('over')>=0){
		fnSrc = pathToImages + 'close.png';
	}else{
		fnSrc = pathToImages + 'close_over.png';
	}
}

function closeCalendar(){
	getElem('yearDropDown').style.display=none;
	getElem('monthDropDown').style.display=none;
	getElem('hourDropDown').style.display=none;
	getElem('minuteDropDown').style.display=none;

	calendarDiv.style.display=none;
	if(iframeObj){
		iframeObj.style.display=none;
		EIS_Hide_Frame();}
	if(activeSelectBoxMonth)activeSelectBoxMonth.className='';
	if(activeSelectBoxYear)activeSelectBoxYear.className='';
}

function writeTopBar(){
	var topBar = doc.createElement('DIV');
	topBar.className = 'topBar';
	topBar.id = 'topBar';
	calendarDiv.appendChild(topBar);

	var leftDiv = doc.createElement('DIV');
	leftDiv.style.marginRight = '1px';
	var img = doc.createElement('IMG');
	img.src = pathToImages + 'left.png';
	img.onmouseover = highlightArrow;
	img.onclick = switchMonth;
	img.onmouseout = highlightArrow;
	leftDiv.appendChild(img);
	topBar.appendChild(leftDiv);
	if(Opera)leftDiv.style.width = '16px';

	var rightDiv = doc.createElement('DIV');
	rightDiv.style.marginRight = '1px';
	var img = doc.createElement('IMG');
	img.src = pathToImages + 'right.png';
	img.onclick = switchMonth;
	img.onmouseover = highlightArrow;
	img.onmouseout = highlightArrow;
	rightDiv.appendChild(img);
	if(Opera)rightDiv.style.width = '16px';
	topBar.appendChild(rightDiv);

	var monthDiv = doc.createElement('DIV');
	monthDiv.id = 'monthSelect';
	monthDiv.onmouseover = highlightSelect;
	monthDiv.onmouseout = highlightSelect;
	monthDiv.onclick = showMonthDropDown;
	var span = doc.createElement('SPAN');
	span.innerHTML = monthArray[currentMonth];
	span.id = 'calendar_month_txt';
	monthDiv.appendChild(span);

	var img = doc.createElement('IMG');
	img.src = pathToImages + 'down.png';
	img.style.position = 'absolute';
	img.style.right = '0';
	monthDiv.appendChild(img);
	monthDiv.className = 'selectBox';
	if(Opera){
		img.style.cssText = 'float:right;position:relative';
		img.style.position = 'relative';
		img.style.styleFloat = 'right';
	}
	topBar.appendChild(monthDiv);

	var monthPicker = createMonthDiv();
	monthPicker.style.left = '37px';
	monthPicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
	monthPicker.style.width ='60px';
	monthPicker.id = 'monthDropDown';

	calendarDiv.appendChild(monthPicker);

	var yearDiv = doc.createElement('DIV');
	yearDiv.onmouseover = highlightSelect;
	yearDiv.onmouseout = highlightSelect;
	yearDiv.onclick = showYearDropDown;
	var span = doc.createElement('SPAN');
	span.innerHTML = currentYear;
	span.id = 'calendar_year_txt';
	yearDiv.appendChild(span);
	topBar.appendChild(yearDiv);

	var img = doc.createElement('IMG');
	img.src = pathToImages + 'down.png';
	yearDiv.appendChild(img);
	yearDiv.className = 'selectBox';

	if(Opera){
		yearDiv.style.width = '50px';
		img.style.cssText = 'float:right';
		img.style.position = 'relative';
		img.style.styleFloat = 'right';
	}

	var yearPicker = createYearDiv();
	yearPicker.style.left = '113px';
	yearPicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
	yearPicker.style.width = '35px';
	yearPicker.id = 'yearDropDown';
	calendarDiv.appendChild(yearPicker);

	var img = doc.createElement('IMG');
	img.src = pathToImages + 'close.png';
	img.style.styleFloat = 'right';
	img.onmouseover = highlightClose;
	img.onmouseout = highlightClose;
	img.onclick = closeCalendar;
	topBar.appendChild(img);
	if(!doc.all){
		img.style.position = 'absolute';
		img.style.right = '2px';
	}
}

function writeCalendarContent(){
	var calendarContentDivExists = TRUE;
	if(!calendarContentDiv){
		calendarContentDiv = doc.createElement('DIV');
		calendarDiv.appendChild(calendarContentDiv);
		calendarContentDivExists = FALSE;
	}
	currentMonth = currentMonth/1;
	var d = new Date();

	d.setFullYear(currentYear);
	d.setDate(1);
	d.setMonth(currentMonth);

	var dayStartOfMonth = d.getDay();
	if (! weekStartsOnSunday){
		if(dayStartOfMonth==0)dayStartOfMonth=7;
		dayStartOfMonth--;
	}

	getElem('calendar_year_txt').innerHTML = currentYear;
	getElem('calendar_month_txt').innerHTML = monthArray[currentMonth];
	getElem('calendar_hour_txt').innerHTML = currentHour/1 > 9 ? currentHour : '0' + currentHour;
	getElem('calendar_minute_txt').innerHTML = currentMinute/1 >9 ? currentMinute : '0' + currentMinute;

	var existingTable = calendarContentDiv.getElementsByTagName('TABLE');
	if(existingTable.length>0){
		calendarContentDiv.removeChild(existingTable[0]);
	}

	var calTable = doc.createElement('TABLE');
	calTable.width = '100%';
	calTable.cellSpacing = '0';
	calendarContentDiv.appendChild(calTable);

	var calTBody = doc.createElement('TBODY');
	calTable.appendChild(calTBody);
	var row = calTBody.insertRow(-1);
	row.className = 'calendar_week_row';
	if (showWeekNumber) {
		var cell = row.insertCell(-1);
		cell.innerHTML = weekString;
		cell.className = 'calendar_week_column';
		cell.style.backgroundColor = selectBoxRolloverBgColor;
	}

	for(var no=0;no<dayArray.length;no++){
		var cell = row.insertCell(-1);
		cell.innerHTML = dayArray[no];
	}

	var row = calTBody.insertRow(-1);

	if(showWeekNumber){
		var cell = row.insertCell(-1);
		cell.className = 'calendar_week_column';
		cell.style.backgroundColor = selectBoxRolloverBgColor;
		var week = getWeek(currentYear,currentMonth,1);
		cell.innerHTML = week;		// Week
	}
	for(var no=0;no<dayStartOfMonth;no++){
		var cell = row.insertCell(-1);
		cell.innerHTML = '&nbsp;';
	}

	var colCounter = dayStartOfMonth;
	var daysInMonth = daysInMonthArray[currentMonth];
	if(daysInMonth==28){
		if(isLeapYear(currentYear))daysInMonth=29;
	}

	for(var no=1;no<=daysInMonth;no++){
		d.setDate(no-1);
		if(colCounter>0 && colCounter%7==0){
			var row = calTBody.insertRow(-1);
			if(showWeekNumber){
				var cell = row.insertCell(-1);
				cell.className = 'calendar_week_column';
				var week = getWeek(currentYear,currentMonth,no);
				cell.innerHTML = week;		// Week
				cell.style.backgroundColor = selectBoxRolloverBgColor;
			}
		}
		var cell = row.insertCell(-1);
		if(currentYear==inputYear && currentMonth == inputMonth && no==inputDay){
			cell.className='activeDay';
		}
		cell.innerHTML = no;
		cell.onclick = pickDate;
		colCounter++;
	}

	if(!doc.all){
		if(calendarContentDiv.offsetHeight)
			getElem('topBar').style.top = calendarContentDiv.offsetHeight + getElem('timeBar').offsetHeight + getElem('topBar').offsetHeight -1 + 'px';
		else{
			getElem('topBar').style.top = '';
			getElem('topBar').style.bottom = '0';
		}

	}

	if(iframeObj){
		if(!calendarContentDivExists)setTimeout('resizeIframe()',350);else setTimeout('resizeIframe()',10);
	}
}

function resizeIframe(){
	iframeObj.style.width = calendarDiv.offsetWidth + 'px';
	iframeObj.style.height = calendarDiv.offsetHeight + 'px' ;
}

function pickTodaysDate(){
	var d = new Date();
	currentMonth = d.getMonth();
	currentYear = d.getFullYear();
	pickDate(FALSE,d.getDate());
}

function pickDate(e,inputDay){
	var month = currentMonth/1 +1;
	if(month<10)month = '0' + month;
	var day;
	if(!inputDay && this)day = this.innerHTML; else day = inputDay;

	if(day/1<10)day = '0' + day;
	if(returnFormat){
		returnFormat = returnFormat.replace('dd',day);
		returnFormat = returnFormat.replace('mm',month);
		returnFormat = returnFormat.replace('yyyy',currentYear);
		returnFormat = returnFormat.replace('hh',currentHour);
		returnFormat = returnFormat.replace('ii',currentMinute);
		returnFormat = returnFormat.replace('d',day/1);
		returnFormat = returnFormat.replace('m',month/1);

		returnDateTo.value = returnFormat;
		try{
			returnDateTo.onchange();
		}catch(e){

		}
	}else{
		for(var no=0;no<returnDateToYear.options.length;no++){
			if(returnDateToYear.options[no].value==currentYear){
				returnDateToYear.selectedIndex=no;
				break;
			}
		}
		for(var no=0;no<returnDateToMonth.options.length;no++){
			if(returnDateToMonth.options[no].value==parseFloat(month)){
				returnDateToMonth.selectedIndex=no;
				break;
			}
		}
		for(var no=0;no<returnDateToDay.options.length;no++){
			if(returnDateToDay.options[no].value==parseFloat(day)){
				returnDateToDay.selectedIndex=no;
				break;
			}
		}
		if(calendarDisplayTime){
			for(var no=0;no<returnDateToHour.options.length;no++){
				if(returnDateToHour.options[no].value==parseFloat(currentHour)){
					returnDateToHour.selectedIndex=no;
					break;
				}
			}
			for(var no=0;no<returnDateToMinute.options.length;no++){
				if(returnDateToMinute.options[no].value==parseFloat(currentMinute)){
					returnDateToMinute.selectedIndex=no;
					break;
				}
			}
		}
	}
	closeCalendar();
}

function getWeek(year,month,day){
	if(! weekStartsOnSunday){
		day = (day/1);
	}else{
		day = (day/1)+1;
	}
	year = year /1;
	month = month/1 + 1;
	var a = Math.floor((14-(month))/12);
	var y = year+4800-a;
	var m = (month)+(12*a)-3;
	var jd = day + Math.floor(((153*m)+2)/5) +
	(365*y) + Math.floor(y/4) - Math.floor(y/100) +
	Math.floor(y/400) - 32045;
	var d4 = (jd+31741-(jd%7))%146097%36524%1461;
	var L = Math.floor(d4/1460);
	var d1 = ((d4-L)%365)+L;
	NumberOfWeek = Math.floor(d1/7) + 1;
	return NumberOfWeek;
}

function writeTimeBar(){
	var timeBar = doc.createElement('DIV');
	timeBar.id = 'timeBar';
	timeBar.className = 'timeBar';

	var subDiv = doc.createElement('DIV');
	subDiv.innerHTML = 'Time:';

	var hourDiv = doc.createElement('DIV');
	hourDiv.onmouseover = highlightSelect;
	hourDiv.onmouseout = highlightSelect;
	hourDiv.onclick = showHourDropDown;
	hourDiv.style.width = '30px';
	var span = doc.createElement('SPAN');
	span.innerHTML = currentHour;
	span.id = 'calendar_hour_txt';
	hourDiv.appendChild(span);
	timeBar.appendChild(hourDiv);

	var img = doc.createElement('IMG');
	img.src = pathToImages + 'down_time.png';
	hourDiv.appendChild(img);
	hourDiv.className = 'selectBoxTime';

	if(Opera){
		hourDiv.style.width = '30px';
		img.style.cssText = 'float:right';
		img.style.position = 'relative';
		img.style.styleFloat = 'right';
	}

	var hourPicker = createHourDiv();
	hourPicker.style.left = '130px';
	//hourPicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
	hourPicker.style.width = '35px';
	hourPicker.id = 'hourDropDown';
	calendarDiv.appendChild(hourPicker);

	var minuteDiv = doc.createElement('DIV');
	minuteDiv.onmouseover = highlightSelect;
	minuteDiv.onmouseout = highlightSelect;
	minuteDiv.onclick = showMinuteDropDown;
	minuteDiv.style.width = '30px';
	var span = doc.createElement('SPAN');
	span.innerHTML = currentMinute;

	span.id = 'calendar_minute_txt';
	minuteDiv.appendChild(span);
	timeBar.appendChild(minuteDiv);

	var img = doc.createElement('IMG');
	img.src = pathToImages + 'down_time.png';
	minuteDiv.appendChild(img);
	minuteDiv.className = 'selectBoxTime';

	if(Opera){
		minuteDiv.style.width = '30px';
		img.style.cssText = 'float:right';
		img.style.position = 'relative';
		img.style.styleFloat = 'right';
	}

	var minutePicker = createMinuteDiv();
	minutePicker.style.left = '167px';
	//minutePicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
	minutePicker.style.width = '35px';
	minutePicker.id = 'minuteDropDown';
	calendarDiv.appendChild(minutePicker);

	return timeBar;
}

function writeBottomBar(){
	var d = new Date();
	var bottomBar = doc.createElement('DIV');

	bottomBar.id = 'bottomBar';

	bottomBar.style.cursor = 'pointer';
	bottomBar.className = 'todaysDate';
	// var todayStringFormat = '[todayString] [dayString] [day] [monthString] [year]';	;;

	var subDiv = doc.createElement('DIV');
	subDiv.onclick = pickTodaysDate;
	subDiv.id = 'todaysDateString';
	subDiv.style.width = (calendarDiv.offsetWidth - 95) + 'px';
	var day = d.getDay();
	if(! weekStartsOnSunday){
		if(day==0){day = 7;}
		day--;
	}

	var bottomString = todayStringFormat;
	bottomString = bottomString.replace('[monthString]',monthArrayShort[d.getMonth()]);
	bottomString = bottomString.replace('[day]',d.getDate());
	bottomString = bottomString.replace('[year]',d.getFullYear());
	bottomString = bottomString.replace('[dayString]',dayArray[day].toLowerCase());
	bottomString = bottomString.replace('[UCFdayString]',dayArray[day]);
	bottomString = bottomString.replace('[todayString]',todayString);

	subDiv.innerHTML = todayString + ': ' + d.getDate() + '. ' + monthArrayShort[d.getMonth()] + ', ' +  d.getFullYear() ;
	subDiv.innerHTML = bottomString ;
	bottomBar.appendChild(subDiv);

	var timeDiv = writeTimeBar();
	bottomBar.appendChild(timeDiv);

	calendarDiv.appendChild(bottomBar);
}

function getTopPos(inputObj){
	var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
	while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
	return returnValue + calendar_offsetTop;
}

function getleftPos(inputObj){
	var returnValue = inputObj.offsetLeft;
	while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
	return returnValue + calendar_offsetLeft;
}

function getRightPos(inputObj, calObj){
	var returnValue = inputObj.offsetLeft;
	while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
	return returnValue + calendar_offsetLeft;
}


function positionCalendar(inputObj){
	calendarDiv.style.left = getRightPos(inputObj, calendarDiv) + 'px';
	calendarDiv.style.top = getTopPos(inputObj) + 'px';
	if(iframeObj){
		iframeObj.style.left = calendarDiv.style.left;
		iframeObj.style.top =  calendarDiv.style.top;
		iframeObj2.style.left = calendarDiv.style.left;
		iframeObj2.style.top =  calendarDiv.style.top;
	}
}

function initCalendar(){
	if(MSIE){
		iframeObj = doc.createElement('IFRAME');
		iframeObj.style.filter = 'alpha(opacity=0)';
		iframeObj.style.position = 'absolute';
		iframeObj.style.border = '0';
		iframeObj.style.backgroundColor = '#f00';
		iframeObj2 = doc.createElement('IFRAME');
		iframeObj2.style.position = 'absolute';
		iframeObj2.style.border = '0';
		iframeObj2.style.height = '1px';
		iframeObj2.style.width = '1px';
		iframeObj2.src = 'blank.html';
		iframeObj.src = 'blank.html';
		doc.body.appendChild(iframeObj2);
		doc.body.appendChild(iframeObj);
	}

	calendarDiv = doc.createElement('DIV');
	calendarDiv.id = 'calendarDiv';
	calendarDiv.style.zIndex = 1000;
	slideCalendarSelectBox();

	doc.body.appendChild(calendarDiv);
	writeBottomBar();
	writeTopBar();



	if(!currentYear){
		var d = new Date();
		currentMonth = d.getMonth();
		currentYear = d.getFullYear();
	}
	writeCalendarContent();
}

function setTimeProperties(){
	if(!calendarDisplayTime){
		getElem('timeBar').style.display=none;
		getElem('timeBar').style.visibility='hidden';
		getElem('todaysDateString').style.width = '100%';
	}else{
		getElem('timeBar').style.display=block;
		getElem('timeBar').style.visibility=visible;
		getElem('hourDropDown').style.top = getElem('calendar_minute_txt').parentNode.offsetHeight + calendarContentDiv.offsetHeight + getElem('topBar').offsetHeight + 'px';
		getElem('minuteDropDown').style.top = getElem('calendar_minute_txt').parentNode.offsetHeight + calendarContentDiv.offsetHeight + getElem('topBar').offsetHeight + 'px';
		getElem('minuteDropDown').style.right = '50px';
		getElem('hourDropDown').style.right = '50px';
		getElem('todaysDateString').style.width = '115px';
	}
}

function calendarSortItems(a,b){return a/1 - b/1;}

function displayCalendar(inputField,format,buttonObj,displayTime,timeInput){
	if(displayTime)calendarDisplayTime=TRUE; else calendarDisplayTime = FALSE;

	if(inputField.value.length>6){
		if(!inputField.value.match(/^[0-9]*?$/gi)){
			var items = inputField.value.split(/[^0-9]/gi);
			var positionArray = new Object();
			positionArray.m = format.indexOf('mm');
			if(positionArray.m==-1)positionArray.m = format.indexOf('m');
			positionArray.d = format.indexOf('dd');
			if(positionArray.d==-1)positionArray.d = format.indexOf('d');
			positionArray.y = format.indexOf('yyyy');
			positionArray.h = format.indexOf('hh');
			positionArray.i = format.indexOf('ii');
			
			this.initialHour = '00';
			this.initialMinute = '00';				
			var elements = ['y','m','d','h','i'];
			var properties = ['currentYear','currentMonth','inputDay','currentHour','currentMinute'];
			var propertyLength = [4,2,2,2,2];
			for(var i=0;i<elements.length;i++) {
				if(positionArray[elements[i]]>=0) {
					window[properties[i]] = inputField.value.substr(positionArray[elements[i]],propertyLength[i])/1;
				}
			}
			currentMonth--;
		}else{
			var monthPos = format.indexOf('mm');
			currentMonth = inputField.value.substr(monthPos,2)/1 -1;
			var yearPos = format.indexOf('yyyy');
			currentYear = inputField.value.substr(yearPos,4);
			var dayPos = format.indexOf('dd');
			tmpDay = inputField.value.substr(dayPos,2);

			var hourPos = format.indexOf('hh');
			if(hourPos>=0){
				tmpHour = inputField.value.substr(hourPos,2);
				currentHour = tmpHour;
				if(currentHour.length==1) currentHour = '0'
			}else{
				currentHour = '00';
			}
			var minutePos = format.indexOf('ii');
			if(minutePos>=0){
				tmpMinute = inputField.value.substr(minutePos,2);
				currentMinute = tmpMinute;
			}else{
				currentMinute = '00';
			}
		}
	}else{
		var d = new Date();
		currentMonth = d.getMonth();
		currentYear = d.getFullYear();
		currentHour = '08';
		currentMinute = '00';
		inputDay = d.getDate()/1;
	}

	inputYear = currentYear;
	inputMonth = currentMonth;


	if(!calendarDiv){
		initCalendar();
	}else{
		if(calendarDiv.style.display==block){
			closeCalendar();
			return FALSE;
		}
		writeCalendarContent();
	}

	returnFormat = format;
	returnDateTo = inputField;
	positionCalendar(buttonObj);
	calendarDiv.style.visibility = visible;
	calendarDiv.style.display = block;
	if(iframeObj){
		iframeObj.style.display = '';
		iframeObj.style.height = '140px';
		iframeObj.style.width = '195px';
				iframeObj2.style.display = '';
		iframeObj2.style.height = '140px';
		iframeObj2.style.width = '195px';
	}

	setTimeProperties();
	updateYearDiv();
	updateMonthDiv();
	updateMinuteDiv();
	updateHourDiv();
}

function displayCalendarSelectBox(yearInput,monthInput,dayInput,hourInput,minuteInput,buttonObj){
	if(!hourInput)calendarDisplayTime=FALSE; else calendarDisplayTime = TRUE;

	currentMonth = monthInput.options[monthInput.selectedIndex].value/1-1;
	currentYear = yearInput.options[yearInput.selectedIndex].value;
	if(hourInput){
		currentHour = hourInput.options[hourInput.selectedIndex].value;
		inputHour = currentHour/1;
	}
	if(minuteInput){
		currentMinute = minuteInput.options[minuteInput.selectedIndex].value;
		inputMinute = currentMinute/1;
	}

	inputYear = yearInput.options[yearInput.selectedIndex].value;
	inputMonth = monthInput.options[monthInput.selectedIndex].value/1 - 1;
	inputDay = dayInput.options[dayInput.selectedIndex].value/1;

	if(!calendarDiv){
		initCalendar();
	}else{
		writeCalendarContent();
	}

	returnDateToYear = yearInput;
	returnDateToMonth = monthInput;
	returnDateToDay = dayInput;
	returnDateToHour = hourInput;
	returnDateToMinute = minuteInput;

	returnFormat = FALSE;
	returnDateTo = FALSE;
	positionCalendar(buttonObj);
	calendarDiv.style.visibility = visible;
	calendarDiv.style.display = block;
	if(iframeObj){
		iframeObj.style.display = '';
		iframeObj.style.height = calendarDiv.offsetHeight + 'px';
		iframeObj.style.width = calendarDiv.offsetWidth + 'px';
		iframeObj2.style.display = '';
		iframeObj2.style.height = calendarDiv.offsetHeight + 'px';
		iframeObj2.style.width = calendarDiv.offsetWidth + 'px'
	}

	setTimeProperties();
	updateYearDiv();
	updateMonthDiv();
	updateHourDiv();
	updateMinuteDiv();
}

function getElem(extEle){
	var fnE = typeof extEle === 'string' ? doc.getElementById(extEle) : extEle;
	return fnE;
}