/************************************************************************************************************


this version of the calendar is extremely modified by guido k. (guidok@comasystem.de)
it is not compatible with the original dhtmlgoodies calendar but has many new features.
you can use it under the same conditions as the original script. just leave all copyright messages
as they are. watch the file changes.txt for all changes made by me.
i think i will call that version 2.1g (August 2006)
have fun



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

************************************************************************************************************/

/* Update log:
(C) www.dhtmlgoodies.com, September 2005

Version 1.2, November 8th - 2005 - Added <iframe> background in IE
Version 1.3, November 12th - 2005 - Fixed top bar position in Opera 7
Version 1.4, December 28th - 2005 - Support for Spanish and Portuguese
Version 1.5, January  18th - 2006 - Fixed problem with next-previous buttons after a month has been selected from dropdown
Version 1.6, February 22nd - 2006 - Added variable which holds the path to images.
                                                                        Format todays date at the bottom by use of the todayStringFormat variable
                                                                        Pick todays date by clicking on todays date at the bottom of the calendar
Version 2.0         May, 25th - 2006          - Added support for time(hour and minutes) and changing year and hour when holding mouse over + and - options. (i.e. instead of click)
Version 2.1         July, 2nd - 2006          - Added support for more date formats(example: d.m.yyyy, i.e. one letter day and month).

*/
var theScriptURL="http://www.nrw-neueslernen.de/kalender/index.php";
var defaultLanguageCode = 'en';        // Possible values:         en,ge,no,nl,es,pt-br,fr
                                                        // en = english, ge = german, no = norwegian,nl = dutch, es = spanish, pt-br = portuguese, fr = french, da = danish, hu = hungarian(Use UTF-8 doctype for hungarian)

// Format of current day at the bottom of the calendar
// [dayString] = day of week (examle: mon, tue, wed...)
// [UCFdayString] = day of week (examle: Mon, Tue, Wed...) ( First letter in uppercase)
// [day] = Day of month, 1..31
// [monthString] = Name of current month
// [year] = Current year
var todayStringFormat = '[UCFdayString]. [day]. [monthString] [year]';
var pathToImages = '/_img/images/';        // Relative to your HTML file

var speedOfSelectBoxSliding = 150;        // Milliseconds between changing year and hour when holding mouse over "-" or "+" - lower value = faster
var speedOfSelectBoxSliding2 = 50;        // Milliseconds between changing year and hour when holding mouse over "-" or "+" and clicking the mousebutton - lower value = faster

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 = 25;        // Offset - calendar placement - You probably have to modify this value if you're not using a strict doctype
var calendarDiv = false;
var delayTimeHour = 100;                    //delay in miliseconds for the hour-counter
var delayTimeMinute = 50;                    //delay in miliseconds for the minute-counter
var predelayTime = 400;                 //predelay (the delay-time before the counter begins to raise or lower) in miliseconds for the hour- and minute-counter

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;

