//import Calendar.css // gouse changed to modify regional wise color themes s //includeStyle("/theme/Calendar.css"); var sRegCntCd = regCntyCD; if (typeof(sRegCntCd)!="undefined"){ if(sRegCntCd.length > 0){ includeStyle("/theme/" + regCntyCD + "/Calendar.css"); }else{ includeStyle("/theme/Calendar.css"); } }else{ includeStyle("/theme/Calendar.css"); } // gouse changed to modify regional wise color themes e /** * Global Calendar variables */ Calendar.offsetY = 1; Calendar.offsetX = 0; //Calendar.todayText = "Today";//today button value //Calendar.buttonTitle = "Pick a Date";//today button title Calendar.todayText = typeof(sTodayText) != 'undefined' ? sTodayText : "Today"; Calendar.buttonTitle = typeof(sButtonTitle) != 'undefined' ? sButtonTitle : "Pick a Date"; Calendar.prevYearText = typeof(sPrevYearText) != 'undefined' ? sPrevYearText : "Prev"; Calendar.nextYearText = typeof(sNextYearText) != 'undefined' ? sNextYearText : "Next"; Calendar.prevText = typeof(sPrev) != 'undefined' ? sPrev : "Prev"; Calendar.nextText = typeof(sNext) != 'undefined' ? sNext : "Next"; Calendar.buttonOffsetX = 0; // See below for some considerations about Calendar.buttonOffsetY = 0; // that values (for IE) Calendar.closeOnTodayBtn = true; // close if today button is pressed? Calendar.defaultTodaySel = true; // If true and content is blank, today date will be selected Calendar.firstWeekDay = 0; // First day of week: 0=Sunday, 1=Monday, ..., 6=Saturday Calendar.weekend = [0,6]; // Sunday and Saturday as weekend Calendar.weekNumber = false; // Display or not the week number Calendar.autoShow = false; // Auto show the calendar when the input grab the focus. Calendar.Months = typeof(aCalendarMon) != 'undefined' ? aCalendarMon : ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; Calendar.Days = typeof(aCalendarWeek) != 'undefined' ? aCalendarWeek : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; Calendar.useTrickyBG = false; //FOR IE if (navigator.userAgent.indexOf("MSIE") > 1){ Calendar.useTrickyBG = true; Calendar.offsetY = 0; Calendar.offsetX = -1; Calendar.buttonOffsetX = -4; Calendar.buttonOffsetY = -2; } /** * Calendar constants */ Calendar.hideCauseBlur = false; // Was the calendar close by onblur event? Calendar.hideTimeout = null; // The timeout identifier Calendar.HIDE_TIMEOUT = 200; // Time in ms for hide the calendar layer Calendar.displayed = false; // Is the calendar layer displayed? Calendar.buttonIdPrefix = "ICO_"; // The prefix for the calendar button's id Calendar.dayIdPrefix = "CALDAY"; // The prefix for the calendar days frames' id Calendar.currentDay = 1; // The current day of current month of current year Calendar.originalValue = ""; // The original value of edit control Calendar.calFrameId = "calendarframe"; // The id for the calendar layer Calendar.dayOfWeek = 0; // The current day of current week ... Calendar.firstFocused = false; // Is the first time that the current edit control is focused? Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; // Non-leap year month days Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; // Leap year month days //CEV2-07-01-10 jason.zhang 2015-04-13 start Calendar.initCalenSucc = false; //CEV2-07-01-10 jason.zhang 2015-04-13 end /** * Constructor */ function Calendar() { //NOT BEING USED NOW } /** * Creates the calendar's div element and the button into the input-texts with */ Calendar.init = function() { // try to create the Calendar.container: if (!document.getElementById("CalendarMain")){ this.calBG = null; if (this.useTrickyBG){ // Creates a tricky bg to hide the select controls (IE bug). // We use a iframe element, because is one of the elements that can // stay on top of select controls. this.calBG = document.createElement("iframe"); this.calBG.id = "CalendarMainBG"; this.calBG.style.zIndex = "49999"; // below calcontainer this.calBG.style.position = "absolute"; this.calBG.style.display = "none"; this.calBG.style.border = "0px solid transparent"; this.calBG.src = "../screen/SYS_Dummy.htm"; document.body.appendChild(this.calBG); } this.calContainer = document.createElement("div"); this.calContainer.id = "CalendarMain"; this.calContainer.style.zIndex = "50000"; this.calContainer.style.position = "absolute"; this.calContainer.style.display = "none"; document.body.appendChild(this.calContainer); } // looking for input controls that will be transformed into Calendar's. var inputControls = document.getElementsByTagName("input"); var inputsLength = inputControls.length; for (i=0; i"; vCode += this.getHeaderCode(); vCode += this.getDaysHeaderCode(); vCode += this.getDaysCode(); vCode += ""; return vCode; } /** * The title and nav buttons */ Calendar.getHeaderCode = function() { var prevMMYYYY = this.calcMonthYear(this.month, this.year, -1); var prevMM = prevMMYYYY[0]; var prevYYYY = prevMMYYYY[1]; var nextMMYYYY = this.calcMonthYear(this.month, this.year, 1); var nextMM = nextMMYYYY[0]; var nextYYYY = nextMMYYYY[1]; var gNow = new Date(); var vCode = ""; var numberCols = this.weekNumber ? 8 : 7; vCode += ""; //vCode += this.monthName + "  "; vCode += "« " + this.prevYearText + ""; vCode += "   " + this.year + "  " + this.monthName + "   "; vCode += "" + this.nextYearText + " »"; vCode += ""; vCode += ""; vCode += ""; vCode += ""; vCode += ""; vCode += ""; vCode += "
<< " + this.prevText + ""; vCode += this.todayText + "" + this.nextText + " >>
"; vCode += ""; return vCode; } /** * The days' name headers */ Calendar.getDaysHeaderCode = function() { var vCode = ""; vCode = vCode + ""; if (this.weekNumber){ vCode += " " } for (i=this.firstWeekDay; i" + this.Days[i % 7] + ""; } vCode = vCode + ""; return vCode; } /** * The days numbers code */ Calendar.getDaysCode = function() { var vDate = new Date(); vDate.setDate(1); vDate.setMonth(this.month); vDate.setFullYear(this.year); var vFirstDay = vDate.getDay(); var vDay = 1; var vLastDay = this.getDaysOfMonth(this.month, this.year); var vOnLastDay = 0; var vCode = ""; this.dayOfWeek = vFirstDay; var prevm = this.month == 0 ? 11 : this.month-1; var prevy = this.prevm == 11 ? this.year - 1 : this.year; prevmontdays = this.getDaysOfMonth(prevm, prevy); vFirstDay = (vFirstDay == 0 && this.firstWeekDay) ? 7 : vFirstDay; if (this.weekNumber){ var week = this.getWeekNumber(this.year, this.month, 1); } vCode += ""; if (this.weekNumber){ vCode += "" + week + ""; } // Write the last days of previous month for (i=this.firstWeekDay; i" + (prevmontdays-vFirstDay+i+1) + ""; //vCode = vCode + "" + (prevmontdays-vFirstDay+i+1) + ""; //End } // Write rest of the 1st week for (j=vFirstDay-this.firstWeekDay; j<7; j++) { classname = this.getDayClass(vDay, j); vCode += "" + vDay + ""; vDay++; } vCode = vCode + ""; // Write the rest of the weeks for (k=2; k<7; k++){ vCode = vCode + ""; if (this.weekNumber){ week++; if (week >= 53) week = 1; vCode += "" + week + ""; } for (j=0; j<7; j++){ classname = this.getDayClass(vDay, j); vCode += "" + vDay + ""; vDay++; if (vDay > vLastDay){ vOnLastDay = 1; break; } } if (j == 6) vCode += ""; if (vOnLastDay == 1) break; } // Fill up the rest of last week for (m=1; m<(7-j); m++){ //Martin.Yin modify for calendar support last week 20120524S //vCode += "" + m + ""; vCode += "" + m + ""; //End } return vCode; } /** * Get the class according if is 'today', the 'current' date at the control, * a 'weekend' day, or a 'normal' day. * @param vday The number of the day in the current month and year * @param dayofweek The number of the day within the week (0..6) */ Calendar.getDayClass = function(vday, dayofweek) { var gNow = new Date(); var vNowDay = gNow.getDate(); var vNowMonth = gNow.getMonth(); var vNowYear = gNow.getFullYear(); if (vday == vNowDay && this.month == vNowMonth && this.year == vNowYear){ return "today"; } else{ // transform the day acording the specified firts day of week var realdayofweek = (7 + dayofweek + this.firstWeekDay) % 7; for (i=0; i1){ if("first"==monthStatus){ if(vMonth==1){ vY4 = new String(this.year-1); vMonth = 12; }else{ vMonth = vMonth-1; } }else if("last"==monthStatus){ if(vMonth==12){ vY4 = new String(this.year+1); vMonth = 1; }else{ vMonth = vMonth+1; } } } var vData; //var vMonth = 1 + this.month; vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth; var vMon = this.getMonthName(this.month).substr(0,3).toUpperCase(); var vFMon = this.getMonthName(this.month).toUpperCase(); //var vY4 = new String(this.year); vY2 = vY4.substr(2,2); //End Martin var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day; switch (this.format) { case "MM/DD/YYYY" : vData = vMonth + "/" + vDD + "/" + vY4; break; case "MM/DD/YY" : vData = vMonth + "/" + vDD + "/" + vY2; break; case "MM-DD-YYYY" : vData = vMonth + "-" + vDD + "-" + vY4; break; case "MM-DD-YY" : vData = vMonth + "-" + vDD + "-" + vY2; break; case "YYYY-MM-DD": vData = vY4 + "-" + vMonth + "-" + vDD; break; case "YYYY/MM/DD": vData = vY4 + "/" + vMonth + "/" + vDD; break; case "DD/MON/YYYY" : vData = vDD + "/" + vMon + "/" + vY4; break; case "DD/MON/YY" : vData = vDD + "/" + vMon + "/" + vY2; break; case "DD-MON-YYYY" : vData = vDD + "-" + vMon + "-" + vY4; break; case "DD-MON-YY" : vData = vDD + "-" + vMon + "-" + vY2; break; case "DD/MONTH/YYYY" : vData = vDD + "/" + vFMon + "/" + vY4; break; case "DD/MONTH/YY" : vData = vDD + "/" + vFMon + "/" + vY2; break; case "DD-MONTH-YYYY" : vData = vDD + "-" + vFMon + "-" + vY4; break; case "DD-MONTH-YY" : vData = vDD + "-" + vFMon + "-" + vY2; break; case "DD/MM/YYYY" : vData = vDD + "/" + vMonth + "/" + vY4; break; case "DD/MM/YY" : vData = vDD + "/" + vMonth + "/" + vY2; break; case "DD-MM-YYYY" : vData = vDD + "-" + vMonth + "-" + vY4; break; case "DD-MM-YY" : vData = vDD + "-" + vMonth + "-" + vY2; break; case "DD.MM.YYYY" : vData = vDD + "." + vMonth + "." + vY4; break; case "DD.MM.YY" : vData = vDD + "." + vMonth + "." + vY2; break; default : vData = vMonth + "/" + vDD + "/" + vY4; } return vData; } Calendar.getDateFromControl = function(ctrl) { if (ctrl == null) ctrl = this.inputControl; var value = ctrl.value; //binding CE date format var format = SYS_BU_DATE_FORMAT.toUpperCase(); return this.getDateFromString(value, format.toString()); } /** * Gets a Date objects from a string given a format. * @param strdate The string with the date. * @param format The date's format. * @return A Date object with the date of string according to the format, or * today if string is empty or non-valid. */ Calendar.getDateFromString = function(strdate, format) { var aDate = new Date(); var day, month, year; if (strdate == "" || format == "") return aDate; strdate = strdate.replace("/", "@").replace("/", "@"); strdate = strdate.replace("-", "@").replace("-", "@"); strdate = strdate.replace(".", "@").replace(".", "@"); // check again if (strdate.indexOf("/")>=0 || strdate.indexOf("-")>=0 || strdate.indexOf(".")>=0) return aDate; // validate all other stuff var data = strdate.split("@"); if (data.length != 3) return aDate; for (i=0; i<3; i++){ data[i] = parseFloat(data[i]); if (isNaN(data[i])) return aDate; } aDate.setDate(1); if (format.substring(0,1).toUpperCase() == "D"){ aDate.setFullYear(this.yearTwo2Four(data[2])); aDate.setMonth(data[1]-1); aDate.setDate(data[0]); } else if (format.substring(0,1).toUpperCase() == "Y"){ aDate.setFullYear(this.yearTwo2Four(data[0])); aDate.setMonth(data[1]-1); aDate.setDate(data[2]); } else if (format.substring(0,1).toUpperCase() == "M"){ aDate.setFullYear(this.yearTwo2Four(data[2])); aDate.setMonth(data[0]-1); aDate.setDate(data[1]); } return aDate; } /** * Transform a two digits year into a four digits year. * All year from 30 to 99 are trated as 19XX, year before * 30 are trated as 20XX */ Calendar.yearTwo2Four = function(year) { if (year < 99){ if (year >= 30){ year += 1900; } else{ year += 2000; } } return year; } /** * Writes the specified date in the control and close the calendar. */ Calendar.writeDate = function(day,monStatus) { //Martin add 20120524S var argsLen = Calendar.writeDate.arguments.length; var d; if(argsLen>1){ d = this.formatData(day,monStatus); }else{ d = this.formatData(day); } //var d = this.formatData(day); //End Martin.Yin this.inputControl.value = d; this.originalValue = d; this.hide(); if (Calendar.onSelect) Calendar.onSelect(this.inputControl.id); this.firstFocused = true; this.inputControl.focus(); fireObjEvent(this.inputControl,"onchange"); } /** * Writes the current date in the control */ Calendar.writeCurrentDate = function() { var d = this.formatData(this.currentDay); this.inputControl.value = d; } /** * Creates and write the calendar's code * @param m The month to build * @param y The year to build */ Calendar.build = function(m, y) { var bkm = this.month; var bky = this.year; var calframe = document.getElementById(this.calFrameId); if (m==null){ var now = new Date(); this.month = now.getMonth(); this.year = now.getFullYear(); } else{ this.month = m; this.year = y; } this.monthName = this.Months[this.month]; var code = this.getAllCode(); writeLayer(this.calContainer.id, null, code); if (this.calContainer && calframe) this.calContainer.style.height = calframe.offsetHeight; this.firstFocused = true; this.inputControl.focus(); this.selectDay(this.currentDay); } /** * Today button action */ Calendar.selectToday = function() { var now = new Date(); var today = now.getDate(); if (this.closeOnTodayBtn){ this.currentDay = today; this.writeDate(this.currentDay); } else{ this.selectDay(today); } } /** * Select a specific day */ Calendar.selectDay = function(day) { if (!this.displayed) return; var n = this.currentDay; var max = this.getDaysOfMonth(this.month, this.year); if (day > max) return; var newDayObject = document.getElementById(this.dayIdPrefix+day); var currentDayObject = document.getElementById(this.dayIdPrefix+this.currentDay); if (currentDayObject){ currentDayObject.className = currentDayObject.getAttribute("class_orig"); } if (newDayObject){ newDayObject.className = "current"; this.currentDay = day; this.writeCurrentDate(); } } /** * Select the prev week day * @param decr Use 1 for yesterday or 7 for prev week */ Calendar.selectPrevDay = function(decr) { if (!this.displayed) return; var n = this.currentDay; var max = this.getDaysOfMonth(this.month, this.year); var prev = n - decr; if ( prev <= 0 ){ if (decr == 7){ n = (n + this.dayOfWeek) + 28 - this.dayOfWeek; n--; prev = n > max ? n-7 : n; } else{ prev = max; } } this.selectDay(prev); } /** * Select the next week day * @param decr Use 1 for tomorrow or 7 for next week */ Calendar.selectNextDay = function(incr) { if (!this.displayed) return; var n = this.currentDay; var max = this.getDaysOfMonth(this.month, this.year); var next = n + incr; if ( next > max ){ if (incr == 7){ n = ((n + this.dayOfWeek) % 7) - this.dayOfWeek; next = n < 0 ? n+7 : n; next++; } else{ next = 1; } } this.selectDay(next); } /** * Show the calendar for an edit control */ Calendar.showForEdit = function(edit) { if (this.displayed) return; if (edit == null) return; if (edit.disabled) return; this.inputControl = edit; this.originalValue = edit.value; //binding CE date format var format = SYS_BU_DATE_FORMAT.toUpperCase(); this.format = format; // build with the current date in the control? if (this.validate(edit.value, format)){ var date = this.getDateFromControl(); this.currentDate = date; this.build(date.getMonth(), date.getFullYear()); this.currentDay = date.getDate(); } else{ edit.value = ""; this.originalValue = ""; this.currentDate = null; if (this.defaultTodaySel){ this.currentDay = new Date().getDate(); } else{ //this.currentDay = 1; } this.build(null, null); } var currentDayObject = document.getElementById(this.dayIdPrefix+this.currentDay); if (currentDayObject) currentDayObject.className = "current"; this.writeCurrentDate(); // and finally this.show(); } /** * Validate a string according to a date format. * @param strdate The string with the date. * @param format The format to validate. * @return true if succesfull or false otherwise */ Calendar.validate = function(strdate, format) { var dateRegExp; var separator; var d, m, y; var od = this.currentDay, om = this.month, oy = this.year; if (strdate == "") return false; // use the correct regular expresion... if (format.substring(0,1).toUpperCase() == "D"){ dateRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2,4}$/ } else if (format.substring(0,1).toUpperCase() == "Y"){ dateRegExp = /^\d{2,4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/ } else if (format.substring(0,1).toUpperCase() == "M"){ dateRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2,4}$/ } // is ok at least with the format? if (!dateRegExp.test(strdate)){ return false; } // chek for a valid day month day combination separator = (strdate.indexOf("/") > 1) ? "/" : ((strdate.indexOf("-") > 1) ? "-" : "."); var datearray = strdate.split(separator); // get the number of date elements if (format.substring(0,1).toUpperCase() == "D"){ d = parseFloat(datearray[0]); m = parseFloat(datearray[1]); y = parseFloat(datearray[2]); } else if (format.substring(0,1).toUpperCase() == "Y"){ d = parseFloat(datearray[2]); m = parseFloat(datearray[1]); y = parseFloat(datearray[0]); } else if (format.substring(0,1).toUpperCase() == "M"){ d = parseFloat(datearray[1]); m = parseFloat(datearray[0]); y = parseFloat(datearray[2]); } // is a valid month? if (m<1 || m>12) return false; //check if month value and day value agree if (d > this.getDaysOfMonth(m-1, y)) return false; return true; } /** * Check if a year is leap: * 1.Years evenly divisible by four are normally leap years, except for... * 2.Years also evenly divisible by 100 are not leap years, except for... * 3.Years also evenly divisible by 400 are leap years. * @return true if the year is leap or false otherwise. */ Calendar.isLeapYear = function(year) { if ((year % 4) == 0){ if ((year % 100) == 0 && (year % 400) != 0){ return false; } return true; } return false; } /** * Click event for calendar button */ function showCalendar(event){ //remove error cell if needed rmNode("Template_valSummary"); Calendar.onButtonClick(event); } Calendar.onButtonClick = function(event) { if (!this.displayed){ // get the button if (event == null) event = window.event; var button = (event.srcElement) ? event.srcElement : event.originalTarget; // gets the associated input: var input = document.getElementById(button.getAttribute("dateField_inputid")); this.showForEdit(input); } else{ this.hide(); } } /** * Gets the number of the week on the year for the given year, month, day. */ Calendar.getWeekNumber = function(year, month, day) { var when = new Date(year,month,day); var newYear = new Date(year,0,1); var offset = 7 + 1 - newYear.getDay(); if (offset == 8) offset = 1; var daynum = ((Date.UTC(y2k(year),when.getMonth(),when.getDate(),0,0,0) - Date.UTC(y2k(year),0,1,0,0,0)) /1000/60/60/24) + 1; var weeknum = Math.floor((daynum-offset+7)/7); if (weeknum == 0) { year--; var prevNewYear = new Date(year,0,1); var prevOffset = 7 + 1 - prevNewYear.getDay(); if (prevOffset == 2 || prevOffset == 8) weeknum = 53; else weeknum = 52; } return weeknum; } function y2k(number) { return (number < 1000) ? number + 1900 : number; } function getObject(sId) { if (bw.dom){ this.hElement = document.getElementById(sId); this.hStyle = this.hElement.style; } else if (bw.ns4){ this.hElement = document.layers[sId]; this.hStyle = this.hElement; } else if (bw.ie){ this.hElement = document.all[sId]; this.hStyle = this.hElement.style; } } getObject.getSize = function(sParam, hLayer) { nPos = 0; while ((hLayer.tagName) && !( /(body|html)/i.test(hLayer.tagName))){ nPos += eval("hLayer." + sParam); if (sParam == "offsetTop"){ if (hLayer.clientTop){ nPos += hLayer.clientTop; } } if (sParam == "offsetLeft"){ if (hLayer.clientLeft){ nPos += hLayer.clientLeft; } } hLayer = hLayer.offsetParent; } return nPos; } function writeLayer(ID, parentID, sText) { if (document.layers){ var oLayer; if(parentID){ oLayer = eval("document." + parentID + ".document." + ID + ".document"); } else{ oLayer = document.layers[ID].document; } oLayer.open(); oLayer.write(sText); oLayer.close(); } else if(document.all){ document.all[ID].innerHTML = sText; } else{ document.getElementById(ID).innerHTML = sText; } } /** * Key-up event for for date field */ function onDateFieldKeyUp(event){Calendar.onFieldKeyUp(event);} Calendar.onFieldKeyUp = function(event) { if (event == null) event = window.event; var edit = event.srcElement ? event.srcElement : event.originalTarget; //gouse for protected date field changing issue s 28-02-2017 if(edit.readOnly){ return false; } //gouse for protected date field changing issue e 28-02-2017 var kc = event.charCode ? event.charCode : event.which ? event.which : event.keyCode; //alert(event.keyCode); switch (kc){ case 37: // left arrow key this.selectPrevDay(1); break; case 38: // up arrow key this.selectPrevDay(7); break; case 39: // right arrow key this.selectNextDay(1); break; case 40: // down arrow key if (!this.displayed){ this.showForEdit(edit); } else{ this.selectNextDay(7); break; } break; case 27: // escape key this.hide(); break; } return false; } /** * Blur event for date field */ function onDateFieldBlur(event){Calendar.onFieldBlur(event);} Calendar.onFieldBlur = function(event) { if (event == null) event = window.event; if (!this.hideTimeout){ this.hideTimeout = setTimeout("Calendar.hide()", this.HIDE_TIMEOUT); } this.firstFocused = false; this.hideCauseBlur = true; } /** * Focus event for date field */ function onDateFieldFocus(event){Calendar.onFieldFocus(event);} Calendar.onFieldFocus = function(event) { if (event == null) event = window.event; var edit = (event.srcElement) ? event.srcElement : event.originalTarget; this.inputControl = edit; this.originalValue = edit.value; if ((!this.displayed || this.hideCauseBlur) && this.autoShow && !this.firstFocused){ clearTimeout(this.hideTimeout); this.hideTimeout = null; this.firstFocused = true; if (this.hideCauseBlur){ this.hideCauseBlur = false; this.hide(); } this.showForEdit(edit); } else if (this.inputControl && this.inputControl.id != edit.id){ this.hide(); } else if (this.hideTimeout){ clearTimeout(this.hideTimeout); this.hideTimeout = null; } }