LANSA for the WEB Component S_171ACALENDAR
<script language="JavaScript">
//************************************************//
// Default it to 1 if this is NULL
// Date Format 1 - YYYY/MM/DD
// Date Format 2 - MM/DD/YYYY
// Date Format 3 - DD/MM/YYYY
// Date Format 4 - DD/MM/YY
// Date Format 5 - MM/DD/YY
// Date Format 6 - YY/MM/DD
//************************************************//
var DateFormat;
var FieldName = "";
function isBrowserSupp() {
// Get the version of the browser
version = parseFloat( navigator.appVersion );
if ( ( version >= 2.0 ) && ( version < 2.1 ) && ( navigator.appName.indexOf( "Netscape" ) != -1 ) ) {
return false;
}
else {
return true;
}
}
function getDaysInMonth(mthIdx, YrStr)
{
}
function isLeapYear(yrStr)
{
}
//Calendar Section
//calculation functions
function nextMonth(month)
{
}
function prevMonth(month)
{
}
//increments or decrements month when it goes past JAN or DEC
function changeYear(direction,month,year)
{
}return theYear
}
//opens a new window for the calendar
function createCalendar(Wwidth, Wheight, Wtop, Wleft,format, fieldname)
{
// Sets the global DateFormat and Fieldname here
DateFormat = format;
FieldName = fieldname;
// Build the Calendar Windows HTML
var opt = "width=" + Wwidth + ",height=" + Wheight + ",top=" + Wtop + ",left=" + Wleft + ",resizable=no,scrollbars=no";
var today = new Date();
var mthIdx = today.getMonth();
var mthVal = today.getMonth() + 1;
var yearVal = today.getYear();
// If year returned is 100 (in Netscape Version 4.0x and below)
// Subtract 100 to give you just 00
if (yearVal == 100) yearVal = yearVal - 100;
// If year is between 00 and 50, assume that the year is in the 2000 era.
// otheriwse assume year is in the 1900 era
if ((yearVal >= 00) && (yearVal <= 50))
{
// if year is 00, add 2000 to give you a 4 digit year
yearVal = yearVal + 2000;
}
else
{
if (yearVal.length <= 2)
{
// If year is NOT between 00 and 50, ad 1900 to assume its in the 1900 era.
}
}
//call the function to populate the window
generateCalendar(calendarWindow,mthVal,yearVal)
}
//generates the meat of the calendar
function generateCalendar(target,month,year)
{
prevYear+")'><img border=0 src='<RDML MERGE="*LW3SETCALPREV">'></B></a></font></td>"
+ year + "</font></b></td>"
nextYear+")'><img border=0 src='<RDML MERGE="*LW3SETCALNEXT">'></td></tr></table></td></tr>"
}
}
calendar +="</table></div></form></body></html>"
target.focus();
}
function SetDateField(FieldName, DateFormat, day, year)
{
// Get the total number of input elements on the page
var NumElements=document.LANSA.elements.length;
// Loop thorugh each input element
for (i=0; i<NumElements;i++)
{
// Find the matching fieldname and type
if (document.LANSA.elements[i].name==FieldName && document.LANSA.elements[i].type =="text")
{
// Set the Date to the selected date using the required format
if (DateFormat == 6)
{
document.LANSA.elements[i].value=year + "/" + selectedmonth + "/" + parseInt(day, 10);
}
else if (DateFormat == 5)
{
document.LANSA.elements[i].value=selectedmonth + "/" + day + "/" + year;
}
else if (DateFormat == 4)
{
document.LANSA.elements[i].value=parseInt(day,10) + "/" + selectedmonth + "/" + year;
}
else if (DateFormat == 3 || DateFormat == null)
{
document.LANSA.elements[i].value=parseInt(day,10) + "/" + selectedmonth + "/" + year;
break;
}
else if (DateFormat == 2)
{
document.LANSA.elements[i].value=selectedmonth + "/" + day + "/" + year;
break;
}
else if (DateFormat == 1)
{
document.LANSA.elements[i].value=year + "/" + selectedmonth + "/" + parseInt(day, 10);
break;
}
}
}
}
function closeCalendar(day, year)
{
// If no FieldName is passed in return. you could put an alert in here to inform the user that no FieldName was passed.
if (FieldName == null || FieldName == "")
{ return; }
// Set Default DateFOrmat to 1
if (DateFormat == null || DateFormat == "")
{ DateFormat = 1; }
// Add leading 0 if Month is less than 10
if (selectedmonth < 10)
{ selectedmonth = "0" + selectedmonth; }
if (day < 10 && day.length != 2) {day = "0" + day;}
// Make year 2 digit format only if DateFormat is 4, 5 or 6
if (DateFormat >= 4 && DateFormat <= 6)
{
if ((year >= 2000) && (year <= 2050))
else
if (year < 10) year = "0" + year;
}
// Call SetDateField to set the value of the Field to the Selected Date.
SetDateField(FieldName, DateFormat, day, year);
}
</script>
<script language="JavaScript">
//************************************************//
// Default it to 1 if this is NULL
// Date Format 1 - YYYY/MM/DD
// Date Format 2 - MM/DD/YYYY
// Date Format 3 - DD/MM/YYYY
// Date Format 4 - DD/MM/YY
// Date Format 5 - MM/DD/YY
// Date Format 6 - YY/MM/DD
//************************************************//
var DateFormat;
var FieldName = "";
function isBrowserSupp() {
// Get the version of the browser
version = parseFloat( navigator.appVersion );
if ( ( version >= 2.0 ) && ( version < 2.1 ) && ( navigator.appName.indexOf( "Netscape" ) != -1 ) ) {
return false;
}
else {
return true;
}
}
function getDaysInMonth(mthIdx, YrStr)
{
// all the rest have 31 | |
var maxDays=31 |
// expect FEB. (of course) |
if (mthIdx==2) | ||||||
{ | ||||||
if (isLeapYear(YrStr)) | ||||||
{ | maxDays=29; | } | ||||
else | { | maxDays=28; | } | } | ||
// thirty days hath... | ||||||
if (mthIdx==4 || mthIdx==6 || mthIdx==9 || mthIdx==11) | ||||||
{ | maxDays=30; | } | ||||
return maxDays; |
function isLeapYear(yrStr)
{
var leapYear=false; |
if ((parseInt(yrStr, 10)%4) == 0) | ||||
{ | leapYear=true; | } | return leapYear; |
//Calendar Section
//calculation functions
function nextMonth(month)
{
if (month==12) | ||
{ | return 1;}else{ | return (month+1);} |
function prevMonth(month)
{
var prevMonth = (month-1) | |||
if (month==1) | { | prevMonth = 12;}return prevMonth |
//increments or decrements month when it goes past JAN or DEC
function changeYear(direction,month,year)
{
var theYear = year | |||||
if (direction=="next") | |||||
{if (month == 12) | { | ||||
theYear = (year+1) | |||||
} | |||||
} | |||||
if (direction=="prev") | |||||
{ | |||||
if (month == 1) | |||||
{ | theYear = (year-1) | } |
}
//opens a new window for the calendar
function createCalendar(Wwidth, Wheight, Wtop, Wleft,format, fieldname)
{
// Sets the global DateFormat and Fieldname here
DateFormat = format;
FieldName = fieldname;
// Build the Calendar Windows HTML
var opt = "width=" + Wwidth + ",height=" + Wheight + ",top=" + Wtop + ",left=" + Wleft + ",resizable=no,scrollbars=no";
if (!isBrowserSupp()) | ||
{ | ||
alert("Your browser is outdated and does not support this feature") | ||
return; | ||
} | ||
if (navigator.appVersion.indexOf("Mac",0) != -1) | ||
{ | ||
calendarWindow = window.open("","Calendar", opt); | ||
} | ||
else | ||
{ | ||
calendarWindow = window.open("","Calendar", opt); | ||
} |
var mthIdx = today.getMonth();
var mthVal = today.getMonth() + 1;
var yearVal = today.getYear();
// If year returned is 100 (in Netscape Version 4.0x and below)
// Subtract 100 to give you just 00
if (yearVal == 100) yearVal = yearVal - 100;
// If year is between 00 and 50, assume that the year is in the 2000 era.
// otheriwse assume year is in the 1900 era
if ((yearVal >= 00) && (yearVal <= 50))
{
// if year is 00, add 2000 to give you a 4 digit year
yearVal = yearVal + 2000;
}
else
{
if (yearVal.length <= 2)
{
// If year is NOT between 00 and 50, ad 1900 to assume its in the 1900 era.
yearVal = yearVal + 1900; |
}
//call the function to populate the window
generateCalendar(calendarWindow,mthVal,yearVal)
}
//generates the meat of the calendar
function generateCalendar(target,month,year)
{
if (!isBrowserSupp()) | ||
{ | ||
return; | ||
} | ||
var monthName = new Array ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") | ||
//begin table for calendar | ||
target.document.open(); | ||
calendar = "<html><head><title>Calendar</title></head><body bgcolor='white' topmargin=2 leftmargin=2><div align='center'>" | ||
calendar +="<table border=0 cellspacing=3 cellpadding=0>" | ||
calendar +="<tr valign=top>" |
var mthIdx = parseInt(month, 10); |
var endday = getDaysInMonth(mthIdx, year) |
//next month and previous month buttons |
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)) | |
var index = (mthIdx-1) |
//month header | |
{ |
calendar +="<form><td align=left colspan=7 bgcolor=#A7CCDC><table width='100%' border=0 cellpadding=0 cellspacing=0><tr><td><a href='javascript:void(0)' onClick='document.clear();opener.generateCalendar(opener.calendarWindow,"+goPrevMonth+","+ |
calendar +="<td align=center colspan=3 bgcolor=#A7CCDC><b><font size='-2' face='Arial' color='darkblue'>" + monthName[index] + " " |
calendar +="<td align=right colspan=2 bgcolor=#A7CCDC><a href='javascript:void(0)'onClick='document.clear();opener.generateCalendar(opener.calendarWindow,"+goNextMonth+","+ |
} | |
//writes in the day of the week labels |
calendar +="<tr align=center>" |
calendar +="<td align='center' bgcolor='#FFFFC0'><b><img src='<RDML MERGE="*LW3SETSCAL">' border=0></b></font></td>" |
calendar +="<td align='center' bgcolor='#FFFFC0'><b><img src='<RDML MERGE="*LW3SETMCAL">' border=0></b></font></td>" |
calendar +="<td align='center' bgcolor='#FFFFC0'><b><img src='<RDML MERGE="*LW3SETTCAL">' border=0></b></font></td>" |
calendar +="<td align='center' bgcolor='#FFFFC0'><b><img src='<RDML MERGE="*LW3SETWCAL">' border=0></b></font></td>" |
calendar +="<td align='center' bgcolor='#FFFFC0'><b><img src='<RDML MERGE="*LW3SETTCAL">' border=0></b></font></td>" |
calendar +="<td align='center' bgcolor='#FFFFC0'><b><img src='<RDML MERGE="*LW3SETFCAL">' border=0></b></font></td>" |
calendar +="<td align='center' bgcolor='#FFFFC0'><font color='#FF0000'><b><img src='<RDML MERGE="*LW3SETSCAL">' border=0></b></font></td>" | |
calendar +="</tr>" | |
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) | |
calendar +="<tr>" |
var daycounter = 0; | |||
for (var i = 1; i < lastDay; i++) | |||
{ | |||
daycounter=i; | |||
if (i <= firstDay) | |||
{ | |||
// 'empty' boxes prior to first day | |||
calendar +="<td><img border=0 src='<RDML MERGE="*LW3SETCALBLANK">'></td>" |
} | ||||
else | ||||
{ | ||||
// enter date number | ||||
if (i % 7 == 0 || i % 7 == 1) | ||||
{ | ||||
if ((i-firstDay)==(today.getDate())&&(month == parseInt(today.getMonth() + 1)) &&(year == today.getYear())) | ||||
{ | ||||
calendar +="<td bgcolor='lightgreen' align=center><a href='JavaScript:self.close();opener.closeCalendar"+"("+(i-firstDay)+ "," + selectedyear + ")'>"+(i-firstDay)+"</a></td>" |
else | ||||
{ | ||||
calendar +="<td bgcolor='pink' align=center><a href='JavaScript:self.close();opener.closeCalendar"+"("+(i-firstDay)+ "," + selectedyear + ")'>"+(i-firstDay)+"</a></td>" |
} | ||||
else | ||||
{ | ||||
if ((i-firstDay)==(today.getDate())&&(month == parseInt(today.getMonth() + 1)) && (year == today.getYear())) | ||||
{ | ||||
calendar +="<td bgcolor='lightgreen' align=center><a href='JavaScript:self.close();opener.closeCalendar"+"("+(i-firstDay)+ "," + selectedyear + ")'>"+(i-firstDay)+"</a></td>" | ||||
} | ||||
else | ||||
{ | ||||
calendar +="<td align=center><a href='JavaScript:self.close();opener.closeCalendar"+"("+(i-firstDay)+ "," + selectedyear + ")'>"+(i-firstDay)+"</a></td>" | ||||
} | ||||
} |
} | |||
//must start new row after each week | |||
if (i % 7 == 0 && i != lastDay) | |||
{ | |||
calendar +="</tr><tr>" | |||
} | |||
} | |||
calendar +="</tr>" |
//separator line |
//calendar +="<tr><td colspan=7 align=center width=200><hr noshade></td></tr></table></form></body></html>" |
calendar +="</table></div></form></body></html>"
target.document.write(calendar); |
target.document.close() |
function SetDateField(FieldName, DateFormat, day, year)
{
// Get the total number of input elements on the page
var NumElements=document.LANSA.elements.length;
// Loop thorugh each input element
for (i=0; i<NumElements;i++)
{
// Find the matching fieldname and type
if (document.LANSA.elements[i].name==FieldName && document.LANSA.elements[i].type =="text")
{
// Set the Date to the selected date using the required format
if (DateFormat == 6)
{
document.LANSA.elements[i].value=year + "/" + selectedmonth + "/" + parseInt(day, 10);
}
else if (DateFormat == 5)
{
document.LANSA.elements[i].value=selectedmonth + "/" + day + "/" + year;
}
else if (DateFormat == 4)
{
document.LANSA.elements[i].value=parseInt(day,10) + "/" + selectedmonth + "/" + year;
}
else if (DateFormat == 3 || DateFormat == null)
{
document.LANSA.elements[i].value=parseInt(day,10) + "/" + selectedmonth + "/" + year;
break;
}
else if (DateFormat == 2)
{
document.LANSA.elements[i].value=selectedmonth + "/" + day + "/" + year;
break;
}
else if (DateFormat == 1)
{
document.LANSA.elements[i].value=year + "/" + selectedmonth + "/" + parseInt(day, 10);
break;
}
}
}
}
function closeCalendar(day, year)
{
// If no FieldName is passed in return. you could put an alert in here to inform the user that no FieldName was passed.
if (FieldName == null || FieldName == "")
{ return; }
// Set Default DateFOrmat to 1
if (DateFormat == null || DateFormat == "")
{ DateFormat = 1; }
// Add leading 0 if Month is less than 10
if (selectedmonth < 10)
{ selectedmonth = "0" + selectedmonth; }
if (day < 10 && day.length != 2) {day = "0" + day;}
// Make year 2 digit format only if DateFormat is 4, 5 or 6
if (DateFormat >= 4 && DateFormat <= 6)
{
if ((year >= 2000) && (year <= 2050))
{ | year = parseInt(year, 10) - 2000; } |
{ | year = parseInt(year, 10) - 1900;} |
}
// Call SetDateField to set the value of the Field to the Selected Date.
SetDateField(FieldName, DateFormat, day, year);
}
</script>