// $RCSfile: popupcalendarfunctions.js,v $ $Revision: 1.2 $ //************************************************************************ // Global variables //************************************************************************ var calendarWindow; //************************************************************************ // Function: getCalendarCtrlString // Purpose: Return the appropriate localized calendar control string. // (eg: prev, cancel, next). // Input: stringID - Control string to return. // language - language used by the WEB page. // locale - locale used by the WEB page. // Output: String containing the Calendar Control string. //************************************************************************ var CALCTRLSTR_NEXT = 0; var CALCTRLSTR_PREV = 1; var CALCTRLSTR_CNCL = 2; function getCalendarCtrlString (stringID, language, locale) { // var enCalendarCtrlStrings = new Array ("Next", "Prev", "Close"); // var esCalendarCtrlStrings = new Array ("Después", "Anterior", "Cancelan"); return (calendarCtrlStrings [stringID]); } //************************************************************************ // Function: parseYear // Purpose: Find the index of the year in a HTML SELECT control. // Input: year - year to locate in the control. // inY - the control to search. // Output: Index into the SELECT control. //************************************************************************ function parseYear(year, yearCtrlStr) { var retval=0; var i=0; var formyear=0; for (i=0; i<=5; i++) { eval ("formyear = document.getElementById('" + yearCtrlStr + "').options[" + i + "].text;"); if (year == formyear) { retval=i; break; } } return retval; } //************************************************************************ // Function: nextMonth // Purpose: Increment the month. // Input: month // Output: month + 1 //************************************************************************ function nextMonth (month) { if (month==12) { return 1; } else { return (month+1); } } //************************************************************************ // Function: prevMonth // Purpose: Previous month. // Input: month // Output: month - 1 //************************************************************************ function prevMonth (month) { var prevMonth = (month - 1) if (month==1) { prevMonth = 12; } return prevMonth } //************************************************************************ // Function: changeYear // Purpose: Updates the year if incrementing or decrementing into the // previous or following year. // Input: direction - incrementing or decrementing // month - month that is being updated. // year - current year value. // Output: Updated year. //************************************************************************ function changeYear (direction, month, year) { // increments or decrements month when it goes past Jan or Dec var theYear = year if (direction=='next') { if (month == 12) { theYear = (year + 1) } } if (direction=='prev') { if (month == 1) { theYear = (year - 1) } } return theYear } //************************************************************************ // Function: createCalendar // Purpose: Create the calendar popup. // Input: formStr - HTML name of the form that contains the date controls. // dayCtrlStr - HTML name of the day drop down. // monthCtrlStr - HTML name of the month drop down. // yearCtrlStr - HTML name of the year drop down. // dowCtrlStr - HTML name of the day of week control. // language - language used by the WEB page. // locale - locale used by the WEB page. // callBackFn - JavaScript function to call when closing the calendar. // Output: none //************************************************************************ function createCalendar (formStr, dayCtrlStr, monthCtrlStr, yearCtrlStr, dowCtrlStr, language, locale, callBackFn) { calendarWindow = window.open ('', 'Calendar', 'width=220,height=255,resizable=yes,scrollbars=no'); var mthVal = eval ("parseInt(document.getElementById('" + monthCtrlStr + "').options [document.getElementById('" + monthCtrlStr + "').selectedIndex].value, 10)"); var yearVal = eval ("document.getElementById('" + yearCtrlStr + "').options [document.getElementById('" + yearCtrlStr + "').selectedIndex].value"); generateCalendar (calendarWindow, mthVal, yearVal, formStr, dayCtrlStr, monthCtrlStr, yearCtrlStr, dowCtrlStr, language, locale, callBackFn) } //************************************************************************ // Function: generateCalendar // Purpose: Emit the HTML into the calendar popup window. // Input: target - Target browser window for the calendar. // month - Month of the calendar top create. // year - Year of the calendar to create. // formStr - HTML name of the form that contains the date controls. // dayCtrlStr - HTML name of the day drop down. // monthCtrlStr - HTML name of the month drop down. // yearCtrlStr - HTML name of the year drop down. // dowCtrlStr - HTML name of the day of week control. // language - language used by the WEB page. // locale - locale used by the WEB page. // callBackFn - JavaScript function to call when closing the calendar. // Output: none //************************************************************************ function generateCalendar(target, month, year, formStr, dayCtrlStr, monthCtrlStr, yearCtrlStr, dowCtrlStr, language, locale, callBackFn) { target.document.open() calendar = "Calendar II" calendar +="\n" calendar +="\n" calendar +=" " calendar +="" var mthIdx = month; var endday = getDaysInMonth(mthIdx, year) var index = (mthIdx-1) var goPrevMonth = prevMonth(mthIdx) var goNextMonth = nextMonth(mthIdx) var nextYear = changeYear ('next', parseInt (month, 10), parseInt (year, 10)) var prevYear = changeYear ('prev', parseInt (month, 10), parseInt (year, 10)) // Create the calendar header calendar +=" " calendar +=" " calendar +=" " calendar +=" " calendar +=" " calendar +=" " calendar +=" " calendar +=" " calendar +=" " calendar +=" " calendar +=" " calendar +=" " // Create the days. wholeDate = month + "/01/" + year thedate = new Date(wholeDate) firstDay = thedate.getDay() selectedmonth = mthIdx; var today = new Date(); var thisyear = today.getYear() + 1900; selectedyear = year var lastDay = (endday + firstDay+1) var iRows =0 calendar +=" " for (var i = 1; i < lastDay; i++) { if (i <= firstDay) { calendar +=" " } else { calendar +=" " } if (i % 7 == 0 ) { if (i != lastDay-1) { calendar +=" " iRows = iRows + 1 } else { iRows = iRows } } } calendar +=" " // Create the calendar footer iRows = iRows + 1 calendar +=" " for (var icounter = 1; icounter <= 6-iRows; icounter++) { calendar +=" " } calendar +=" " calendar +="
" calendar +=" <" calendar +=" " calendar += getMonth (mthIdx) + " " + year calendar +=" " calendar +=">
 S M T W T F S
 "+(i-firstDay)+"

       
