var currentDate, currentYear, curField, startField,endField, startObj, endObj, curObj; //strore date Mask for showing in span var shortDateMask = "m.d.Y"; //Possible values Mo or Su var weekStart = "Su"; var originalLeft = 0; var originalTop = 0; //Flag between using timestamp or date in format yyyy-mm-dd var useTimestamp = 0; var startDate; //calendar style var csTitleBackground = "#000080"; var csFontSize = '12px'; var csFontType = 'Verdana'; var csTableWidth = '170px'; var csTableBackground = 'white'; var csTableCellSpacing = 0; var csCloseColor = '#FFFFFF'; var csCloseFontType = 'Couier New'; var csCloseFontSize = '14px'; var csCloseFontWeight = 'bold'; var csCloseDecoration = 'none'; var csNavFontType = 'Arial'; var csNavFontSize = '14px'; var csNavFontWeight = 'bold'; var csNavColor = 'black'; var csNavDecoration = 'none'; var navSelBorder = '1px solid white'; var csDMFontType = 'Verdana'; var csDMFontSize = '14px'; var csDMFontWeight = 'normal'; var csDMcolor = 'black'; var csRowBackground = '#CACACA'; //var csAlterRowBackground = '#E2E2E2'; var csAlterRowBackground = '#EFEFEF'; var csWeekFontType = 'Verdana'; var csWeekFontSize = '12px'; var csWeekFontWeight = 'bold'; var csWeekColor = '#5B7AAF'; var csWeekDecoration = 'none'; var csDayFontType = 'Verdana'; var csDayFontSize = '12px'; var csDayFontWeight = 'normal'; var csDayColor = '#003366'; var csDayDecoration = 'none'; function getLeft(imgElem) { xPos = eval(imgElem).offsetLeft; tempEl = eval(imgElem).offsetParent; while (tempEl != null) { xPos += tempEl.offsetLeft; tempEl = tempEl.offsetParent; } return xPos; } function getTop(imgElem) { yPos = eval(imgElem).offsetTop; tempEl = eval(imgElem).offsetParent; while (tempEl != null) { yPos += tempEl.offsetTop; tempEl = tempEl.offsetParent; } return yPos; } function getParsedDate(val,returnTimestamp) { if (useTimestamp) { d = new Date(val * 1000); } else { res = /^(\d{4})[\.\-\/]{1}(\d{1,2})[\.\-\/]{1}(\d{1,2})$/.exec(val); if(res && (res.length > 1)){ dDay = parseInt(res[3].replace(/^0/,'')); dMonth = parseInt(res[2].replace(/^0/,'')); dMonth = dMonth - 1; dYear = parseInt(res[1]); d = new Date(dYear,dMonth,dDay); } } if (returnTimestamp) { return d.getTime(); } return d; } function setParsedDate(tempDate) { dd = tempDate.getDate(); dd = dd < 10 ? '0' + dd : dd; tempDateStr = shortDateMask.replace(/d/,dd); mm = tempDate.getMonth() + 1; mm = mm < 10 ? '0' + mm : mm; yyyy = tempDate.getFullYear(); tempDateStr = tempDateStr.replace(/m/,mm); tempDateStr = tempDateStr.replace(/Y/,yyyy); curField.value = yyyy + '-' + mm + '-' + dd; curObj.innerHTML = tempDateStr; } function startGoto(uid,timestampuid,objuid) { curField = document.getElementById(timestampuid); curObj = document.getElementById(objuid); startDate = getParsedDate(curField.value); openGoto(getParsedDate(curField.value,true),uid,'#','#'); } function startLinkedGoto(uid,timestamp,objimg,url) { layObj = document.getElementById(uid); imgObj = document.getElementById(objimg); layObj.style.left = getLeft(imgObj) + 'px'; layObj.style.top = getTop(imgObj) + 'px'; startDate = getParsedDate(timestamp); openGoto(getParsedDate(timestamp,true),uid,url,'#'); } function startGotoShift(uid,timestampuid,objuid,objimg) { layObj = document.getElementById(uid); imgObj = document.getElementById(objimg); layObj.style.left = getLeft(imgObj) + 'px'; layObj.style.top = getTop(imgObj) + 'px'; curField = document.getElementById(timestampuid); curObj = document.getElementById(objuid); startDate = getParsedDate(curField.value); openGoto(getParsedDate(curField.value,true),uid,'#','#'); } function startGotoShiftPlus(uid,timestampuid,objuid,objimg,horShift,verShift) { layObj = document.getElementById(uid); imgObj = document.getElementById(objimg); layObj.style.left = getLeft(imgObj) + horShift + 'px'; layObj.style.top = getTop(imgObj) + verShift + 'px'; curField = document.getElementById(timestampuid); curObj = document.getElementById(objuid); startDate = getParsedDate(curField.value); openGoto(getParsedDate(curField.value,true),uid,'#','#'); } function startWeekGoto(uid,startTimestampuid,startObjuid, endTimestampuid,endObjuid) { startField = document.getElementById(startTimestampuid); startObj = document.getElementById(startObjuid); endField = document.getElementById(endTimestampuid); endObj = document.getElementById(endObjuid); startDate = getParsedDate(curField.value); openGoto(getParsedDate(curField.value,true),uid,'#','#',true); } function weekOfYear(d) { var year = d.getYear() if (year < 1900) { year += 1900; } var firstday = new Date(year, 0, 1); var firstwday = 8 - firstday.getDay(); if (firstwday == 8) { firstwday = 1; } else if (firstwday > 4) { firstwday -= 7; } var dayofyear = (d - firstday.getTime() + 86400000) / 86400000; if (dayofyear < firstwday) { return weekOfYear(new Date(year - 1, 12, 31)); } else { return Math.floor((dayofyear - firstwday) / 7) + 1; } } function getWeekPeriod(d) { timestamp = d.getTime() / 1000; weekDay = d.getDay(); //alert(d); if(weekDay == 0) { if(weekStart == 'Mo') { return new Array((timestamp - 518400),timestamp); } return new Array(timestamp, (timestamp + 518400)); } if(weekDay == 6) { if( weekStart == 'Mo') { return new Array((timestamp - 432000), (timestamp + 86400)); } return new Array((timestamp - 518400),timestamp); } if(weekStart == 'Mo') { return new Array((timestamp - ((weekDay - 1) * 86400)),(timestamp + (7 - weekDay) * 86400)); } return new Array((timestamp - (weekDay * 86400)),(timestamp + (6 - weekDay) * 86400)); } function openGoto(timestamp,uid,dayUrl,monthUrl,showWeeks,noScrollTo) { var row, cell, img, link, days; var rowSpan; var week,bold; var d; rowSpan = (showWeeks == true) ? 8 : 7; var scrollNow = noScrollTo ? false : true; if(timestamp == 0) { d = new Date(); } else { d = new Date(timestamp); } currentDate = d; var month = d.getMonth(); var year = d.getYear(); if (year < 1900) { year += 1900; } currentYear = year; var firstOfMonth = new Date(year, month, 1); var diff = firstOfMonth.getDay()- ((weekStart == 'Mo') ? 1 : 0); if (diff == -1) diff = 6; switch (month) { case 3: case 5: case 8: case 10: days = 30; break; case 1: if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) { days = 29; } else { days = 28; } break; default: days = 31; break; } var wdays = new Array(); if (weekStart == 'Mo') { wdays = ['Mo','Tu','We','Th','Fr','Sa','Su']; } else { wdays = ['Su','Mo','Tu','We','Th','Fr','Sa']; } var months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; var lay = document.getElementById(uid); if (lay.firstChild) { lay.removeChild(lay.firstChild); } var table = document.createElement('TABLE'); var tbody = document.createElement('TBODY'); table.style.fontSize = csFontSize; table.style.fontFamilyName = csFontType; table.style.width = csTableWidth; table.style.backgroundColor = csTableBackground; table.cellSpacing = csTableCellSpacing; table.appendChild(tbody); //var prevTxt = '<<'; //var nextTxt = '>>'; var prevTxt = '«'; var nextTxt = '»'; // title bar row = document.createElement('TR'); cell = document.createElement('TD'); cell.colSpan = rowSpan; cell.align = 'right'; cell.style.backgroundColor = csTitleBackground; link = document.createElement('A'); link.href = 'javascript:;'; link.onclick = function() { document.getElementById(uid).style.visibility = 'hidden'; return false; } link.innerHTML = 'x'; link.style.color = csCloseColor; link.style.fontFamilyName = csCloseFontType; link.style.fontSize = csCloseFontSize; link.style.fontWeight = csCloseFontWeight; link.style.textDecoration = csCloseDecoration; cell.appendChild(link); row.appendChild(cell); tbody.appendChild(row); // year and month select row = document.createElement('TR'); cell = document.createElement('TD'); cell.align = 'center'; cell.valign = 'middle'; cell.style.padding = '1 4 1 4'; cell.colSpan = rowSpan; link = document.createElement('A'); link.href = 'javascript:;'; link.style.fontFamilyName = csNavFontType; link.style.fontSize = csNavFontSize; link.style.fontWeight = csNavFontWeight; link.style.color = csNavColor; link.style.textDecoration = csNavDecoration; link.onclick = function() { newDate = new Date(currentYear, currentDate.getMonth() - 1, currentDate.getDate()); openGoto((newDate.getTime()),uid,dayUrl,monthUrl,showWeeks,noScrollTo); } link.innerHTML = prevTxt; cell.appendChild(link); span = document.createElement('SPAN'); span.innerHTML = '  '; cell.appendChild(span); /* link = document.createElement('A'); link.href = 'javascript:;'; link.style.fontFamilyName = csNavFontType; link.style.fontSize = csNavFontSize; link.style.fontWeight = csNavFontWeight; link.style.color = csNavColor; link.style.textDecoration = csNavDecoration; link.onclick = function() { newDate = new Date(currentYear - 1, currentDate.getMonth(), currentDate.getDate()); openGoto((newDate.getTime()),uid,dayUrl,monthUrl,showWeeks,noScrollTo); } link.innerHTML = prevTxt; //cell.appendChild(link); span = document.createElement('SPAN'); span.style.fontFamilyName = csDMFontType; span.style.fontSize = csDMFontSize; span.style.fontWeight = csDMFontWeight; span.style.color = csDMcolor; //span.innerHTML = year; */ sel = document.createElement('SELECT'); for(i = (year - 5); i <= (year+6); i++) { opt = document.createElement('OPTION'); opt.innerHTML = i; opt.value = i; if(i == year) { opt.selected = true; } sel.appendChild(opt); } sel.onchange = function() { newDate = new Date(this.options[this.selectedIndex].value, currentDate.getMonth(), currentDate.getDate()); openGoto((newDate.getTime()),uid,dayUrl,monthUrl,showWeeks,noScrollTo); } cell.appendChild(sel); /* link = document.createElement('A'); link.href = 'javascript:;'; link.style.fontFamilyName = csNavFontType; link.style.fontSize = csNavFontSize; link.style.fontWeight = csNavFontWeight; link.style.color = csNavColor; link.style.textDecoration = csNavDecoration; link.onclick = function() { newDate = new Date(currentYear + 1, currentDate.getMonth(), currentDate.getDate()); openGoto((newDate.getTime()),uid,dayUrl,monthUrl,showWeeks,noScrollTo); } link.innerHTML = nextTxt; */ //cell.appendChild(link); row.appendChild(cell); /* span = document.createElement('SPAN'); span.innerHTML = '   '; cell.appendChild(span); link = document.createElement('A'); link.href = 'javascript:;'; link.style.fontFamilyName = csNavFontType; link.style.fontSize = csNavFontSize; link.style.fontWeight = csNavFontWeight; link.style.color = csNavColor; link.style.textDecoration = csNavDecoration; link.onclick = function() { newDate = new Date(currentYear, currentDate.getMonth() - 1, 1); openGoto((newDate.getTime()),uid,dayUrl,monthUrl,showWeeks,noScrollTo); } link.innerHTML = prevTxt; //cell.appendChild(link); span = document.createElement('SPAN'); span.align = 'center'; span.style.fontFamilyName = csDMFontType; span.style.fontSize = csDMFontSize; span.style.fontWeight = csDMFontWeight; span.style.color = csDMcolor; //span.innerHTML = months[month]; //cell.appendChild(span); */ sel = document.createElement('SELECT'); for(i = 0; i < 12; i++) { opt = document.createElement('OPTION'); opt.innerHTML = months[i]; opt.value = i; if(i == month) { opt.selected = true; } opt.style.border = navSelBorder; sel.appendChild(opt); } sel.style.border = navSelBorder; sel.onchange = function() { newDate = new Date(currentYear, this.options[this.selectedIndex].value, 1); openGoto((newDate.getTime()),uid,dayUrl,monthUrl,showWeeks,noScrollTo); } cell.appendChild(sel); span = document.createElement('SPAN'); span.innerHTML = '  '; cell.appendChild(span); link = document.createElement('A'); link.href = 'javascript:;'; link.style.fontFamilyName = csNavFontType; link.style.fontSize = csNavFontSize; link.style.fontWeight = csNavFontWeight; link.style.color = csNavColor; link.style.textDecoration = csNavDecoration; link.onclick = function() { newDate = new Date(currentYear, currentDate.getMonth() + 1, 1); openGoto((newDate.getTime()),uid,dayUrl,monthUrl,showWeeks,noScrollTo); } link.innerHTML = nextTxt; cell.appendChild(link); row.appendChild(cell); tbody.appendChild(row); // weekdays row = document.createElement('TR'); row.style.backgroundColor = csRowBackground; for (var i = 0; i < 7; i++) { cell = document.createElement('TD'); cell.align = 'right'; span = document.createElement('SPAN'); span.innerHTML = '' + wdays[i] + ''; //weekday = document.createTextNode(wdays[i]); cell.appendChild(span); row.appendChild(cell); } if (showWeeks) { cell = document.createElement('TD'); row.appendChild(cell); } tbody.appendChild(row); // rows var count = 1; var today = new Date(); var odd = true; for (var i = 1; i <= days; i++) { if (count == 1) { row = document.createElement('TR'); row.align = 'right'; if (odd) { row.style.backgroundColor = csAlterRowBackground; } else { row.style.backgroundColor = csAlterRowBackground; } odd = !odd; } if (i == 1) { for (var j = 0; j < diff; j++) { cell = document.createElement('TD'); row.appendChild(cell); count++; } } cell = document.createElement('TD'); if (today.getYear() == year && today.getMonth() == month && today.getDate() == i) { cell.style.border = '1px solid red'; } if ((startDate.getDate() != today.getDate()) && (startDate.getYear() == year) && (startDate.getMonth() == month) && (startDate.getDate() == i)) { cell.style.border = '1px solid blue'; } if(showWeeks) { cell.appendChild(document.createTextNode(i)); } else { link = document.createElement('A'); link.style.fontFamilyName = csDayFontType; link.style.fontSize = csDayFontSize; link.style.fontWeight = csDayFontWeight; link.style.color = csDayColor; link.style.textDecoration = csDayDecoration; if (curField == null) { link.href = dayUrl + (new Date(year,month,i).getFullYear() + '-' + ((new Date(year,month,i).getMonth())+1) + '-' + i); } else { link.href = "#"; link.onclick = function() { tempDate = new Date(year,month,this.innerHTML); setParsedDate(tempDate); /* dd = tempDate.getDate(); dd = dd < 10 ? '0' + dd : dd; tempDateStr = shortDateMask.replace(/d/,dd); mm = tempDate.getMonth() + 1; mm = mm < 10 ? '0' + mm : mm; tempDateStr = tempDateStr.replace(/m/,mm); tempDateStr = tempDateStr.replace(/Y/,tempDate.getFullYear()); curField.value = tempDate.getTime() / 1000; curObj.innerHTML = tempDateStr; */ curField = null; document.getElementById(uid).style.visibility = 'hidden'; return false; } } cell.appendChild(link); day = document.createTextNode(i); link.appendChild(day); } row.appendChild(cell); if ((i == days) && (count >= 1)) { for (k = count; k < 7; k++) { cell = document.createElement('TD'); row.appendChild(cell); } tbody.appendChild(row); } if (showWeeks && ((count == 7) || (i == days))) { cell = document.createElement('TD'); cell.style.width = '40px'; cell.align = 'center'; week = weekOfYear(new Date(year, month, i)); bold = document.createElement('B'); cell.appendChild(bold); link = document.createElement('A'); link.href = "#"; weekPeriodArray = getWeekPeriod(new Date(year,month,i)); link.weekStart = weekPeriodArray[0]; link.weekEnd = weekPeriodArray[1]; link.onclick = function() { startField.value = this.weekStart; tempDate = new Date(this.weekStart * 1000); tempDateStr = shortDateMask.replace(/d/,tempDate.getDate()); tempDateStr = tempDateStr.replace(/m/,(tempDate.getMonth() + 1)); tempDateStr = tempDateStr.replace(/Y/,tempDate.getFullYear()); startObj.innerHTML = tempDateStr; endField.value = this.weekEnd; tempDate = new Date(this.weekEnd * 1000); tempDateStr = shortDateMask.replace(/d/,tempDate.getDate()); tempDateStr = tempDateStr.replace(/m/,(tempDate.getMonth() + 1)); tempDateStr = tempDateStr.replace(/Y/,tempDate.getFullYear()); endObj.innerHTML = tempDateStr; document.getElementById(uid).style.visibility = 'hidden'; return false; } bold.appendChild(link); link.appendChild(document.createTextNode(week)); row.appendChild(cell); } if (count == 7) { tbody.appendChild(row); count = 0; } count++; } if (count > 1) { tbody.appendChild(row); } // show Layer lay.appendChild(table); lay.style.visibility = 'visible'; //lay.style.visibility = ''; if (scrollNow) { //lay.scrollIntoView(); lay.focus(); } }