function setLanguage(languageCode)
{
switch(languageCode){
        case "en":        /* English */
                monthArray = ['January','February','March','April','May','June','July','August','September','October','November','December'];
                monthArrayShort = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
                dayArray = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'];
                weekString = 'Week';
                closeTitle = 'close calendar without accepting changes';
                okTitle = 'accept changes and close calendar';
                plusMinusHourTitle = 'Hour: Type in or select with buttons. Hold button pressed for automatic counting.';
                plusMinusMinuteTitle = 'Minute: Type in or select with buttons. Hold button pressed for automatic counting.';
                monthDropDownTitle = 'Open the pulldown and select a month.';
                yearDropDownTitle = 'Open the pulldown and select a year. By sliding over - or + years are counted down or up. Holding the mousebutton down increases the speed.';
                monthSwitchUpTitle = 'Switch a month forward.';
                monthSwitchDownTitle = 'Switch a month back.';
                todaysDateTitle = 'Select todays date';
                break;
        case "de":        /* German */
                monthArray = ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'];
                monthArrayShort = ['Jan','Feb','Mar','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'];
                dayArray = ['Mon','Die','Mit','Don','Fre','Sam','Son'];
                weekString = 'Woche';
                closeTitle = 'Kalender ohne Änderungen schließen';
                okTitle = 'Änderungen übernehmen und Kalender schließen';
                plusMinusHourTitle ='Stunde: Bitte eintippen, oder mit den Buttons wählen. Button gedrückt halten, um automatisch zu zählen.';
                plusMinusMinuteTitle ='Minute: Bitte eintippen, oder mit den Buttons wählen. Button gedrückt halten, um automatisch zu zählen.';
                monthDropDownTitle = 'Öffnet das Pulldown zur Monatswahl.';
                yearDropDownTitle = 'Öffnet das Pulldown zur Jahreswahl. Um die Jahreszahlen zu erhöhen oder zu verringern, bewegen Sie die Maus über + oder -. Halten Sie die Maustaste geclickt für höhere Geschwindigkeit.';
                monthSwitchUpTitle = 'Einen Monat vor.';
                monthSwitchDownTitle = 'Einen Monat zurück.';
                todaysDateTitle = 'Wählt das heutige Datum';
                break;
}
}


//no more configuration from here on

var daysInMonthArray = [31,28,31,30,31,30,31,31,30,31,30,31];
var currentDay;
var currentMonth;
var currentYear;
var currentHour;
var currentMinute;
var calendarContentDiv;
var returnDateTo;
var returnFormat;

var iframeObj = false;

var returnDateToYear;
var returnDateToMonth;
var returnDateToDay;
var returnDateToHour;
var returnDateToMinute;

var predelayCounter = 0;
var counterTimeout;
var changeYearTimeout;
var movementTimeout;
var selectBoxSpeed=speedOfSelectBoxSliding;
var calendarDisplayTime;

function cancelCalendarEvent()
{
        return false;
}

function isLeapYear(inputYear)
{
        if(inputYear%400==0||(inputYear%4==0&&inputYear%100!=0)) return true;
        return false;
}

function highlightMonth()
{
        if(this.className=='monthYearActive'){
                this.className='';
                if(currentMonth && this.id == 'monthDiv' + currentMonth/1){this.className = 'selectBoxHighlightColor';}
        }
        else{
                this.className = 'monthYearActive';
        }
}

function highlightYear()
{
        if(this.className=='monthYearActive'){
                this.className='';
                if(currentYear && this.id == 'yearDiv' + currentYear/1){this.className = 'selectBoxHighlightColor';}
        }else{
                this.className = 'monthYearActive';
        }

        if(this.innerHTML.indexOf('-')>=0 || this.innerHTML.indexOf('+')>=0){
                if(this.className=='monthYearActive'){changeSelectBoxYear();}
                else {clearTimeout(changeYearTimeout);}
        }
}

function showMonthDropDown()
{
        updateMonthDiv();
        if(document.getElementById('monthDropDown').style.display=='block'){
                document.getElementById('monthDropDown').style.display='none';
        }else{
                document.getElementById('monthDropDown').style.display='block';
                document.getElementById('yearDropDown').style.display='none';
        }
}

function showYearDropDown()
{
        updateYearDiv();
        if(document.getElementById('yearDropDown').style.display=='block'){
                document.getElementById('yearDropDown').style.display='none';
        }else{
                document.getElementById('yearDropDown').style.display='block';
                document.getElementById('monthDropDown').style.display='none';
        }

}

function selectMonth()
{
        document.getElementById('calendar_month_txt').innerHTML = this.innerHTML
        currentMonth = this.id.replace(/[^\d]/g,'');

        document.getElementById('monthDropDown').style.display='none';
        this.className = 'selectBoxHighlightColor';
        writeCalendarContent();

}

