/* www.dhtmlgoodies.com, Alf Magne Kalleland */

var languageCode = 'en';
var calendar_display_time = true;
var todayStringFormat = '[todayString] [UCFdayString], [day] [monthString] [year]';
var pathToImages = '/Inc/Ext/Date/Images/';	// Relative to your HTML file
var speedOfSelectBoxSliding = 200;
var intervalSelectBox_minutes = 5;
var calendar_offsetTop = 0;		// Offset - calendar placement - You probably have to modify this value if you're not using a strict doctype
var calendar_offsetLeft = 0;	// Offset - calendar placement - You probably have to modify this value if you're not using a strict doctype
var calendarDiv = false;
var MSIE = false;
var Opera = false;
if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')<0)MSIE=true;
if(navigator.userAgent.indexOf('Opera')>=0)Opera=true;
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 dayArray2 = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
var weekString = 'Week';
var todayString = '<b>Today</b>&nbsp;&nbsp;&nbsp;&nbsp;';
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;
//// fix for EI frame problem on time dropdowns 09/30/2006
var iframeObj2 =false;

function __IeFix(where2fixit) {
    if (!iframeObj2) return;
    iframeObj2.style.display = 'block';
    iframeObj2.style.height =document.getElementById(where2fixit).offsetHeight+1;
    iframeObj2.style.width=document.getElementById(where2fixit).offsetWidth;
    iframeObj2.style.left=__GetLeft(document.getElementById(where2fixit))+1;
    iframeObj2.style.top=__GetTop(document.getElementById(where2fixit))-document.getElementById(where2fixit).offsetHeight;
}

function __IeHide() {
    if (iframeObj2) iframeObj2.style.display = 'none';
}
//// fix for EI frame problem on time dropdowns 09/30/2006
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 = '#0c0'; // Highlight color of select boxes
var selectBoxRolloverBgColor = '#ffc'; // Background color on drop down lists(rollover)
var selectBoxMovementInProgress = false;
var activeSelectBox = false;

function __CancelEvent() {
	return false;
}
function IsYearLeap(inputYear) {
	if(inputYear%400==0||(inputYear%4==0&&inputYear%100!=0)) return true;
	return false;	
	
}
var activeSelectBoxMonth = false;
var activeSelectBoxDirection = false;

function SetMonthActive() {
	if (activeSelectBoxMonth) activeSelectBoxMonth.className='';
	activeSelectBox = this;
	if (this.className=='aaa3') {
		this.className='';
	} else {
		this.className = 'aaa3';
		activeSelectBoxMonth = this;
	}
	if (this.innerHTML.indexOf('-')>=0 || this.innerHTML.indexOf('+')>=0) {
		if (this.className=='aaa3') {
			selectBoxMovementInProgress = true;
		} else {
			selectBoxMovementInProgress = false;
        }
		if (this.innerHTML.indexOf('-')>=0) {
            activeSelectBoxDirection = -1;
        } else {
            activeSelectBoxDirection = 1;
        }
	} else {
        selectBoxMovementInProgress = false;
    }
}
function ShowSelectMonth() {
	if (document.getElementById('monthDropDown').style.display=='block') {
		document.getElementById('monthDropDown').style.display='none';
        __IeHide();
	} else {
		document.getElementById('monthDropDown').style.display='block';
		document.getElementById('yearDropDown').style.display='none';
		document.getElementById('hourDropDown').style.display='none';
		document.getElementById('minuteDropDown').style.display='none';
        if (MSIE) __IeFix('monthDropDown');
	}
}
function ShowSelectYear() {
	if(document.getElementById('yearDropDown').style.display=='block'){
		document.getElementById('yearDropDown').style.display='none';
        __IeHide();
	} else {
		document.getElementById('yearDropDown').style.display='block';
		document.getElementById('monthDropDown').style.display='none';
		document.getElementById('hourDropDown').style.display='none';
		document.getElementById('minuteDropDown').style.display='none';
        if (MSIE) __IeFix('yearDropDown');
	}

}
function ShowSelectHour() {
	if(document.getElementById('hourDropDown').style.display=='block'){
		document.getElementById('hourDropDown').style.display='none';
        __IeHide();
	} else {
		document.getElementById('hourDropDown').style.display='block';
		document.getElementById('monthDropDown').style.display='none';
		document.getElementById('yearDropDown').style.display='none';
		document.getElementById('minuteDropDown').style.display='none';
        if (MSIE) __IeFix('hourDropDown');
	}
}
function ShowSelectMinute() {
	if(document.getElementById('minuteDropDown').style.display=='block'){
        document.getElementById('minuteDropDown').style.display='none';
		__IeHide();
	} else {
		document.getElementById('minuteDropDown').style.display='block';	
		document.getElementById('monthDropDown').style.display='none';	
		document.getElementById('yearDropDown').style.display='none';	
		document.getElementById('hourDropDown').style.display='none';	
        if (MSIE) __IeFix('minuteDropDown');
	}
}

