',d);
s = s.replace('mmmm','');
s = s.replace('mmm','');
s = s.replace('mm','');
s = s.replace('m','');
s = s.replace('',m+1);
s = s.replace('',this.padZero(m+1));
s = s.replace('',nv_aryMonth[m]);
s = s.replace('',nv_aryMS[m]);
s = s.replace('yyyy',y);
s = s.replace('yy',this.padZero(y%100));
s = s.replace('hh',this.hour);
s = s.replace('xx',this.minute);
s = s.replace('ss',this.second);
return s.replace ('yy',this.padZero(y%100));
},
close: function(day) {
this.hide();
if (day) this.dateSelected = day;
this.ctlToPlaceValue.value = this.constructDate(this.dateSelected, this.monthSelected, this.yearSelected);
},
setToday: function() {
this.dateSelected = this.dateNow;
this.monthSelected = this.monthNow;
this.yearSelected = this.yearNow;
this.construct();
},
StartDecMonth: function() { // Month Pulldown
this.intervalID1 = setInterval('popCalendar.decMonth()',80);
},
StartIncMonth: function() {
this.intervalID1 = setInterval('popCalendar.incMonth()',80);
},
incMonth: function() {
this.monthSelected++;
if (this.monthSelected > 11) {this.monthSelected = 0; this.yearSelected++;}
this.construct();
},
decMonth: function() {
this.monthSelected--;
if (this.monthSelected < 0) {this.monthSelected = 11; this.yearSelected--;}
this.construct();
},
constructMonth: function() {
this.popDownYear();
var s = '';
for (i=0; i<12; i++) {
var sName = nv_aryMonth[i];
if (i == this.monthSelected) sName = '' + sName + '';
s += '
' + sName + '';
}
this.om.innerHTML = '';
},
popUpMonth: function() {
var leftOffset;
if (this.visMonth == 1) {
this.popDownMonth();
this.visMonth--;
} else {
this.constructMonth();
this.om.style.visibility = 'visible';
leftOffset = parseInt(this.o.style.left) + this.$('pcIDMonth').offsetLeft;
if (this.ie) leftOffset += 1;
this.om.style.left = leftOffset + 'px';
this.om.style.top = parseInt(this.o.style.top) + 19 + 'px';
if (this.hideElements) {
this.hideElement('SELECT', this.om);
this.hideElement('APPLET', this.om);
}
this.visMonth++;
}
},
popDownMonth: function() {
this.om.style.visibility = 'hidden';
this.visMonth = 0;
},
incYear: function() { // Year Pulldown
for (var i=0; i<7; i++) {
var newYear = (i + this.nStartingYear) + 1;
this.$('pcY'+i).innerHTML = (newYear == this.yearSelected) ? ''+newYear+'' : newYear;
}
this.nStartingYear++; this.bShow=true;
},
decYear: function() {
for (var i=0; i<7; i++) {
var newYear = (i + this.nStartingYear) - 1;
this.$('pcY'+i).innerHTML = (newYear == this.yearSelected) ? ''+newYear+'' : newYear;
}
this.nStartingYear--; this.bShow=true;
},
selectYear: function(nYear) {
this.yearSelected = parseInt(nYear + this.nStartingYear);
this.yearConstructed = false;
this.construct();
this.popDownYear();
},
constructYear: function() {
this.popDownMonth();
var s = '';
if (!this.yearConstructed) {
s = '-';
var j = 0;
this.nStartingYear = this.yearSelected - 3;
for ( var i = (this.yearSelected-3); i <= (this.yearSelected+3); i++ ) {
var sName = i;
if (i == this.yearSelected) sName = '' + sName + '';
s += '' + sName + '';
j++;
}
s += '+';
this.oy.innerHTML = '';
this.yearConstructed = true;
}
},
popDownYear: function() {
clearInterval(this.intervalID1);
clearTimeout(this.timeoutID1);
clearInterval(this.intervalID2);
clearTimeout(this.timeoutID2);
this.oy.style.visibility= 'hidden';
this.visYear = 0;
},
popUpYear: function() {
var leftOffset;
if (this.visYear==1) {
this.popDownYear();
this.visYear--;
} else {
this.constructYear();
this.oy.style.visibility = 'visible';
leftOffset = parseInt(this.o.style.left) + this.$('pcIDYear').offsetLeft;
if (this.ie) leftOffset += 1;
this.oy.style.left = leftOffset + 'px';
this.oy.style.top = parseInt(this.o.style.top) + 19 + 'px';
this.visYear++;
}
},
WeekNbr: function(n) { // construct calendar
// Algorithm used from Klaus Tondering's Calendar document (The Authority/Guru)
// http://www.tondering.dk/claus/calendar.html
if (n == null) n = new Date (this.yearSelected,this.monthSelected,1);
var year = n.getFullYear();
var month = n.getMonth() + 1;
if (this.startAt == 0) {
var day = n.getDate() + 1;
} else {
var day = n.getDate();
}
var a = Math.floor((14-month) / 12);
var y = year + 4800 - a;
var m = month + 12 * a - 3;
var b = Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400);
var J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045;
var d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;
var L = Math.floor(d4 / 1460);
var d1 = ((d4 - L) % 365) + L;
var week = Math.floor(d1/7) + 1;
return week;
},
construct : function() {
var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31);
var startDate = new Date (this.yearSelected,this.monthSelected,1);
var endDate;
if (this.monthSelected==1) { // get days of February
endDate = new Date (this.yearSelected,this.monthSelected+1,1);
endDate = new Date (endDate - (24*60*60*1000));
var numDaysInMonth = endDate.getDate();
} else {
var numDaysInMonth = aNumDays[this.monthSelected];
}
var dayPointer = startDate.getDay() - this.startAt;
if (dayPointer<0) dayPointer = 6;
var s = ''; // dayheader
if (this.showWeekNumber) { // spacer for Weeknumbers
s += '' + nv_weekShortString + ' | ';
}
for (var i = 0; i<7; i++) { // render daynames
if (this.showDayLetter)
s += '' + nv_aryDayNS[(i+this.startAt) % 7].charAt(0) + ' | ';
else
s += '' + nv_aryDayNS[(i+this.startAt) % 7] + ' | ';
}
s += '
';
if (this.showWeekNumber) {
s += '' + this.WeekNbr(this.startDate) + ' | ';
}
for ( var i=1; i<=dayPointer; i++ ) {
s += ' | ';
}
for (var datePointer=1; datePointer <= numDaysInMonth; datePointer++) {
dayPointer++;
var sClass = '';
var selDayAction = '';
var sHint = '';
for (var k=0; k < this.HolidaysCounter; k++) { // insert holidays
if ((parseInt(this.Holidays[k].d) == datePointer)&&(parseInt(this.Holidays[k].m) == (this.monthSelected+1))) {
if ((parseInt(this.Holidays[k].y)==0)||((parseInt(this.Holidays[k].y)==this.yearSelected)&&(parseInt(this.Holidays[k].y)!=0))) {
sClass = 'pcDayHoliday ';
sHint += sHint=="" ? this.Holidays[k].desc : "\n"+this.Holidays[k].desc;
}
}
}
sHint = sHint.replace('/\"/g', '"');
if ((datePointer == this.odateSelected) && (this.monthSelected == this.omonthSelected) && (this.yearSelected == this.oyearSelected)) {
sClass+='pcDaySelected'; // selected day
} else if ((datePointer == this.dateNow) && (this.monthSelected == this.monthNow) && (this.yearSelected == this.yearNow)) {
sClass+='pcToday'; // today
} else if (
(dayPointer % 7 == (this.startAt * -1)+1)
|| ((dayPointer % 7 == (this.startAt * -1)+7 && this.startAt==1) || (dayPointer % 7 == this.startAt && this.startAt==0)) )
{
sClass+='pcWeekend'; // sunday
} else {
sClass+='pcDay'; // every other day
}
if (!this.enablePast &&
( this.yearSelected < this.yearNow ||
(this.yearSelected == this.yearNow && this.monthSelected < this.monthNow) ||
(this.yearSelected == this.yearNow && this.monthSelected == this.monthNow && datePointer < this.dateNow)
)) {
sClass+='Past'; // all CSS-classes with past-style are suffixed with "Past":
} else {
selDayAction = 'href="javascript:void(0);" onclick="javascript:popCalendar.close('+datePointer+');"';
}
// create HTML:
s += ''+datePointer+' | ';
if ((dayPointer+this.startAt) % 7 == this.startAt) {
s += '
';
if (datePointer < numDaysInMonth) {
s += ''; // open next table row, if we are not at the and of actual month
if (this.showWeekNumber) {
s += '' + (this.WeekNbr(new Date(this.yearSelected,this.monthSelected,datePointer+1))) + ' | ';
}
}
}
}
if (dayPointer % 7 != 0) s += '
'; // close last opened table row
s+='
';
this.$('pcIDcontent').innerHTML = s;
this.$('pcIDMonth').innerHTML = '' + nv_aryMonth[this.monthSelected] + '';
this.$('pcIDYear').innerHTML = '' + this.yearSelected + '';
},
/**
* Main function, shows the calendar.
*
* @param btn The "button" which (de-)activates the calendar
* @param ctl The field to receive the selected date; element or ID-string
* @param format Format of the date-string; optional; see constructDate()
* @param past allow dates in the past; optional; yes=true, no=false
* @param x x-position of the calendar; optional; -1 for directly below btn
* @param y y-position of the calendar; optional; -1 for directly below btn
* @param start Start of the week; optional; Monday=1 or Sunday=0
*/
show: function(btn, ctl, format, past, x, y, start) {
if (start != null) this.startAt = start;
if (!format) format = nv_formatString;
if (!btn) btn = this;
if (!ctl) ctl = btn;
this.enablePast = (past != null) ? past : this.enablePast;
this.fixedX = (x != null) ? x : -1;
this.fixedY = (y != null) ? y : -1;
if (this.showToday)
this.$('pcIDfooter').innerHTML = nv_todayString+' '+ nv_aryDayName[(this.today.getDay()) % 7]+', '+this.dateNow+' '+nv_aryMS[this.monthNow]+' '+this.yearNow+'';
this.popUp(btn, ctl, format);
},
popUp: function(btn, ctl, format) {
var formatChar = '';
var aFormat = new Array();
if (typeof(btn)=='string') btn = this.$(btn);
if (typeof(ctl)=='string') ctl = this.$(ctl);
if (this.bPageLoaded) {
if (this.o.style.visibility == 'hidden') {
this.ctlToPlaceValue = ctl;
this.dateFormat = format || this.dateFormat;
formatChar = ' ';
aFormat = this.dateFormat.split(formatChar);
if (aFormat.length < 3) {
formatChar = '/';
aFormat = this.dateFormat.split(formatChar);
if (aFormat.length < 3) {
formatChar = '.';
aFormat = this.dateFormat.split(formatChar);
if (aFormat.length < 3) {
formatChar = '-';
aFormat = this.dateFormat.split(formatChar);
if (aFormat.length < 3) {
formatChar = ''; // invalid date format
}
}
}
}
var tokensChanged = 0;
var aData;
if (formatChar != "") {
aData = ctl.value.split(formatChar); // use user's date
for (var i=0; i<3; i++) {
if ((aFormat[i] == "d") || (aFormat[i] == "dd")) {
this.dateSelected = parseInt(aData[i], 10);
tokensChanged++;
} else if ((aFormat[i] == "m") || (aFormat[i] == "mm")) {
this.monthSelected = parseInt(aData[i], 10) - 1;
tokensChanged++;
} else if (aFormat[i] == "yyyy") {
this.yearSelected = parseInt(aData[i], 10);
tokensChanged++;
} else if (aFormat[i] == "mmm") {
for (j=0; j<12; j++) {
if (aData[i] == nv_aryMonth[j]) {
this.monthSelected=j;
tokensChanged++;
}
}
} else if (aFormat[i] == "mmmm") {
for (j=0; j<12; j++) {
if (aData[i] == nv_aryMS[j]) {
this.monthSelected = j;
tokensChanged++;
}
}
}
}
}
var TimeFormatChar = ':';
var timeString = ctl.value.split(" ");
if (timeString[1] !=null) {
var timeTokens = timeString[1].split(':');
if(timeTokens[0].length==2) {
this.hour = timeTokens[0];
}
if (timeTokens[1].length==2) {
this.minute = timeTokens[1];
}
if (timeTokens[2].length==2) {
this.second= timeTokens[2];
}
} else {
this.hour=00;
this.minute=00;
this.second=00;
}
if ((tokensChanged != 3) ||
isNaN(this.dateSelected) ||
isNaN(this.monthSelected) ||
this.monthSelected<0 ||
isNaN(this.yearSelected)) {
this.dateSelected = this.dateNow;
this.monthSelected = this.monthNow;
this.yearSelected = this.yearNow;
}
this.odateSelected = this.dateSelected;
this.omonthSelected = this.monthSelected;
this.oyearSelected = this.yearSelected;
if (typeof jQuery != 'undefined') { // use jQuery if available
this.o.style.top = (this.fixedY == -1) ? $(btn).position().top + btn.offsetHeight + 'px' : this.fixedY + 'px' ;
this.o.style.left= (this.fixedX == -1) ? $(btn).position().left + 'px' : this.fixedX + 'px';
} else {
this.o.style.top = (this.fixedY == -1) ? btn.offsetTop + this.getTop(btn.offsetParent) + btn.offsetHeight + 2 + 'px' : this.fixedY + 'px' ;
this.o.style.left= (this.fixedX == -1) ? btn.offsetLeft + this.getLeft(btn.offsetParent) + 'px' : this.fixedX + 'px';
}
this.construct (1, this.monthSelected, this.yearSelected);
this.o.style.visibility = "visible";
if (this.hideElements) {
this.hideElement('SELECT', this.$('pcIDcalendar'));
this.hideElement('APPLET', this.$('pcIDcalendar'));
}
this.bShow = true;
} else {
popCalendar.hide();
if (this.ctlNow!=btn) this.popUp(btn, ctl, format);
}
this.ctlNow = btn;
}
}
}
popCalendar.init();