function selectYear()
{
        document.getElementById('calendar_year_txt').innerHTML = this.innerHTML
        currentYear = this.innerHTML.replace(/[^\d]/g,'');
        document.getElementById('yearDropDown').style.display='none';
        this.className = 'selectBoxHighlightColor';
        writeCalendarContent();

}

function switchMonth()
{
        closeYearMonthDropDown();
        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 = document.createElement('DIV');
        div.className='monthYearPicker';
        div.id = 'monthPicker';

        for(var no=0;no<monthArray.length;no++){
                var subDiv = document.createElement('DIV');
                subDiv.innerHTML = monthArray[no];
                subDiv.onmouseover = highlightMonth;
                subDiv.onmouseout = highlightMonth;
                subDiv.onclick = selectMonth;
                subDiv.id = 'monthDiv' + no;
                subDiv.style.width = '56px';
                subDiv.onselectstart = cancelCalendarEvent;
                div.appendChild(subDiv);
                if(currentMonth && currentMonth==no){
                        subDiv.className = 'selectBoxHighlightColor';
                }

        }
        return div;

}

function changeSelectBoxYear()
{
        var inputObj = document.getElementById('yearDropDown');
        var yearItems = inputObj.getElementsByTagName('DIV');
        if(yearItems[0].className=='monthYearActive'){var startYear = yearItems[1].innerHTML/1 -1;}
        else{var startYear = yearItems[1].innerHTML/1 +1;}

        for(var no=1;no<yearItems.length-1;no++){
                yearItems[no].innerHTML = startYear+no-1;
                yearItems[no].id = 'yearDiv' + (startYear/1+no/1-1);
                yearItems[no].className = '';
                if(currentYear && startYear+no-1 == currentYear){yearItems[no].className = 'selectBoxHighlightColor';}
        }
        changeYearTimeout = setTimeout("changeSelectBoxYear()",selectBoxSpeed);
}

function updateYearDiv()
{
        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].className = 'selectBoxHighlightColor';
                }else{
                        yearItems[no].className = '';
                }
        }
}

function updateMonthDiv()
{
        for(no=0;no<12;no++){
                document.getElementById('monthDiv' + no).className = '';
        }
        document.getElementById('monthDiv' + currentMonth).className = 'selectBoxHighlightColor';
}

function createYearDiv()
{

        if(!document.getElementById('yearDropDown')){
                var div = document.createElement('DIV');
                div.className='monthYearPicker';
        }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;- ';
        subDiv.onmousedown = function(){selectBoxSpeed=speedOfSelectBoxSliding2;}
        subDiv.onmouseup = function(){selectBoxSpeed=speedOfSelectBoxSliding;}
        subDiv.onmouseover = highlightYear;
        subDiv.onmouseout = highlightYear;
        subDiv.onselectstart = cancelCalendarEvent;
        div.appendChild(subDiv);

        for(var no=startYear;no<(startYear+10);no++){
                var subDiv = document.createElement('DIV');
                subDiv.innerHTML = no;
                subDiv.onmouseover = highlightYear;
                subDiv.onmouseout = highlightYear;
                subDiv.onclick = selectYear;
                subDiv.id = 'yearDiv' + no;
                subDiv.onselectstart = cancelCalendarEvent;
                div.appendChild(subDiv);
                if(currentYear && currentYear==no){
                        subDiv.className = 'selectBoxHighlightColor';
                }
        }
        var subDiv = document.createElement('DIV');
        subDiv.innerHTML = '&nbsp;&nbsp;+ ';
        subDiv.onmousedown = function(){selectBoxSpeed=speedOfSelectBoxSliding2;}
        subDiv.onmouseup = function(){selectBoxSpeed=speedOfSelectBoxSliding;}
        subDiv.onmouseover = highlightYear;
        subDiv.onmouseout = highlightYear;
        subDiv.onselectstart = cancelCalendarEvent;
        div.appendChild(subDiv);
        return div;
}

