<% @ Page contentType = "text/html; charset = gb2312" language = "java" %>
<Html>
<Head>
<Title> date selector </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Style>
Body, td {font-size: 9pt ;}
Input
{
Color: 333333;
Font-size: 9pt;
Border-width: 0;
Padding: 2;
Width: 20;
}
</Style>
</Head>
<Script language = javascript>
<! --
Var monthNames = new Array ("", "1", "2", "3", "4", "5", "6", "7 ", "8", "9", "10", "11", "12 ");
Var endDay = new Array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31 );
Var dayNow = 0;
Var monthNow = 0;
Var yearNow = 0;
Function load (form ){
Set_month_year_now ();
Var found = false;
For (var month = 0; month <form. monthList. length; month ++)
If (form. monthList [month]. text = monthNames [monthNow]) {
Form. monthList [month]. selected = true;
Found = true;
}
If (! Found ){
Error ();
Return;
}
VaR found = false;
For (VAR year = 0; year <form. yearlist. length; year ++)
If (Form. yearlist [year]. Text = yearnow ){
Form. yearlist [year]. Selected = true;
Found = true;
}
If (! Found ){
Error ();
Return;
}
Display_month (form );
}
Function preceding_month (form ){
Var month_selected = form. monthList. selectedIndex;
Var year_selected = form. yearList. selectedIndex;
If (! Month_selected &&! Year_selected ){
Error ();
Return;
}
If (month_selected> 0)
Month_selected --;
Else {
Month_selected = 11;
Year_selected --;
}
Form. monthList [month_selected]. selected = true;
Form. yearlist [year_selected]. Selected = true;
Display_month (form );
}
Function following_month (form ){
VaR month_selected = form. monthlist. selectedindex;
VaR year_selected = form. yearlist. selectedindex;
If (month_selected> = (Form. monthlist. Length-1) & year_selected> = (Form. yearlist. Length-1 )){
Error ();
Return;
}
If (month_selected <11)
Month_selected ++;
Else {
Month_selected = 0;
Year_selected ++;
}
Form. monthList [month_selected]. selected = true;
Form. yearList [year_selected]. selected = true;
Display_month (form );
}
Function set_month_year_now (){
Var form = document. calendar;
Var now = new Date ();
MonthNow = now. getMonth () + 1;
YearNow = now. getYear ();
DayNow = now. getDate ();
YearNow = (yearNow <100 )? YearNow + 1900: yearNow;
Var count = 0
For (var I = yearNow-103; I <yearNow + 50; I ++ ){
Eval ("form. yearList. options [count] = new Option ('" + I + "', '" + I + "')");
Count ++;
}
Form. yearlist. selectedindex = 103;
Form. yearlist. Length = count;
}
Function error (){
Alert ("out of range! ");
}
Function display_month (form ){
VaR month = form. monthlist. selectedindex + 1;
VaR year = parseint (Form. yearlist. Options [Form. yearlist. selectedindex]. Text );
VaR start_day = start_day_in_month (year, month );
VaR COUNT = 0;
For (var row = 0; row <6; row ++ ){
For (var col = 0; col <7; col ++)
{
If (row = 0 & col <(start_day-1 ))
Var day = "";
Else if (count <endDay [month])
Day = ++ count;
Else
Day = "";
Form. daybox [(row * 7) + Col]. style. Display = "";
Form. daybox [(row * 7) + Col]. style. color = "black ";
If (Day = ""){
Form. daybox [(row * 7) + Col]. style. Display = "NONE ";
} Else {
Form. dayBox [(row * 7) + col]. value = day;
If (col % 7 = 0) form. dayBox [(row * 7) + col]. style. color = "red ";
If (yearNow = year & monthNow = month & dayNow = day) form. dayBox [(row * 7) + col]. style. color = "blue ";;
}
}
}
}
Function start_day_in_month (year, month ){
Var day, daynum, ndays, mnum;
Sday = start_day_in_year (year );
EndDay [2] = (year % 4 )? 28: 29;
If (month = 1)
Daynum = sday;
Else {
Ndays = sday;
For (mnum = 2; mnum <month + 1; mnum ++)
Ndays = ndays + endDay [mnum-1];
Daynum = ndays % 7;
}
Daynum = (! Daynum )? 7: daynum;
Return (daynum );
}
Function start_day_in_year (year ){
Var y, m, d;
Var n;
Y = year-1; m = 13; d = 1;
N = d + 2 * m + (Math. floor (0.6 + (m + 1) + y );
N = n + Math. floor (y/4)-Math. floor (y/100) + Math. floor (y/400) + 2;
N = Math. floor (n/7-Math. floor (n/7) * 7 + 0.5 ));
Return (n + 1 );
}
Function CheckDate (strDay ){
Var docFrm = document. calendar;
Var choice_daynum = 0;
Var current_daynum = 0;
Var day_temp;
If (strDay! = ""){
Var strY = docFrm. yearList. value;
Var strM = docFrm. monthList. value;
Var curr_y = new String (yearNow );
Var curr_m = new String (monthNow );
Var curr_d = new String (dayNow );
If (curr_m.length = 1) curr_m = "0" + curr_m;
If (curr_d.length = 1) curr_d = "0" + curr_d;
Current_daynum = new Number (curr_y + curr_m + curr_d );
If (strM. length = 1) strM = "0" + strM;
If (strDay. length = 1) strDay = "0" + strDay;
Choice_daynum = new Number (strY + strM + strDay );
Parent. window. returnValue = strY + "-" + strM + "-" + strDay; // pass the selected date to the parent window.
Parent. window. close ();
}
Return false;
}
-->
</Script>
<Body onLoad = "load (document. calendar)" topmargin = "0">
<Center>
<Form name = "calendar">
<Table border = "0" cellpadding = "0" cellspacing = "0">
<Tr>
<Td colspan = "3" height = "24"> </td>
</Tr>
<Tr>
<TD width = "205" nowrap = "nowrap" align = "right"> <select name = "yearlist" onchange = "display_month (this. Form)">
</SELECT>
</TD>
<TD width = "65" nowrap = "nowrap" align = "Left"> <select name = "monthlist" size = "1" onchange = "display_month (this. form) ">
<% For (INT I = 1; I <13; I ++) {%>
<Option value = "<% = I %>"> <% = I %> </option>
<% }%>
</Select>
</Td>
<Td width = "10"> </td>
</Tr>
<Tr>
<Td colspan = "3" height = "6"> </td>
</Tr>
<Tr>
<Td colspan = "3"> <table border = "0" cellpadding = "1" cellspacing = "0" align = "center">
<Tr>
<Td bgcolor = "# 82664F"> <table border = "0" cellpadding = "0" cellspacing = "0">
<Tr bgcolor = "# 82664F" height = "18">
<Td width = "31" align = "center" nowrap = "nowrap"> <font color = "# FF0000"> day </font> </td>
<Td width = "31" align = "center" nowrap = "nowrap"> 1 </td>
<Td width = "31" align = "center" nowrap = "nowrap"> 2 </td>
<TD width = "31" align = "center" nowrap = "nowrap"> 3 </TD>
<TD width = "31" align = "center" nowrap = "nowrap"> 4 </TD>
<TD width = "31" align = "center" nowrap = "nowrap"> 5 </TD>
<TD width = "31" align = "center" nowrap = "nowrap"> 6 </TD>
</Tr>
<% For (int r = 0; r <6; r ++) {%>
<Tr bgcolor = "# FFFFFF" height = "18">
<% For (int d = 0; d <7; d ++) {%>
<Td align = "center"> <input type = "text" size = "2" name = "dayBox" readOnly onClick = "javascript: CheckDate (this. value); "onMouseOver =" this. style. background = '# eeeeeee' "onmouseout =" this. style. background = 'white' ">
</Td>
<% }%>
</Tr>
<% }%>
</Table> </td>
</Tr>
</Table> </td>
</Tr>
</Table>
</Form>
</Center>
</Body>
</Html>