// JavaScript Document
// JavaScript Document


var timerID = null;
var timerRunning = false;

function stopclock (){
	if(timerRunning)
	clearTimeout(timerID);
	timerRunning = false;
}

//显示当前时间
function showtime () {
	var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds()
	var timeValue = " " + ((hours >12) ? hours -12 :hours)
	timeValue += ((minutes < 10) ? ":0" : ":") + minutes
	timeValue += ((seconds < 10) ? ":0" : ":") + seconds
	timeValue += (hours >= 12) ? " 下午 " : " 上午 "
	document.clock.face.value = timeValue;
	timerID = setTimeout("showtime()",1000);//设置超时,使时间动态显示
	timerRunning = true;
}

function startclock () {
	stopclock();
	showtime();
}


function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11) 
{
this[0] = m0;
this[1] = m1;
this[2] = m2;
this[3] = m3;
this[4] = m4;
this[5] = m5;
this[6] = m6;
this[7] = m7;
this[8] = m8;
this[9] = m9;
this[10] = m10;
this[11] = m11;
}

//实现月历
function calendar() {
		
	var monthNames = "JanFebMarAprMayJunJulAugSepOctNovDec";
	var today = new Date();
	var thisDay;
	var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	year = today.getYear() +1900;
	thisDay = today.getDate();
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) monthDays[1] = 29;
	nDays = monthDays[today.getMonth()];
	firstDay = today;
	firstDay.setDate(1);
	testMe = firstDay.getDate();
	if (testMe == 2) firstDay.setDate(0);
	startDay = firstDay.getDay();
	
	var dayNames = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
	var monthNames = new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");
	var now = new Date();
	
	document.write("<TABLE  align='center'  BORDER='0' CELLSPACING='0' CELLPADDING='0'>")
	document.write("<tr><TD>");
	document.write("<table border='1' bordercolor='#FFFFFF'  cellspacing='0' cellpadding='1' style='border-collapse:collapse;'");
	//document.write("<tr><td colspan='7' STYLE='text-align: left;background-image: url(/Templets/image/gov/calendarHead.gif);background-repeat: no-repeat;	background-position: 5px 0px;height:45px;font-size:14px;font-weight:bold;Color:#ee9900'>");
	document.write("<tr><td colspan='7'><div id='calendarhead'><br><br>");
	document.writeln(monthNames[now.getMonth()]+"&nbsp;&nbsp;"+ now.getYear());
	document.writeln("</div></td></tr><tr style='color:#ffffff;' bgcolor='#D80800'>");
	document.writeln("<td>Sun</td>");
	document.writeln("<td>Mon</td>");
	document.writeln("<td>Tue</td>");
	document.writeln("<td>Wed</td>");
	document.writeln("<td>Thu</td>");
	document.writeln("<td>&nbsp;Fri&nbsp;</td>");
	document.writeln("<td>&nbsp;Sat&nbsp;</td></tr>");
	
	document.writeln("<tr height='20'>");
	
	//前置空格
	column = 0;
	for (i=0; i<startDay; i++) {
		document.writeln("<td></td>");
		column++;
	}
	
	//月内每一日
	for (i=1; i<=nDays; i++) {
		if (i == thisDay) 
			document.writeln("</TD><TD style='font-weight: bold;font-family:Arial, Helvetica, sans-serif;font-size:9px;color:#ffffff' bgcolor='#DB5D59'>")
		else 
			document.writeln("</TD><TD style='font-family:Arial, Helvetica, sans-serif;font-size:9px;color:#333333'>");
		
		document.writeln(i);
		document.writeln("</TD>")
		
		column++;
		if (column == 7) {
			document.writeln("</tr><tr height='20'>"); 
			column = 0;
		}
	}
	//尾部空格
	for (i=0; i<7-column; i++) document.writeln("<td></td>");
	//封闭行
	document.writeln("</tr>")
	
	//时间框
	document.writeln("<tr><FORM NAME='clock' onSubmit='return false;'><TD COLSPAN='7' ALIGN='CENTER' VALIGN='TOP'>")
	document.writeln("<INPUT TYPE='Text' NAME='face' style='font-family:宋体 ;font-size:12px'></TD></FORM></tr></TABLE>")
	document.writeln("</TD></tr></TABLE>");
}