function highlightSelect()
{
       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 highlightArrow()
{
        if(this.src.indexOf('over')>=0){
                if(this.src.indexOf('left')>=0)this.src = pathToImages + 'left.gif';
                if(this.src.indexOf('right')>=0)this.src = pathToImages + 'right.gif';
        }else{
                if(this.src.indexOf('left')>=0)this.src = pathToImages + 'left_over.gif';
                if(this.src.indexOf('right')>=0)this.src = pathToImages + 'right_over.gif';
        }
}

function highlightPlusMinus()
{
                if(this.src.indexOf('plus')>=0)this.src = pathToImages + 'plus_over.gif';
                if(this.src.indexOf('minus')>=0)this.src = pathToImages + 'minus_over.gif';
}

function highlightClose()
{
        if(this.src.indexOf('over')>=0){
                this.src = pathToImages + 'close.gif';
        }else{
                this.src = pathToImages + 'close_over.gif';
        }

}

function highlightOk()
{
        if(this.src.indexOf('over')>=0){
                this.src = pathToImages + 'ok.gif';
        }else{
                this.src = pathToImages + 'ok_over.gif';
        }

}

function closeCalendar(){

        closeYearMonthDropDown();

        calendarDiv.style.display='none';
        if(iframeObj)iframeObj.style.display='none';
}

function moveCalendar(event)
{
        if(!event){var event = window.event;}
        calendarDiv.style.left = event.clientX-158 + 'px';
        calendarDiv.style.top = event.clientY-9 + 'px';
        if(iframeObj){
                iframeObj.style.left = calendarDiv.style.left;
                iframeObj.style.top =  calendarDiv.style.top;
        }
        movementTimeout = setTimeout(moveCalendar(event),50);
}

function stopMoveCalendar()
{
        if(movementTimeout){clearTimeout(movementTimeout);}
}

function writeTopBar()
{
        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';
        leftDiv.title = monthSwitchDownTitle;
        var img = document.createElement('IMG');
        img.src = pathToImages + 'left.gif';
        img.onmouseover = highlightArrow;
        img.onclick = switchMonth;
        img.onmouseout = highlightArrow;
        leftDiv.appendChild(img);
        topBar.appendChild(leftDiv);
        if(Opera)leftDiv.style.width = '16px';

        // Right arrow
        var rightDiv = document.createElement('DIV');
        rightDiv.style.marginRight = '1px';
        rightDiv.title = monthSwitchUpTitle;
        var img = document.createElement('IMG');
        img.src = pathToImages + 'right.gif';
        img.onclick = switchMonth;
        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.title = monthDropDownTitle;
        monthDiv.onmouseover = highlightSelect;
        monthDiv.onmouseout = highlightSelect;
        monthDiv.onclick = showMonthDropDown;
        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 = createMonthDiv();
        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.title = yearDropDownTitle;
        yearDiv.onmouseover = highlightSelect;
        yearDiv.onmouseout = highlightSelect;
        yearDiv.onclick = showYearDropDown;
        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 = createYearDiv();
        yearPicker.style.left = '113px';
        yearPicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
        yearPicker.style.width = '35px';
        yearPicker.id = 'yearDropDown';
        calendarDiv.appendChild(yearPicker);
}

function writeCalendarContent()
{
        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').value = currentHour;
        document.getElementById('calendar_minute_txt').value = currentMinute;

        var existingTable = calendarContentDiv.getElementsByTagName('TABLE');
        if(existingTable.length>0){
                calendarContentDiv.removeChild(existingTable[0]);
        }

        var calTable = document.createElement('TABLE');
        calTable.cellSpacing = '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.className = 'weekNumberDiv';
        cell.onclick = closeYearMonthDropDown;

        for(var no=0;no<dayArray.length;no++){
                var cell = row.insertCell(-1);
                cell.innerHTML = dayArray[no];
                cell.onclick = closeYearMonthDropDown;
        }

        var row = calTBody.insertRow(-1);
        var cell = row.insertCell(-1);
        cell.className = 'weekNumberDiv';
        var week = getWeek(currentYear,currentMonth,1);
        cell.innerHTML = week;            // Week
        cell.onclick = closeYearMonthDropDown;
        for(var no=0;no<dayStartOfMonth;no++){
                var cell = row.insertCell(-1);
                cell.innerHTML = '&nbsp;';
                cell.onclick = closeYearMonthDropDown;
        }

        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);
                        var cell = row.insertCell(-1);
                        var week = getWeek(currentYear,currentMonth,no);
                        cell.innerHTML = week;                // Week
                        cell.className = 'weekNumberDiv';
                        cell.onclick = closeYearMonthDropDown;
                }
                var cell = row.insertCell(-1);
	var cM=currentMonth;
		if (cM < 9){cM='0'+(cM+1);}
			else{cM++;}
				var cD=no;
					if (cD <= 9){cD='0'+cD;}
						//alert(currentYear+""+cM+""+cD);
						                if(ndates[currentYear+""+cM+""+cD]=='1'){
                        cell.className = 'activeDay2';
                        cell.id = 'activeDay2';
                                cell.innerHTML = "<a href='"+theScriptURL+"?year="+currentYear+"&month="+(currentMonth+1)+"&day="+no+"'>"+no+"</a>";
                }
                else{
                                        cell.innerHTML = no;
                }
                cell.onclick = closeYearMonthDropDown;
                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('resizeIframe()',350);else setTimeout('resizeIframe()',10);
        }




}

