h1 { font-size:30; color:black; font-weight:bolder; } div { text-align:center; /* h1 && text =>center*/ } /* text */ #text { width:150; text-align:center;/* the word in text => center*/ } /*the whole table*/ table { border-collapse:collapse; } td { text-align:right; border:solid 1px black; } /*set today red*/ td.today { color:red; } td.sunsat { color:green; } th { border:solid 1px black; } /*first part in table*/ th.firstpart { font-size:25; } /*second part in table*/ th.secondpart { font-size:20; color:blue; width:50; } /*button style*/ .button { width:25; height:25; text-align:center; vertical-align: center;/*????*/ } .buttonToday { width:50; height:25; text-align:center; padding-top:0px; } /* span.buttonleft { float:left; } span.buttonright { padding-left:60; } span.bigwords { padding-left:50; } */ <html> <head> <title>calendaragain</title> <link rel=stylesheet href="calendaragain.css" mce_href="calendaragain.css"> <mce:script type = "text/javascript"><!-- //show the all page function allpage() { timeintext(); getnowtimeagain();//for change month and year timeintable(); } /* time in text */ var nowTime,nowTimeYear,nowTimeMonth,nowTimeDate,nowTimeHours,nowTimeMinutes,nowTimeSeconds; var nowTimeShowInText; //set the nowtime in the text function timeintext() { //get nowtime nowTime = new Date(); nowTimeYear = nowTime.getFullYear(); //now Year nowTimeMonth = nowTime.getMonth() + 1; //now Month nowTimeDate = nowTime.getDate(); //now Date nowTimeHours = nowTime.getHours(); //now Hours nowTimeMinutes = nowTime.getMinutes(); //now Minutes nowTimeSeconds = nowTime.getSeconds(); //now Seconds //put nowtime into the text nowTimeShowInText = nowTimeYear + "/" + inputzero(nowTimeMonth) + "/" + inputzero(nowTimeDate) + " "; nowTimeShowInText += inputzero(nowTimeHours) + ":" + inputzero(nowTimeMinutes) + ":" + inputzero(nowTimeSeconds); document.getElementById("text").value = nowTimeShowInText; window.setTimeout("timeintext();",100); } //get now time again for change month and year function getnowtimeagain() { willnowTime = new Date(); willchangedMonth = willnowTime.getMonth() + 1; //first set changedMonth willchangedYear = willnowTime.getFullYear(); //first set changedYear } var showTimeInTable; var willchangedMonth,willchangedYear;//active year and month /* time in table */ function timeintable(state) { FirstPartInTable(state); //part one in table SecondlPartInTable(); //part two in table ThirdPartInTable(willchangedYear,willchangedMonth); //part third in table showtable.innerHTML = showTimeInTable; } //first line in the table =>just show year and month what can be changed function FirstPartInTable(state) { statechange(state); showTimeInTable = "<table><tr><th colspan='7' class = 'firstpart'><span>";//table start //button left //last year showTimeInTable += "<input type = 'button' class = 'button' title='LastYear' value = '<' onclick = timeintable('lastyear');>"; //lastmonth showTimeInTable += "<input type = 'button' class = 'button' title='LastMonth' value = '<<' onclick = timeintable('lastmonth');>"; showTimeInTable +="</span>"+" "; showTimeInTable += willchangedYear +"/"+ inputzero(willchangedMonth); //button right showTimeInTable += "</span> <span>"; //next month showTimeInTable += "<input type = 'button' class = 'button' title='NextMonth' value = '>>' onclick = timeintable('nextmonth');>"; //next year showTimeInTable += "<input type = 'button' class = 'button' title='NextYear' value = '>' onclick = timeintable('nextyear');>"; showTimeInTable += "</span>"; showTimeInTable += "</th></tr>"; } //state change year or month function statechange(state) { if (state == "lastmonth") { if (willchangedMonth == 1) { willchangedYear -=1; willchangedMonth = 12; } else { willchangedMonth -= 1; } } else if (state == "nextmonth") { if (willchangedMonth == 12) { willchangedYear += 1; willchangedMonth = 1; } else { willchangedMonth += 1; } } else if (state == "lastyear") { willchangedYear -= 1; } else if (state == "nextyear") { willchangedYear += 1; } else if (state == "today") { willchangedYear = nowTimeYear; willchangedMonth = nowTimeMonth; } else if (state == "selectyear") {//set the table year var listyear = document.getElementById("yearlist"); var yearnumber; for (var i = 0;i < listyear.length;i++) { if (listyear.options[i].selected) { yearnumber = listyear.options[i].text; break; } } willchangedYear = yearnumber; } else if (state == "selectmonth") {//set the table month var listmonth = document.getElementById("monthlist"); var monthnumber; for (var i = 0;i < listmonth.length;i++) { if (listmonth.options[i].selected) { monthnumber = listmonth.options[i].text; break; } } willchangedMonth = monthnumber; } } //second line in the table =>just show the weekname function SecondlPartInTable() { var weekname = new Array(7); weekname[0] = "Sun"; weekname[1] = "Mon"; weekname[2] = "Tue"; weekname[3] = "Wen"; weekname[4] = "Thu"; weekname[5] = "Fri"; weekname[6] = "Sat"; showTimeInTable += "<tr>"; for (var i=0;i<7;i++) { showTimeInTable += "<th class = 'secondpart'>" + weekname[i] + "</th>"; } showTimeInTable += "</tr>"; } //third part in the table =>show every day in this month function ThirdPartInTable(willchangedYear,willchangedMonth) { //setting the select selectlistsetting(willchangedYear,willchangedMonth); ThirdPartTime = new Date(); //set the first day of the month ThirdPartShortTime = new Date(ThirdPartTime.setYear(willchangedYear)); ThirdPartShortTime = new Date(ThirdPartTime.setMonth(willchangedMonth-1)); ThirdPartShortTIme = new Date(ThirdPartTime.setDate("1")); ThirdPartYear = ThirdPartTime.getYear();//get year ThirdPartMonthConfirm = ThirdPartTime.getMonth() + 1;//get the month ThirdPartDate = ThirdPartTime.getDate();//get the date of the month ThirdPartDay = ThirdPartTime.getDay();//get the weekday of the day of the month ThirdPartChangeTime = ThirdPartTime.getTime(); //set the blank before the firstday of the month in table startblank(ThirdPartDay); //set all date of the month do { //set all date in table TableRoundDate(ThirdPartYear,ThirdPartMonthConfirm,ThirdPartDay,ThirdPartDate); ThirdPartChangeTime += 24*60*60*1000; ThirdPartShortTime = new Date(ThirdPartTime.setTime(ThirdPartChangeTime)); ThirdPartYear = ThirdPartTime.getYear();//get year ThirdPartMonth = ThirdPartTime.getMonth() + 1;//get the month ThirdPartDate = ThirdPartTime.getDate();//get the date of the month ThirdPartDay = ThirdPartTime.getDay();//get the weekday of the day of the month ThirdPartChangeTime = ThirdPartTime.getTime(); } while (ThirdPartMonthConfirm == ThirdPartMonth); //set the blank before the firstday of the month in table endblank(ThirdPartDay); showTimeInTable += "</table>";//table end } //select list setting function selectlistsetting(willchangedYear,willchangedMonth) { //year select setting var setselectyear = document.getElementById("yearlist"); for (var i = 0;i < setselectyear.length;i++) { if (setselectyear.options[i].text == willchangedYear) { setselectyear.options[i].selected = true; break; } } //month select setting var setselectmonth = document.getElementById("monthlist"); for (var i = 0;i <setselectmonth.length;i++) { if (setselectmonth.options[i].text == willchangedMonth) { setselectmonth.options[i].selected = true; break; } } } //set the blank before the firstday of the month in table function startblank(firstWeekDay) { showTimeInTable += "<tr>"; for (var i=0;i < firstWeekDay;i++) { showTimeInTable += "<td>" + " " + "</td>"; } } //set the blank after the lastday of the month in table function endblank(lastWeekDay) { if (lastWeekDay != 0) { for (var i=0;i<(7-lastWeekDay);i++ ) { showTimeInTable += "<td>" + " " + "</td>"; } } showTimeInTable += "</tr>"; } //set the all date of month function TableRoundDate(Year,Month,Day,DateTime) { if ((nowTimeYear == Year)&&(nowTimeMonth == Month)&&(nowTimeDate == DateTime))//set today red { if (Day == 0) { showTimeInTable += "<tr><td class = 'today'>" + DateTime +"</td>"; } else if (Day == 6) { showTimeInTable += "<td class = 'today'>" + DateTime +"</td></tr>"; } else { showTimeInTable += "<td class = 'today'>" + DateTime +"</td>"; } } else { if (Day == 0) { showTimeInTable += "<tr><td class = 'sunsat'>" + DateTime +"</td>"; } else if (Day == 6) { showTimeInTable += "<td class = 'sunsat'>" + DateTime +"</td></tr>"; } else { showTimeInTable += "<td>" + DateTime +"</td>"; } } } //input the 0 before some numbers function inputzero(num) { num = parseInt(num);//change string to int if (num < 10) { num = "0" + num; } return num; } // --></mce:script> </head> <body onload = "allpage();"> <!-- title --> <div> <h1>Calendar</h1> </div> <!--the text--> <div> <input type = "text" id = "text"> </div><br> <div> <input type = "button" class = "buttonToday" value = "Today" onclick = timeintable('today');> <select id = "yearlist" onchange = timeintable("selectyear");> <mce:script type = "text/javascript"><!-- for (var i= 1970;i < 2071;i++) { document.write("<option>" + i + "</option>"); } // --></mce:script> </select> <select id = "monthlist" onchange = timeintable("selectmonth");> <mce:script type = "text/javascript"><!-- for (var i= 1;i < 13;i++) { document.write("<option>" + i + "</option>"); } // --></mce:script> </select> </div> <!--the table--> <div id = "showtable"> </div> </body> </html>