function SetMonth() {
	document.getElementById('calendar_month_txt').innerHTML = this.innerHTML
	currentMonth = this.id.replace(/[^\d]/g,'');
	document.getElementById('monthDropDown').style.display='none';
    __IeHide();
	for (var no=0;no<monthArray.length;no++) {
	    document.getElementById('monthDiv_'+no).style.color='';
	}
	//this.style.color = selectBoxHighlightColor;
    this.className = 'aaa2';
	activeSelectBoxMonth = this;
	WriteCalendar();
}

function SetHour() {
	document.getElementById('calendar_hour_txt').innerHTML = this.innerHTML
	currentHour = this.innerHTML.replace(/[^\d]/g,'');
	document.getElementById('hourDropDown').style.display='none';
    __IeHide();
	if (activeSelectBoxHour) activeSelectBoxHour.style.color='';
	activeSelectBoxHour=this;
	//this.style.color = selectBoxHighlightColor;
    this.className = 'aaa2';
}
function SetMinute() {
	document.getElementById('calendar_minute_txt').innerHTML = this.innerHTML
	currentMinute = this.innerHTML.replace(/[^\d]/g,'');
	document.getElementById('minuteDropDown').style.display='none';
    __IeHide();
	if (activeSelectBoxMinute) activeSelectBoxMinute.style.color='';
	activeSelectBoxMinute=this;
	//this.style.color = selectBoxHighlightColor;
    this.className = 'aaa2';
}
function SetYear() {
	document.getElementById('calendar_year_txt').innerHTML = this.innerHTML
	currentYear = this.innerHTML.replace(/[^\d]/g,'');
	document.getElementById('yearDropDown').style.display='none';
    __IeHide();
	if (activeSelectBoxYear) activeSelectBoxYear.style.color='';
	activeSelectBoxYear=this;
	//this.style.color = selectBoxHighlightColor;
    this.className = 'aaa2';
	WriteCalendar();
}
function ChangeMonth() {
	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;
		}
	}
	WriteCalendar();
}
function CreateMonth() {
	var div = document.createElement('DIV');
    div.className='monthPicker';
    div.id = 'monthPicker';
	for (var no=0; no<monthArray.length; no++) {
		var subDiv = document.createElement('DIV');
		subDiv.innerHTML = monthArray[no];
		subDiv.onmouseover = SetMonthActive;
		subDiv.onmouseout = SetMonthActive;
		subDiv.onclick = SetMonth;
		subDiv.id = 'monthDiv_' + no;
		subDiv.style.width = '70px';
        subDiv.className = 'aaa';
		subDiv.onselectstart = __CancelEvent;
		div.appendChild(subDiv);
		if(currentMonth && currentMonth==no){
	        //subDiv.style.color = selectBoxHighlightColor;
            subDiv.className = 'aaa2';
			activeSelectBoxMonth = subDiv;
		}				
	}
	return div;
}
function ChangeYear(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(document.getElementById('yearDiv'+currentYear)){
			activeSelectBoxYear = document.getElementById('yearDiv'+currentYear);
			//activeSelectBoxYear.style.color=selectBoxHighlightColor;
			activeSelectBoxYear.className = 'aaa2';
		}
	}
}
function ChangeHour(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(document.getElementById('hourDiv'+currentHour)){
			activeSelectBoxHour = document.getElementById('hourDiv'+currentHour);
			//activeSelectBoxHour.style.color=selectBoxHighlightColor;
			activeSelectBoxHour.className = 'aaa2';
		}
	}
}
function UpdateYear() {
    var div = document.getElementById('yearDropDown');
	var yearItems = div.getElementsByTagName('DIV');
	for (var no=1;no<yearItems.length-1;no++) {
		yearItems[no].innerHTML = currentYear/1 -6 + no;	
		if (currentYear==(currentYear/1 -6 + no)) {
			//yearItems[no].style.color = selectBoxHighlightColor;
			yearItems[no].className = 'aaa2';
			activeSelectBoxYear = yearItems[no];
		} else {
			yearItems[no].style.color = '';
		}
	}		
}
function UpdateMonth() {
	for (no=0;no<12;no++) {
		document.getElementById('monthDiv_' + no).style.color = '';
	}
    //document.getElementById('monthDiv_' + currentMonth).style.color = selectBoxHighlightColor;
	document.getElementById('monthDiv_' + currentMonth).className = 'aaa2';
	activeSelectBoxMonth = 	document.getElementById('monthDiv_' + currentMonth);
}
function UpdateHour() {
	var div = document.getElementById('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;
			hourItems[no].className = 'aaa2';
			activeSelectBoxHour = hourItems[no];
		} else {
			hourItems[no].style.color = '';
		}
	}
}
function UpdateMinute() {
	for (no=0;no<60;no+=intervalSelectBox_minutes) {
		var prefix = '';
		if(no<10)prefix = '0';
		document.getElementById('minuteDiv_' + prefix + no).style.color = '';
	}
	if (document.getElementById('minuteDiv_' + currentMinute)) {
		//document.getElementById('minuteDiv_' + currentMinute).style.color = selectBoxHighlightColor;
		document.getElementById('minuteDiv_' + currentMinute).className = 'aaa2';
		activeSelectBoxMinute = document.getElementById('minuteDiv_' + currentMinute);
	}
}
function CreateYear() {
	if (!document.getElementById('yearDropDown')) {
		var div = document.createElement('DIV');
		div.className='yearPicker';
	} else {
		var div = document.getElementById('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 subDiv = document.createElement('DIV');
	subDiv.innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;&nbsp;';
	//subDiv.innerHTML = '&nbsp;Less&nbsp;';
	subDiv.onclick = ChangeYear;
	subDiv.onmouseover = SetMonthActive;
	subDiv.onmouseout = function(){
        selectBoxMovementInProgress = false;
    };
	subDiv.onselectstart = __CancelEvent;
	div.appendChild(subDiv);
	for (var no=startYear;no<(startYear+10);no++) {
		var subDiv = document.createElement('DIV');
		subDiv.innerHTML = no;
		subDiv.onmouseover = SetMonthActive;
		subDiv.onmouseout = SetMonthActive;
		subDiv.onclick = SetYear;
		subDiv.id = 'yearDiv' + no;
		subDiv.onselectstart = __CancelEvent;
		div.appendChild(subDiv);
		if (currentYear && currentYear==no) {
			//subDiv.style.color = selectBoxHighlightColor;
			subDiv.className = 'aaa2';
			activeSelectBoxYear = subDiv;
		}
	}
	var subDiv = document.createElement('DIV');
	subDiv.innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;+&nbsp;&nbsp;&nbsp;&nbsp;';
	//subDiv.innerHTML = '&nbsp;More&nbsp;';
	subDiv.onclick = ChangeYear;
	subDiv.onmouseover = SetMonthActive;
	subDiv.onmouseout = function(){
        selectBoxMovementInProgress = false;
    };
    subDiv.onselectstart = __CancelEvent;
	div.appendChild(subDiv);		
	return div;
}
function slideCalendarSelectBox() {
	if (selectBoxMovementInProgress) {
		if (activeSelectBox.parentNode.id=='hourDropDown') ChangeHour(false, activeSelectBox);
		if (activeSelectBox.parentNode.id=='yearDropDown') ChangeYear(false, activeSelectBox);
	}
	setTimeout('slideCalendarSelectBox()',speedOfSelectBoxSliding);
}
function CreateHour() {
	if (!document.getElementById('hourDropDown')) {
		var div = document.createElement('DIV');
		div.className='yearPicker';
	} else {
		var div = document.getElementById('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 = document.createElement('DIV');
	subDiv.innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;&nbsp;';
	subDiv.onclick = ChangeHour;
	subDiv.onmouseover = SetMonthActive;
	subDiv.onmouseout = function(){ selectBoxMovementInProgress = false;};
	subDiv.onselectstart = __CancelEvent;
	div.appendChild(subDiv);
	for (var no=startHour;no<startHour+10;no++) {
		var prefix = '';
		if(no/1<10)prefix='0';
		var subDiv = document.createElement('DIV');
		subDiv.innerHTML = prefix + no;
		subDiv.onmouseover = SetMonthActive;
		subDiv.onmouseout = SetMonthActive;
		subDiv.onclick = SetHour;
		subDiv.id = 'hourDiv' + no;
		subDiv.onselectstart = __CancelEvent;
		div.appendChild(subDiv);
		if(currentYear && currentYear==no){
			//subDiv.style.color = selectBoxHighlightColor;
			subDiv.className = 'aaa2';
			activeSelectBoxYear = subDiv;
		}
	}
	var subDiv = document.createElement('DIV');
	subDiv.innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;+&nbsp;&nbsp;&nbsp;&nbsp;';
	subDiv.onclick = ChangeHour;
	subDiv.onmouseover = SetMonthActive;
	subDiv.onmouseout = function(){ selectBoxMovementInProgress = false;};
	subDiv.onselectstart = __CancelEvent;
	div.appendChild(subDiv);
	return div;
}
function CreateMinute() {
	if (!document.getElementById('minuteDropDown')) {
		var div = document.createElement('DIV');
		div.className='yearPicker';
	} else {
		var div = document.getElementById('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 = document.createElement('DIV');
		subDiv.innerHTML = prefix + no;
		subDiv.onmouseover = SetMonthActive;
		subDiv.onmouseout = SetMonthActive;
		subDiv.onclick = SetMinute;
		subDiv.id = 'minuteDiv_' + prefix +  no;
		subDiv.onselectstart = __CancelEvent;
		div.appendChild(subDiv);
        if (currentYear && currentYear==no) {
			//subDiv.style.color = selectBoxHighlightColor;
			subDiv.className = 'aaa2';
			activeSelectBoxYear = subDiv;
		}
	}
	return div;
}
function SetActive() {
	if (this.className == 'selectBoxTime') {
		this.className = 'selectBoxTimeOver';
		this.getElementsByTagName('IMG')[0].src = pathToImages + 'down_time_over.gif';
	} else if (this.className == 'selectBoxTimeOver') {
		this.className = 'selectBoxTime';
		this.getElementsByTagName('IMG')[0].src = pathToImages + 'down_time2.gif';
	}
	if (this.className == 'selectBox') {
		this.className = 'selectBoxOver';
		//this.getElementsByTagName('IMG')[0].src = pathToImages + 'down_over.gif';
	} else if (this.className=='selectBoxOver') {
		this.className = 'selectBox';
		//this.getElementsByTagName('IMG')[0].src = pathToImages + 'down.gif';
	}
}
function HideCalendar(){
	document.getElementById('yearDropDown').style.display='none';
	document.getElementById('monthDropDown').style.display='none';
	document.getElementById('hourDropDown').style.display='none';
	document.getElementById('minuteDropDown').style.display='none';
	calendarDiv.style.display='none';
	if (iframeObj) {
        iframeObj.style.display='none';
        __IeHide();
    }
	if (activeSelectBoxMonth) activeSelectBoxMonth.className='';
	if (activeSelectBoxYear)  activeSelectBoxYear.className='';
}
function WriteTop() {
    var topBar = document.createElement('DIV');
	topBar.className = 'topBar';
	topBar.id = 'topBar';
	calendarDiv.appendChild(topBar);
	// Left arrow
	var leftDiv = document.createElement('DIV');
	leftDiv.style.marginRight = '1px';
	var img = document.createElement('IMG');
	img.src = pathToImages + 'left.gif';
	//img.onmouseover = highlightArrow;
	//img.onmouseout = highlightArrow;
	img.onclick = ChangeMonth;
	leftDiv.appendChild(img);
	topBar.appendChild(leftDiv);
	if (Opera) leftDiv.style.width = '16px';
	// Right arrow
	var rightDiv = document.createElement('DIV');
	rightDiv.style.marginRight = '1px';
	var img = document.createElement('IMG');
	img.src = pathToImages + 'right.gif';
	img.onclick = ChangeMonth;
	//img.onmouseover = highlightArrow;
	//img.onmouseout = highlightArrow;
	rightDiv.appendChild(img);
	if (Opera) rightDiv.style.width = '16px';
	topBar.appendChild(rightDiv);
	// Month selector
	var monthDiv = document.createElement('DIV');
	monthDiv.id = 'monthSelect';
	monthDiv.onmouseover = SetActive;
	monthDiv.onmouseout = SetActive;
	monthDiv.onclick = ShowSelectMonth;
	var span = document.createElement('SPAN');
	span.innerHTML = monthArray[currentMonth];
	span.id = 'calendar_month_txt';
	monthDiv.appendChild(span);

	var img = document.createElement('IMG');
	img.src = pathToImages + 'down.gif';
	img.style.position = 'absolute';
	img.style.right = '0px';
	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 = CreateMonth();
	monthPicker.style.left = '37px';
	monthPicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
	monthPicker.style.width ='60px';
	monthPicker.id = 'monthDropDown';
	calendarDiv.appendChild(monthPicker);
	// Year selector
	var yearDiv = document.createElement('DIV');
	yearDiv.onmouseover = SetActive;
	yearDiv.onmouseout = SetActive;
	yearDiv.onclick = ShowSelectYear;
	var span = document.createElement('SPAN');		
	span.innerHTML = currentYear;
	span.id = 'calendar_year_txt';
	yearDiv.appendChild(span);
	topBar.appendChild(yearDiv);
	
	var img = document.createElement('IMG');
	img.src = pathToImages + 'down.gif';
	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 = CreateYear();
	yearPicker.style.left = '113px';
	yearPicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
	yearPicker.style.width = '60px';
	yearPicker.id = 'yearDropDown';
	calendarDiv.appendChild(yearPicker);

    var img = document.createElement('IMG');
	img.src = pathToImages + 'close_over.gif';
	img.style.styleFloat = 'right';
	//img.onmouseover = highlightClose;
	//img.onmouseout = highlightClose;
	img.onclick = HideCalendar;
	topBar.appendChild(img);
	if (!document.all) {
		img.style.position = 'absolute';
		img.style.right = '30px';
		img.style.top = '2px';
	}
}
function WriteCalendar() {
	var calendarContentDivExists = true;
	if (!calendarContentDiv) {
		calendarContentDiv = document.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 (dayStartOfMonth==0) dayStartOfMonth=7;
	dayStartOfMonth--;

	document.getElementById('calendar_year_txt').innerHTML = currentYear;
	document.getElementById('calendar_month_txt').innerHTML = monthArray[currentMonth];
	document.getElementById('calendar_hour_txt').innerHTML = currentHour;
	document.getElementById('calendar_minute_txt').innerHTML = currentMinute;
	
	var existingTable = calendarContentDiv.getElementsByTagName('TABLE');
	if (existingTable.length>0) calendarContentDiv.removeChild(existingTable[0]);

	var calTable = document.createElement('TABLE');
	calTable.cellSpacing = '0';
    calTable.cellPadding = '0';
	calendarContentDiv.appendChild(calTable);
	var calTBody = document.createElement('TBODY');
	calTable.appendChild(calTBody);

    var row = calTBody.insertRow(-1);
	var cell = row.insertCell(-1);
	cell.innerHTML = weekString;
	//cell.style.backgroundColor = selectBoxRolloverBgColor;
    cell.className = 'week2';

	for (var no=0; no<dayArray.length; no++) {
		var cell = row.insertCell(-1);
		cell.innerHTML = dayArray[no];
	}
	
	var row = calTBody.insertRow(-1);
	var cell = row.insertCell(-1);
	//cell.style.backgroundColor = selectBoxRolloverBgColor;
    cell.className = 'week2';
	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 (IsYearLeap(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);
			var cell = row.insertCell(-1);
			var week = __GetWeek(currentYear,currentMonth,no);
			cell.innerHTML = week;		// Week
			//cell.style.backgroundColor = selectBoxRolloverBgColor;
            cell.className = 'week2';
		}
		var cell = row.insertCell(-1);
		if (currentYear==inputYear && currentMonth == inputMonth && no==inputDay) cell.className='activeDay';
        cell.innerHTML = no;
		cell.onclick = SelectDate;
		colCounter++;
	}
	if (!document.all) {
		if (calendarContentDiv.offsetHeight) {
			document.getElementById('topBar').style.top = calendarContentDiv.offsetHeight + document.getElementById('timeBar').offsetHeight + document.getElementById('topBar').offsetHeight -1 + 'px';
		} else {
			document.getElementById('topBar').style.top = '';
			document.getElementById('topBar').style.bottom = '0px';
		}
	}
	if (iframeObj) {
		if (!calendarContentDivExists)
            setTimeout('__ResizeFrame()', 350);
        else
            setTimeout('__ResizeFrame()', 10);
	}
}
function __ResizeFrame() {
	iframeObj.style.width = calendarDiv.offsetWidth + 'px';
	iframeObj.style.height = calendarDiv.offsetHeight + 'px' ;
}
function SelectToday() {
	var d = new Date();
	currentMonth = d.getMonth();
	currentYear = d.getFullYear();
	SelectDate(false,d.getDate());
}
function SelectDate(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('d',day);
		returnFormat = returnFormat.replace('m',month);
		returnFormat = returnFormat.replace('Y',currentYear);
		returnFormat = returnFormat.replace('H',currentHour);
		returnFormat = returnFormat.replace('i',currentMinute);
		returnFormat = returnFormat.replace('d',day/1);
		returnFormat = returnFormat.replace('m',month/1);
		returnDateTo.value = returnFormat;
	} 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==month) {
				returnDateToMonth.selectedIndex=no;
				break;
			}				
		}
		for (var no=0;no<returnDateToDay.options.length;no++) {
			if (returnDateToDay.options[no].value==day) {
				returnDateToDay.selectedIndex=no;
				break;
			}				
		}
		
		if (calendarDisplayTime) {
			for (var no=0;no<returnDateToHour.options.length;no++) {
				if (returnDateToHour.options[no].value==currentHour) {
					returnDateToHour.selectedIndex=no;
					break;
				}				
			}			
			for (var no=0;no<returnDateToMinute.options.length;no++) {
				if (returnDateToMinute.options[no].value==currentMinute) {
					returnDateToMinute.selectedIndex=no;
					break;
				}
			}
		}
	}
	HideCalendar();
}
function __GetWeek(year,month,day) {
	day = day/1;
	year = year /1;
    month = month/1 + 1; //use 1-12
    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 WriteTime() {
	var timeBar = document.createElement('DIV');
	timeBar.id = 'timeBar';
	timeBar.className = 'timeBar';
	var subDiv = document.createElement('DIV');
	subDiv.innerHTML = 'Time:';

	var hourDiv = document.createElement('DIV');
	hourDiv.onmouseover = SetActive;
	hourDiv.onmouseout = SetActive;
	hourDiv.onclick = ShowSelectHour;
	hourDiv.style.width = '30px';
	var span = document.createElement('SPAN');		
	span.innerHTML = currentHour;
	span.id = 'calendar_hour_txt';
	hourDiv.appendChild(span);
	timeBar.appendChild(hourDiv);
	
	var img = document.createElement('IMG');
	img.src = pathToImages + 'down_time.gif';
	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 = CreateHour();
	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 = document.createElement('DIV');
	minuteDiv.onmouseover = SetActive;
	minuteDiv.onmouseout = SetActive;
	minuteDiv.onclick = ShowSelectMinute;
	minuteDiv.style.width = '30px';
	var span = document.createElement('SPAN');
	span.innerHTML = currentMinute;

	span.id = 'calendar_minute_txt';
	minuteDiv.appendChild(span);
	timeBar.appendChild(minuteDiv);

	var img = document.createElement('IMG');
	img.src = pathToImages + 'down_time.gif';
	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 = CreateMinute();
	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 CreateBottom() {
	var d = new Date();
	var bottomBar = document.createElement('DIV');
	bottomBar.id = 'bottomBar';
	bottomBar.style.cursor = 'pointer';
	bottomBar.className = 'todaysDate';

	var subDiv = document.createElement('DIV');
	subDiv.onclick = SelectToday;
	subDiv.id = 'todaysDateString';
	subDiv.style.width = (calendarDiv.offsetWidth - 95) + 'px';
	var day = d.getDay();
	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('[UCFdayString]',dayArray2[day]);
	bottomString = bottomString.replace('[todayString]',todayString);

	subDiv.innerHTML = todayString + ': ' + d.getDate() + '. ' + monthArrayShort[d.getMonth()] + ', ' +  d.getFullYear() ;
	subDiv.innerHTML = bottomString ;
	bottomBar.appendChild(subDiv);

	var timeDiv = WriteTime();
	bottomBar.appendChild(timeDiv);
	calendarDiv.appendChild(bottomBar);
}
function __GetTop(inputObj) {
    var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
    while ((inputObj = inputObj.offsetParent) != null)
        returnValue += inputObj.offsetTop;
    return returnValue + calendar_offsetTop;
}
function __GetLeft(inputObj) {
    var returnValue = inputObj.offsetLeft;
    while ((inputObj = inputObj.offsetParent) != null)
        returnValue += inputObj.offsetLeft;
    return returnValue + calendar_offsetLeft;
}
function SetCalendar(inputObj) {
    calendarDiv.style.left = __GetLeft(inputObj) + 'px';
	calendarDiv.style.top = __GetTop(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 StartCalendar() {
	if (MSIE) {
		iframeObj = document.createElement('IFRAME');
		iframeObj.style.position = 'absolute';
		iframeObj.border='0px';
		iframeObj.style.border = '0px';
		iframeObj.style.backgroundColor = '#FF0000';
		//// fix for EI frame problem on time dropdowns 09/30/2006
		iframeObj2 = document.createElement('IFRAME');
		iframeObj2.style.position = 'absolute';
		iframeObj2.border='0px';
		iframeObj2.style.border = '0px';
		iframeObj2.style.height = '1px';
		iframeObj2.style.width = '1px';
		document.body.appendChild(iframeObj2);
		//// fix for EI frame problem on time dropdowns 09/30/2006
		// Added fixed for HTTPS
		iframeObj2.src = 'blank.html'; 
		iframeObj.src = 'blank.html'; 
		document.body.appendChild(iframeObj);
    }
    calendarDiv = document.createElement('DIV');
	calendarDiv.id = 'calendarDiv';
	calendarDiv.style.zIndex = 1000;
	slideCalendarSelectBox();
	document.body.appendChild(calendarDiv);
	CreateBottom();
	WriteTop();
	if (!currentYear) {
		var d = new Date();
		currentMonth = d.getMonth();
		currentYear = d.getFullYear();
	}
	WriteCalendar();
}
function SetTime() {
    if (!calendarDisplayTime) {
		document.getElementById('timeBar').style.display='none';
		document.getElementById('timeBar').style.visibility='hidden';
		document.getElementById('todaysDateString').style.width = '100%';
	} else {
		document.getElementById('timeBar').style.display='block';
		document.getElementById('timeBar').style.visibility='visible';
		document.getElementById('hourDropDown').style.top = document.getElementById('calendar_minute_txt').parentNode.offsetHeight + calendarContentDiv.offsetHeight + document.getElementById('topBar').offsetHeight + 'px';
		document.getElementById('minuteDropDown').style.top = document.getElementById('calendar_minute_txt').parentNode.offsetHeight + calendarContentDiv.offsetHeight + document.getElementById('topBar').offsetHeight + 'px';
		document.getElementById('minuteDropDown').style.right = '50px';
		document.getElementById('hourDropDown').style.right = '50px';
		document.getElementById('todaysDateString').style.width = '115px';
	}
}
function SetSort(a,b) {
	return a/1 - b/1;
}
function ShowCalendar(inputField,format,buttonObj,displayTime,timeInput) {
    if (displayTime) {
        calendarDisplayTime = true;
    } else {
        calendarDisplayTime = false;
    }
	if (inputField.value.length>0) {
		if (!format.match(/^[0-9]*?$/gi)) {
			var items = inputField.value.split(/[^0-9]/gi);
			var positionArray = new Array();
			positionArray['m'] = format.indexOf('m');
			if(positionArray['m']==-1)positionArray['m'] = format.indexOf('m');
			positionArray['d'] = format.indexOf('d');
			if(positionArray['d']==-1)positionArray['d'] = format.indexOf('d');
			positionArray['y'] = format.indexOf('Y');
			positionArray['h'] = format.indexOf('H');
			positionArray['i'] = format.indexOf('i');

			var positionArrayNumeric = Array();
			positionArrayNumeric[0] = positionArray['m'];
			positionArrayNumeric[1] = positionArray['d'];
			positionArrayNumeric[2] = positionArray['y'];
			positionArrayNumeric[3] = positionArray['h'];
			positionArrayNumeric[4] = positionArray['i'];


			positionArrayNumeric = positionArrayNumeric.sort(SetSort);
			var itemIndex = -1;
			currentHour = '00';
			currentMinute = '00';
			for (var no=0;no<positionArrayNumeric.length;no++)  {
				if (positionArrayNumeric[no]==-1) continue;
				itemIndex++;
				if (positionArrayNumeric[no]==positionArray['m']) {
					currentMonth = items[itemIndex]-1;
					continue;
				}
				if (positionArrayNumeric[no]==positionArray['y']) {
					currentYear = items[itemIndex];
					continue;
				}
				if (positionArrayNumeric[no]==positionArray['d']) {
					tmpDay = items[itemIndex];
					continue;
				}
				if (positionArrayNumeric[no]==positionArray['h']) {
					currentHour = items[itemIndex];
					continue;
				}
				if (positionArrayNumeric[no]==positionArray['i']) {
					currentMinute = items[itemIndex];
					continue;
				}
			}
			currentMonth = currentMonth / 1;
			tmpDay = tmpDay / 1;
		} else {
			var monthPos = format.indexOf('m');
			currentMonth = inputField.value.substr(monthPos,2)/1 -1;
			var yearPos = format.indexOf('Y');
			currentYear = inputField.value.substr(yearPos,4);
			var dayPos = format.indexOf('d');
			tmpDay = inputField.value.substr(dayPos,2);

			var hourPos = format.indexOf('H');
			if (hourPos>=0) {
				tmpHour = inputField.value.substr(hourPos,2);
				currentHour = tmpHour;
			} else {
				currentHour = '00';
			}
			var minutePos = format.indexOf('i');
			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';
		tmpDay = d.getDate();
	}
    inputYear = currentYear;
	inputMonth = currentMonth;
	inputDay = tmpDay/1;
	if (!calendarDiv) {
		StartCalendar();
	} else {
		if (calendarDiv.style.display=='block') {
			HideCalendar();
			return false;
		}
		WriteCalendar();
	}
	returnFormat = format;
	returnDateTo = inputField;
	SetCalendar(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';
	}
	SetTime();	
	UpdateYear();
	UpdateMonth();
	UpdateMinute();
	UpdateHour();
}
function ShowSelect(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) {
		StartCalendar();
	} else {
		WriteCalendar();
	}
	returnDateToYear = yearInput;
	returnDateToMonth = monthInput;
	returnDateToDay = dayInput;
	returnDateToHour = hourInput;
	returnDateToMinute = minuteInput;

	returnFormat = false;
	returnDateTo = false;
	SetCalendar(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';	
		//// fix for EI frame problem on time dropdowns 09/30/2006
		iframeObj2.style.display = '';
		iframeObj2.style.height = calendarDiv.offsetHeight + 'px';
		iframeObj2.style.width = calendarDiv.offsetWidth + 'px'
	}
	SetTime();
	UpdateYear();
	UpdateMonth();
	UpdateHour();
	UpdateMinute();
}