function setActiveDay(){
        closeYearMonthDropDown();
        var aDay = document.getElementById('activeDay');
        if (aDay){
        aDay.className = '';
        aDay.id = '';
        }
        this.className='activeDay';
        this.id='activeDay';
        currentDay=this.innerHTML;
}

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();
        currentDay = d.getDate();
        pickDate();

}

function pickDate()
{
        var month = currentMonth/1 +1;
        if(month<10)month = '0' + month;
        var day;
        day=currentDay;
        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);
                returnDateTo.value = returnFormat;
        }else{
                if(returnDateToYear){

                if (returnDateToYear.options){
                for(var no=0;no<returnDateToYear.options.length;no++){
                        if(returnDateToYear.options[no].value==currentYear){
                                returnDateToYear.selectedIndex=no;
                                break;
                        }
                }
                }
                else {returnDateToYear.value=currentYear;}


                }
                if(returnDateToMonth){
                for(var no=0;no<returnDateToMonth.options.length;no++){
                        if(returnDateToMonth.options[no].value==month){
                                returnDateToMonth.selectedIndex=no;
                                break;
                        }
                }
                }
                if(returnDateToDay){
                for(var no=0;no<returnDateToDay.options.length;no++){
                        if(returnDateToDay.options[no].value==day){
                                returnDateToDay.selectedIndex=no;
                                break;
                        }
                }
                }
                if(returnDateToHour){
                for(var no=0;no<returnDateToHour.options.length;no++){
                        if(returnDateToHour.options[no].value==currentHour){
                                returnDateToHour.selectedIndex=no;
                                break;
                        }
                }
                }
                if(returnDateToMinute){
                for(var no=0;no<returnDateToMinute.options.length;no++){
                        if(returnDateToMinute.options[no].value==currentMinute){
                                returnDateToMinute.selectedIndex=no;
                                break;
                        }
                }
                }
        }
        closeCalendar();
}

// This function is from http://www.codeproject.com/csharp/gregorianwknum.asp
// Only changed the month add
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;      // (gregorian calendar)
    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 checkSetHour()
{
        closeYearMonthDropDown();
        var theHour=document.getElementById('calendar_hour_txt').value/1;
        if (theHour <= 23 && theHour >= 0){
        if (theHour < 10 && theHour >= 0){theHour = '0'+theHour;}
        currentHour = theHour;
        }
        else{theHour = '00';}
        document.getElementById('calendar_hour_txt').value = theHour;
}

