F
Fendi Baba
The function is called from opencalendar(targetfield). Thanks for any
hints on what could be the problem.
..............................................................
var decimalPointDelimiter = ".";
var defaultEmptyOK = false;
var dayA = new Array();
var monthA = new Array();
var yearA = new Array();
var targetfield;
monthA[0]="January";
monthA[1]="February";
monthA[2]="March";
monthA[3]="April";
monthA[4]="May";
monthA[5]="June";
monthA[6]="July";
monthA[7]="August";
monthA[8]="September";
monthA[9]="October";
monthA[10]="November";
monthA[11]="December";
for(var i=1;i<=31;i++)
{
dayA=i;
}
for(var i=0;i<10;i++)
{
yearA=gy(i);
}
function gm(num) {
var mydate = new Date();
mydate.setDate(1);
mydate.setMonth(num-1);
var datestr = "" + mydate;
return datestr.substring(4,7);
}
function gy(num) {
var mydate = new Date();
return (eval(mydate.getYear()) - 4 + num);
}
function ud(mon) {
var i = mon.selectedIndex;
if(mon.options.value == "2") {
document.forms[0].day.options[30] = null;
document.forms[0].day.options[29] = null;
var j = document.forms[0].year.selectedIndex;
var year = eval(document.forms[0].year.options[j].value);
if ( ((year%400)==0) || (((year%100)!=0) && ((year%4)==0)) ) {
if (document.forms[0].day.options[28] == null) {
document.forms[0].day.options[28] = new Option("29");
document.forms[0].day.options[28].value = "29";
}
} else {
document.forms[0].day.options[28] = null;
}
}
if(mon.options.value == "1" ||
mon.options.value == "3" ||
mon.options.value == "5" ||
mon.options.value == "7" ||
mon.options.value == "8" ||
mon.options.value == "10" ||
mon.options.value == "12")
{
if (document.forms[0].day.options[28] == null) {
document.forms[0].day.options[28] = new Option("29");
document.forms[0].day.options[28].value = "29";
}
if (document.forms[0].day.options[29] == null) {
document.forms[0].day.options[29] = new Option("30");
document.forms[0].day.options[29].value = "30";
}
if (document.forms[0].day.options[30] == null) {
document.forms[0].day.options[30] = new Option("31");
document.forms[0].day.options[30].value = "31";
}
}
if(mon.options.value == "4" ||
mon.options.value == "6" ||
mon.options.value == "9" ||
mon.options.value == "11")
{
if (document.forms[0].day.options[28] == null) {
document.forms[0].day.options[28] = new Option("29");
document.forms[0].day.options[28].value = "29";
}
if (document.forms[0].day.options[29] == null) {
document.forms[0].day.options[29] = new Option("30");
document.forms[0].day.options[29].value = "30";
}
document.forms[0].day.options[30] = null;
}
if (document.forms[0].day.selectedIndex == -1)
document.forms[0].day.selectedIndex = 0;
}
function showdate() {
var i = document.forms[0].month.selectedIndex;
var j = document.forms[0].day.selectedIndex;
var k = document.forms[0].year.selectedIndex;
alert(document.forms[0].day.options[j].value + "/" +
document.forms[0].month.options.value + "/" +
document.forms[0].year.options[k].value)
}
function opencalendar(temptargetfield) {
var field= eval("document.forms[0]." + temptargetfield);
targetfield = "opener.document.forms[0]." + temptargetfield +
".value";
var mydate;
if(field.value == "" || field.value.length < 10 || field.value.length
mydate = new Date();
}
else
{
var tempday = field.value.charAt(0).toString() +
field.value.charAt(1).toString();
var tempmonth = (parseInt((parsemonth(field.value.charAt(3).toString(),
field.value.charAt(4).toString())))-1).toString();
var tempyear = (parseInt(field.value.charAt(6).toString() +
field.value.charAt(7).toString() + field.value.charAt(8).toString() +
field.value.charAt(9).toString())).toString();
mydate = new Date(tempyear, tempmonth, tempday );
window.alert(mydate)
}
for(var i=0;i<=monthA.length;i++)
{
if (mydate.getMonth() == i)
{
month = i+1;
}
}
year = mydate.getYear();
//yearA[4].toString();
calwin = window.open("","calwin","resizable,status,height=250,width=210");
calccal(calwin,month,year,targetfield);
}
function parsemonth(tmpm1, tmpm2)
{
var m1;
var m2;
var m3;
if (tmpm1 == "0")
{
m1 = "";
}
else
{
m1 = "1";
}
m2 = tmpm2;
m3 = m1.toString() + m2.toString();
return m3;
}
function calccal(targetwin,month,year,targetfield) {
var monthname = new Array(12);
monthname[0] = "January";
monthname[1] = "February";
monthname[2] = "March";
monthname[3] = "April";
monthname[4] = "May";
monthname[5] = "June";
monthname[6] = "July";
monthname[7] = "August";
monthname[8] = "September";
monthname[9] = "October";
monthname[10] = "November";
monthname[11] = "December";
var endday = calclastday(eval(month),eval(year));
mystr = month + "/01/" + year;
mydate = new Date(mystr);
firstday = mydate.getDay();
var cnt = 0;
var day = new Array(6);
for (var i=0; i<6; i++)
day = new Array(7);
for (var r=0; r<6; r++)
{
for (var c=0; c<7; c++)
{
if ((cnt==0) && (c!=firstday))
continue;
cnt++;
day[r][c] = cnt;
if (cnt==endday)
break;
}
if (cnt==endday)
break;
}
targetwin.document.write("<TABLE><TR VALIGN=TOP><FORM>");
var prevyear = eval(year) - 1;
targetwin.document.write("<TD><INPUT TYPE=BUTTON NAME=prevyearbutton
VALUE='<<'"+
" onclick='document.close();opener.calccal(opener.calwin,"+month+","+prevyear+",\""+targetfield+"\")'></TD>");
var prevmonth = calcprevmonth(month);
var prevmonthyear = calcprevyear(month,year);
targetwin.document.write("<TD><INPUT TYPE=BUTTON
NAME=prevmonthbutton VALUE=' < '"+
" onclick='document.close();opener.calccal(opener.calwin,"+prevmonth+","+prevmonthyear+",\""+targetfield+"\")'></TD>");
targetwin.document.write("<TD COLSPAN=3 ALIGN=CENTER>");
var index = eval(month) - 1;
targetwin.document.write("<B>" + monthname[index] + " " + year +
"</B></TD>");
var nextmonth = calcnextmonth(month);
var nextmonthyear = calcnextyear(month,year);
targetwin.document.write("<TD><INPUT TYPE=BUTTON
NAME=nextmonthbutton VALUE=' > '"+
" onclick='document.close();opener.calccal(opener.calwin,"+nextmonth+","+nextmonthyear+",\""+targetfield+"\")'></TD>");
var nextyear = eval(year) + 1;
targetwin.document.write("<TD><INPUT TYPE=BUTTON NAME=nextyearbutton
VALUE='>>'"+
" onclick='document.close();opener.calccal(opener.calwin,"+month+","+nextyear+",\""+targetfield+"\")'></TD>");
targetwin.document.write("</TR><TR>");
targetwin.document.write("<TD>Su</TD>");
targetwin.document.write("<TD>Mo</TD>");
targetwin.document.write("<TD>Tu</TD>");
targetwin.document.write("<TD>We</TD>");
targetwin.document.write("<TD>Th</TD>");
targetwin.document.write("<TD>Fr</TD>");
targetwin.document.write("<TD>Sa</TD>");
targetwin.document.write("</TR>");
targetwin.document.write("<TR><TD COLSPAN=7><HR
NOSHADE></TD></TR>");
var selectedmonth = eval(month) - 1;
var today = new Date();
var thisyear = today.getYear();
var selectedyear = eval(year) - thisyear + 4;
var conditionalpadder = "";
for(r=0; r<6; r++)
{
targetwin.document.write("<TR>");
for(c=0; c<7; c++)
{
targetwin.document.write("<TD>");
if(day[r][c] != null) {
if (day[r][c] < 10)
conditionalpadder = " "
else
conditionalpadder = "";
targetwin.document.write("<INPUT TYPE=BUTTON NAME="+day[r][c]+
" VALUE=" + conditionalpadder + day[r][c] + conditionalpadder +
" onClick=\"window.close();"
+targetfield+"='"+(day[r][c]).toString()+ "/"+
(selectedmonth+1).toString() + "/" + yearA[selectedyear.toString()]
+"';\";>"); }
targetwin.document.write("</TD>");
}
targetwin.document.write("</TR>");
}
targetwin.document.write("</FORM></TABLE>");
}
function calclastday(month,year) {
if ((month==2) && ((year%4)==0))
return 29;
if ((month==2) && ((year%4)!=0))
return 28;
if ((month==1) || (month == 3) || (month == 5) || (month == 7) ||
(month==8) || (month == 10) || (month ==12))
return 31;
return 30;
}
function calcnextmonth(month) {
if (month=="12")
return "1";
else
return (eval(month)+1);
}
function calcnextyear(month,year) {
if (month=="12")
return (eval(year)+1);
else
return (year);
}
function calcprevmonth(month) {
if (month=="1")
return "12";
else
return (eval(month)-1);
}
function calcprevyear(month,year) {
if (month=="1")
return (eval(year)-1);
else
return (year);
}
hints on what could be the problem.
..............................................................
var decimalPointDelimiter = ".";
var defaultEmptyOK = false;
var dayA = new Array();
var monthA = new Array();
var yearA = new Array();
var targetfield;
monthA[0]="January";
monthA[1]="February";
monthA[2]="March";
monthA[3]="April";
monthA[4]="May";
monthA[5]="June";
monthA[6]="July";
monthA[7]="August";
monthA[8]="September";
monthA[9]="October";
monthA[10]="November";
monthA[11]="December";
for(var i=1;i<=31;i++)
{
dayA=i;
}
for(var i=0;i<10;i++)
{
yearA=gy(i);
}
function gm(num) {
var mydate = new Date();
mydate.setDate(1);
mydate.setMonth(num-1);
var datestr = "" + mydate;
return datestr.substring(4,7);
}
function gy(num) {
var mydate = new Date();
return (eval(mydate.getYear()) - 4 + num);
}
function ud(mon) {
var i = mon.selectedIndex;
if(mon.options.value == "2") {
document.forms[0].day.options[30] = null;
document.forms[0].day.options[29] = null;
var j = document.forms[0].year.selectedIndex;
var year = eval(document.forms[0].year.options[j].value);
if ( ((year%400)==0) || (((year%100)!=0) && ((year%4)==0)) ) {
if (document.forms[0].day.options[28] == null) {
document.forms[0].day.options[28] = new Option("29");
document.forms[0].day.options[28].value = "29";
}
} else {
document.forms[0].day.options[28] = null;
}
}
if(mon.options.value == "1" ||
mon.options.value == "3" ||
mon.options.value == "5" ||
mon.options.value == "7" ||
mon.options.value == "8" ||
mon.options.value == "10" ||
mon.options.value == "12")
{
if (document.forms[0].day.options[28] == null) {
document.forms[0].day.options[28] = new Option("29");
document.forms[0].day.options[28].value = "29";
}
if (document.forms[0].day.options[29] == null) {
document.forms[0].day.options[29] = new Option("30");
document.forms[0].day.options[29].value = "30";
}
if (document.forms[0].day.options[30] == null) {
document.forms[0].day.options[30] = new Option("31");
document.forms[0].day.options[30].value = "31";
}
}
if(mon.options.value == "4" ||
mon.options.value == "6" ||
mon.options.value == "9" ||
mon.options.value == "11")
{
if (document.forms[0].day.options[28] == null) {
document.forms[0].day.options[28] = new Option("29");
document.forms[0].day.options[28].value = "29";
}
if (document.forms[0].day.options[29] == null) {
document.forms[0].day.options[29] = new Option("30");
document.forms[0].day.options[29].value = "30";
}
document.forms[0].day.options[30] = null;
}
if (document.forms[0].day.selectedIndex == -1)
document.forms[0].day.selectedIndex = 0;
}
function showdate() {
var i = document.forms[0].month.selectedIndex;
var j = document.forms[0].day.selectedIndex;
var k = document.forms[0].year.selectedIndex;
alert(document.forms[0].day.options[j].value + "/" +
document.forms[0].month.options.value + "/" +
document.forms[0].year.options[k].value)
}
function opencalendar(temptargetfield) {
var field= eval("document.forms[0]." + temptargetfield);
targetfield = "opener.document.forms[0]." + temptargetfield +
".value";
var mydate;
if(field.value == "" || field.value.length < 10 || field.value.length
{
mydate = new Date();
}
else
{
var tempday = field.value.charAt(0).toString() +
field.value.charAt(1).toString();
var tempmonth = (parseInt((parsemonth(field.value.charAt(3).toString(),
field.value.charAt(4).toString())))-1).toString();
var tempyear = (parseInt(field.value.charAt(6).toString() +
field.value.charAt(7).toString() + field.value.charAt(8).toString() +
field.value.charAt(9).toString())).toString();
mydate = new Date(tempyear, tempmonth, tempday );
window.alert(mydate)
}
for(var i=0;i<=monthA.length;i++)
{
if (mydate.getMonth() == i)
{
month = i+1;
}
}
year = mydate.getYear();
//yearA[4].toString();
calwin = window.open("","calwin","resizable,status,height=250,width=210");
calccal(calwin,month,year,targetfield);
}
function parsemonth(tmpm1, tmpm2)
{
var m1;
var m2;
var m3;
if (tmpm1 == "0")
{
m1 = "";
}
else
{
m1 = "1";
}
m2 = tmpm2;
m3 = m1.toString() + m2.toString();
return m3;
}
function calccal(targetwin,month,year,targetfield) {
var monthname = new Array(12);
monthname[0] = "January";
monthname[1] = "February";
monthname[2] = "March";
monthname[3] = "April";
monthname[4] = "May";
monthname[5] = "June";
monthname[6] = "July";
monthname[7] = "August";
monthname[8] = "September";
monthname[9] = "October";
monthname[10] = "November";
monthname[11] = "December";
var endday = calclastday(eval(month),eval(year));
mystr = month + "/01/" + year;
mydate = new Date(mystr);
firstday = mydate.getDay();
var cnt = 0;
var day = new Array(6);
for (var i=0; i<6; i++)
day = new Array(7);
for (var r=0; r<6; r++)
{
for (var c=0; c<7; c++)
{
if ((cnt==0) && (c!=firstday))
continue;
cnt++;
day[r][c] = cnt;
if (cnt==endday)
break;
}
if (cnt==endday)
break;
}
targetwin.document.write("<TABLE><TR VALIGN=TOP><FORM>");
var prevyear = eval(year) - 1;
targetwin.document.write("<TD><INPUT TYPE=BUTTON NAME=prevyearbutton
VALUE='<<'"+
" onclick='document.close();opener.calccal(opener.calwin,"+month+","+prevyear+",\""+targetfield+"\")'></TD>");
var prevmonth = calcprevmonth(month);
var prevmonthyear = calcprevyear(month,year);
targetwin.document.write("<TD><INPUT TYPE=BUTTON
NAME=prevmonthbutton VALUE=' < '"+
" onclick='document.close();opener.calccal(opener.calwin,"+prevmonth+","+prevmonthyear+",\""+targetfield+"\")'></TD>");
targetwin.document.write("<TD COLSPAN=3 ALIGN=CENTER>");
var index = eval(month) - 1;
targetwin.document.write("<B>" + monthname[index] + " " + year +
"</B></TD>");
var nextmonth = calcnextmonth(month);
var nextmonthyear = calcnextyear(month,year);
targetwin.document.write("<TD><INPUT TYPE=BUTTON
NAME=nextmonthbutton VALUE=' > '"+
" onclick='document.close();opener.calccal(opener.calwin,"+nextmonth+","+nextmonthyear+",\""+targetfield+"\")'></TD>");
var nextyear = eval(year) + 1;
targetwin.document.write("<TD><INPUT TYPE=BUTTON NAME=nextyearbutton
VALUE='>>'"+
" onclick='document.close();opener.calccal(opener.calwin,"+month+","+nextyear+",\""+targetfield+"\")'></TD>");
targetwin.document.write("</TR><TR>");
targetwin.document.write("<TD>Su</TD>");
targetwin.document.write("<TD>Mo</TD>");
targetwin.document.write("<TD>Tu</TD>");
targetwin.document.write("<TD>We</TD>");
targetwin.document.write("<TD>Th</TD>");
targetwin.document.write("<TD>Fr</TD>");
targetwin.document.write("<TD>Sa</TD>");
targetwin.document.write("</TR>");
targetwin.document.write("<TR><TD COLSPAN=7><HR
NOSHADE></TD></TR>");
var selectedmonth = eval(month) - 1;
var today = new Date();
var thisyear = today.getYear();
var selectedyear = eval(year) - thisyear + 4;
var conditionalpadder = "";
for(r=0; r<6; r++)
{
targetwin.document.write("<TR>");
for(c=0; c<7; c++)
{
targetwin.document.write("<TD>");
if(day[r][c] != null) {
if (day[r][c] < 10)
conditionalpadder = " "
else
conditionalpadder = "";
targetwin.document.write("<INPUT TYPE=BUTTON NAME="+day[r][c]+
" VALUE=" + conditionalpadder + day[r][c] + conditionalpadder +
" onClick=\"window.close();"
+targetfield+"='"+(day[r][c]).toString()+ "/"+
(selectedmonth+1).toString() + "/" + yearA[selectedyear.toString()]
+"';\";>"); }
targetwin.document.write("</TD>");
}
targetwin.document.write("</TR>");
}
targetwin.document.write("</FORM></TABLE>");
}
function calclastday(month,year) {
if ((month==2) && ((year%4)==0))
return 29;
if ((month==2) && ((year%4)!=0))
return 28;
if ((month==1) || (month == 3) || (month == 5) || (month == 7) ||
(month==8) || (month == 10) || (month ==12))
return 31;
return 30;
}
function calcnextmonth(month) {
if (month=="12")
return "1";
else
return (eval(month)+1);
}
function calcnextyear(month,year) {
if (month=="12")
return (eval(year)+1);
else
return (year);
}
function calcprevmonth(month) {
if (month=="1")
return "12";
else
return (eval(month)-1);
}
function calcprevyear(month,year) {
if (month=="1")
return (eval(year)-1);
else
return (year);
}