" + getCalendarCtrlString (CALCTRLSTR_CNCL, language, locale) + "
" target.document.write(calendar); target.document.close(); } //************************************************************************ // Function: closeCalendar // Purpose: Close the calendar and update the parent forms date controls. // Input: day - selected day. // formStr - HTML name of the form that contains the date controls. // dayCtrlStr - HTML name of the day drop down. // monthCtrlStr - HTML name of the month drop down. // yearCtrlStr - HTML name of the year drop down. // dowCtrlStr - HTML name of the day of week control. // language - language used by the WEB page. // locale - locale used by the WEB page. // callBackFn - JavaScript function to call when closing the calendar. // Output: none //************************************************************************ function closeCalendar (day, formStr, dayCtrlStr, monthCtrlStr, yearCtrlStr, dowCtrlStr, language, locale, callBackFn) { // Update the controls. var yrIdx = parseYear (selectedyear, yearCtrlStr); eval ("document.getElementById('" + dayCtrlStr + "').selectedIndex = " + parseInt(day-1, 10)); eval ("document.getElementById('" + monthCtrlStr + "').selectedIndex = " + selectedmonth + "-1"); eval ("document.getElementById('" + yearCtrlStr + "').selectedIndex = " + yrIdx); eval ("document.getElementById('" + dowCtrlStr + "').value = '" + getDayOfWeek (buildCRSDate (selectedyear, selectedmonth, day)) + "'"); // Call the callback function. eval (callBackFn); if(dayCtrlStr == "DATERANGESTART_DAY") { updateSTART_DATE('','',''); updateDATES('','','',-1); } else { updateDATES('','','',-1); } }