function checkSetMinute()
{
        closeYearMonthDropDown();
        var theMinute=document.getElementById('calendar_minute_txt').value/1;
        if (theMinute <= 59 && theMinute >= 0){
        if (theMinute < 10 && theMinute >= 0){theMinute = '0'+theMinute;}
        currentMinute = theMinute;
        }
        else{theHour = '00';}
        document.getElementById('calendar_minute_txt').value = theHour;
}

function releaseMouse()
{
        predelayCounter = 0;
        if (counterTimeout){clearTimeout(counterTimeout);}
        if (this.onmouseover != true){
        if(this.src.indexOf('plus')>=0)this.src = pathToImages + 'plus.gif';
        if(this.src.indexOf('minus')>=0)this.src = pathToImages + 'minus.gif';
        }
}

function raiseHour(){
        closeYearMonthDropDown();
        var theHour=document.getElementById('calendar_hour_txt').value/1;
        if (theHour < 23 && theHour >= 0){
                theHour++;
                if (theHour < 10 && theHour >= 0){theHour='0'+theHour;}
                }
        else{theHour = '00';}
        currentHour = theHour;
        document.getElementById('calendar_hour_txt').value = theHour;
        var mydelayTime = delayTimeHour;
        if (predelayCounter == 0){
                mydelayTime = predelayTime;
                predelayCounter = 1;
        }
        counterTimeout = setTimeout("raiseHour()",mydelayTime);
}

function lowerHour(){
        closeYearMonthDropDown();
        var theHour = document.getElementById('calendar_hour_txt').value/1;
        if (theHour <= 23 && theHour > 0){
                theHour--;
                if (theHour < 10 && theHour >= 0){theHour='0'+theHour;}
                }
        else{theHour = 23;}
        currentHour = theHour;
        document.getElementById('calendar_hour_txt').value = theHour;
        var mydelayTime = delayTimeHour;
        if (predelayCounter == 0){
                mydelayTime = predelayTime;
                predelayCounter = 1;
        }
        counterTimeout = setTimeout("lowerHour()",mydelayTime);
}

function raiseMinute(){
        closeYearMonthDropDown();
        var theMinute=document.getElementById('calendar_minute_txt').value/1;
        if (theMinute < 59 && theMinute >= 0){
                theMinute++;
                if (theMinute < 10 && theMinute >= 0){theMinute='0'+theMinute;}
                }
        else{theMinute = '00';}
        currentMinute = theMinute;
        document.getElementById('calendar_minute_txt').value = theMinute;
        var mydelayTime = delayTimeMinute;
        if (predelayCounter == 0){
                mydelayTime = predelayTime;
                predelayCounter = 1;
        }
        counterTimeout = setTimeout("raiseMinute()",mydelayTime);
}

function lowerMinute(){
        closeYearMonthDropDown();
        var theMinute=document.getElementById('calendar_minute_txt').value/1;
        if (theMinute <= 59 && theMinute > 0){
                theMinute--;
                if (theMinute < 10 && theMinute >= 0){theMinute='0'+theMinute;}
                }
        else{theMinute = 59;}
        currentMinute = theMinute;
        document.getElementById('calendar_minute_txt').value = theMinute;
        var mydelayTime = delayTimeMinute;
        if (predelayCounter == 0){
                mydelayTime = predelayTime;
                predelayCounter = 1;
        }
        counterTimeout = setTimeout("lowerMinute()",mydelayTime);
}

function writeTimeBar()
{
        var timeBar = document.createElement('DIV');
        timeBar.id = 'timeBar';
        timeBar.className = 'timeBar';

        // hour selector

        // the input
        var inputHour = document.createElement('INPUT');
        inputHour.className = 'hourInput';
        inputHour.title = plusMinusHourTitle;
        inputHour.maxLength = 2;
        if(Opera){
                inputHour.style.cssText = 'float:left;position:relative';
                inputHour.style.position = 'relative';
                inputHour.style.styleFloat = 'left';
        }
        inputHour.value = currentHour;
        inputHour.onchange = checkSetHour;
        inputHour.id = 'calendar_hour_txt';
        timeBar.appendChild(inputHour);
        //

        // the buttons
        var plusMinusDiv = document.createElement('DIV');
        plusMinusDiv.className = 'hourPlusMinus';
        plusMinusDiv.title = plusMinusHourTitle;
        if(Opera){
                plusMinusDiv.style.cssText = 'float:left;position:relative';
                plusMinusDiv.style.position = 'relative';
                plusMinusDiv.style.styleFloat = 'left';
        }

        var plusImg = document.createElement('IMG');
        plusImg.src = pathToImages + 'plus.gif';
        plusImg.onmousedown = raiseHour;
        plusImg.onmouseup = releaseMouse;
        plusImg.onmouseover = highlightPlusMinus;
        plusImg.onmouseout = releaseMouse;
        plusImg.style.position = 'absolute';
        plusImg.style.left = '0px';
        plusImg.style.top = '0px';

        if(Opera){
                plusImg.style.cssText = 'float:right;position:relative';
                plusImg.style.position = 'relative';
                plusImg.style.styleFloat = 'left';
        }
        plusMinusDiv.appendChild (plusImg);

        var minusImg = document.createElement('IMG');
        minusImg.src = pathToImages + 'minus.gif';
        minusImg.onmousedown = lowerHour;
        minusImg.onmouseup = releaseMouse;
        minusImg.onmouseover = highlightPlusMinus;
        minusImg.onmouseout = releaseMouse;
        minusImg.style.position = 'absolute';
        minusImg.style.left = '0px';
        minusImg.style.top = '8px';

        if(Opera){
                minusImg.style.cssText = 'float:right;position:relative';
                minusImg.style.position = 'relative';
                minusImg.style.styleFloat = 'left';
        }
        plusMinusDiv.appendChild (minusImg);

        timeBar.appendChild(plusMinusDiv);
        //

        // hour selector ends


        // minute selector

        // the input
        var inputMinute = document.createElement('INPUT');
        inputMinute.className = 'minuteInput';
        inputMinute.title = plusMinusMinuteTitle;
        inputMinute.maxLength = 2;
        if(Opera){
                inputMinute.style.cssText = 'float:left;position:relative';
                inputMinute.style.position = 'relative';
                inputMinute.style.styleFloat = 'left';
        }
        inputMinute.value = currentMinute;
        inputMinute.onchange = checkSetMinute;
        inputMinute.id = 'calendar_minute_txt';
        timeBar.appendChild(inputMinute);
        //

        // the buttons
        var plusMinusDiv = document.createElement('DIV');
        plusMinusDiv.className = 'minutePlusMinus';
        plusMinusDiv.title = plusMinusMinuteTitle;
        if(Opera){
                plusMinusDiv.style.cssText = 'float:left;position:relative';
                plusMinusDiv.style.position = 'relative';
                plusMinusDiv.style.styleFloat = 'left';
        }

        var plusImg = document.createElement('IMG');
        plusImg.src = pathToImages + 'plus.gif';
        plusImg.onmousedown = raiseMinute;
        plusImg.onmouseup = releaseMouse;
        plusImg.onmouseover = highlightPlusMinus;
        plusImg.onmouseout = releaseMouse;
        plusImg.style.position = 'absolute';
        plusImg.style.left = '0px';
        plusImg.style.top = '0px';

        if(Opera){
                plusImg.style.cssText = 'float:right;position:relative';
                plusImg.style.position = 'relative';
                plusImg.style.styleFloat = 'left';
        }
        plusMinusDiv.appendChild (plusImg);

        var minusImg = document.createElement('IMG');
        minusImg.src = pathToImages + 'minus.gif';
        minusImg.onmousedown = lowerMinute;
        minusImg.onmouseup = releaseMouse;
        minusImg.onmouseover = highlightPlusMinus;
        minusImg.onmouseout = releaseMouse;
        minusImg.style.position = 'absolute';
        minusImg.style.left = '0px';
        minusImg.style.top = '8px';

        if(Opera){
                minusImg.style.cssText = 'float:right;position:relative';
                minusImg.style.position = 'relative';
                minusImg.style.styleFloat = 'left';
        }
        plusMinusDiv.appendChild (minusImg);

        timeBar.appendChild(plusMinusDiv);
        //

        // minute selector ends

        return timeBar;

}

function writeBottomBar()
{
        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.id = 'todaysDateString';
        subDiv.title = todaysDateTitle;
        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('[dayString]',dayArray[day].toLowerCase());
        bottomString = bottomString.replace('[UCFdayString]',dayArray[day]);

        subDiv.innerHTML = "<a href='"+theScriptURL+"?year="+d.getFullYear()+"&month="+(d.getMonth()+1)+"&day="+d.getDate()+"'>"+bottomString+"</a>";
        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 positionCalendar(inputObj)
{
        calendarDiv.style.left = getleftPos(inputObj) + 'px';
        calendarDiv.style.top = getTopPos(inputObj) + 'px';
        if(iframeObj){
                iframeObj.style.left = calendarDiv.style.left;
                iframeObj.style.top =  calendarDiv.style.top;
        }
}

function initCalendar()
{
        if(MSIE){
                iframeObj = document.createElement('IFRAME');
                iframeObj.style.position = 'absolute';
                iframeObj.border='0px';
                iframeObj.style.border = '0px';
                iframeObj.style.backgroundColor = '#FF0000';
                document.body.appendChild(iframeObj);
        }

        calendarDiv = document.createElement('DIV');
        calendarDiv.id = 'calendarDiv';
        calendarDiv.style.zIndex = 1000;

        document.body.appendChild(calendarDiv);
        writeBottomBar();
        writeTopBar();
        writeCalendarContent();



}

function setTimeProperties()
{
        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('todaysDateString').style.width = '115px';
        }
}


function displayCalendar2(yearInput,monthInput,dayInput,hourInput,minuteInput,displayTime,languageInput,buttonObj)
{
        if (languageInput){defaultLanguageCode = languageInput;}
        setLanguage(defaultLanguageCode);
        if(displayTime)calendarDisplayTime=true; else calendarDisplayTime = false;

        var d = new Date();

        if (dayInput && dayInput/1 > 0 && dayInput/1 <= 31)
        {currentDay = dayInput/1;}
        else{currentDay = d.getDate();}
        if (monthInput && monthInput/1 > 0 && monthInput/1 <= 12)
        {currentMonth = monthInput/1-1;}
        else{currentMonth = d.getMonth();}
        if (yearInput){
        if (yearInput/1 > 0)
        {currentYear = yearInput/1;}
        else{currentYear = d.getFullYear();}
        }
        else if (yearInput && yearInput/1 > 0)
        {currentYear = yearInput/1;}
        else{currentYear = d.getFullYear();}
        if (hourInput && hourInput/1 >= 0 && hourInput/1 <= 23)
        {
        currentHour = hourInput/1;
        if (currentHour < 10 && currentHour >= 0){currentHour='0'+currentHour;}
        }
        else{currentHour = '00';}
        if (minuteInput && minuteInput/1 >= 0 && minuteInput/1 <= 59)
        {
        currentMinute = minuteInput/1;
        if (currentMinute < 10 && currentMinute >= 0){currentMinute='0'+currentMinute;}
        }
        else{currentMinute = '00';}

        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';
        }
        setTimeProperties();
        updateYearDiv();
        updateMonthDiv();
}


function closeYearMonthDropDown()
{
        document.getElementById('monthDropDown').style.display='none';
        document.getElementById('yearDropDown').style.display='none';
}