javascript写的小日历
var text;
var flag = 0;
var cx=0;
var cy=0;
var val=0;
var running=false;
var stx,sty;
function locate()
{ cx=window.event.x;
cy=window.event.y;
}
document.onmousemove=locate;
function mousemove(){
var x,y;
x=cx-stx;
y=cy-sty;
if(x<0) {x=0;}
if(y<0) {y=0;}
with(calendar.style)
{
left=x.toString()+"px";
top=y.toString()+"px";
}
}
function mousedown(){
with(calendar.style)
{
stx=cx-parseInt(left.substring(0,left.charAt('p')+1));
sty=cy-parseInt(top.substring(0,top.charAt('p')+1));
}
if(!running){
val=setInterval("mousemove()",10);
running=true;
}
else{
clearInterval(val);
running=false;
}
}
function mouseup(){
if(running){
clearInterval(val);
running=false;
}
}
function MakeCal(date,intCount) {
var z1, z2,blntoday
var today = new Date();
if (date == null) {
var szMonth = today.getMonth();
var szYear = today.getFullYear();
var szDate = today.getDate();
}
else {
z1 = date.indexOf("/");
z2 = date.indexOf("/", 3);
var szMonth = Number(date.slice(0,z1)) - 1;
var szYear = Number(date.slice(z2 + 1, z2+ 5));
if(szMonth < 0){
szMonth = 11;
szYear = szYear - 1;
}
else if(szMonth > 11){
szMonth = 0;
szYear = szYear + 1;
}
var szDate = Number(date.slice(z1 + 1,z2));
}
var x, intTemp, szId, max, todayx, startx;
var szStart = new Date(szYear, szMonth, 1);
var intDay = szStart.getDay();
var blSet = false;
var szCal;
szStart.setMonth(szMonth - 1);
var PrevMonth = szStart.getMonth();
var PrevYear = szStart.getFullYear();
szStart = new Date(szYear, szMonth, 1);
szStart.setMonth(szMonth + 1);
var NextMonth = szStart.getMonth();
var NextYear = szStart.getFullYear();
szStart = new Date(szYear, szMonth, 1);
szCal = "" ;
szCal = szCal + "<table id=tblBor width=100% border=0 bgcolor=#D6C7DA style=\"border-style:solid;border-width:1px;border-color:black\" cellspacing=0 cellpadding=0 align='center'><tr><td>";
szCal = szCal + "<table id=tblCal width=100% border=0 bgcolor=#E7EAE6 style=\"cursor:default;\" cellspacing=0 cellpadding=3 >";
if (szStart.getMonth() == (szMonth))
szCal = szCal + "<tr bgcolor=#BDE6E8 onmouseup=\"mouseup();\" onmousedown=\"mousedown()\"><td colspan=6 align=center id=title style=\"cursor:default;\"><div style=\"display:none;\" id=\"whoactive\">"+MakeString(szStart.getMonth())+"10</div>" +"<font color=#00009F>"+ MakeStringT(szMonth)+"</Font>" + " " +"<Font Color =#00009F>"+ szYear + "年"+"</font>"+"</td><td><input type=button value=× style=\"background-color: #DFECEC; width: 18; height: 18\" onclick=\"calendar.style.visibility='hidden'\"></td></tr>";
else
szCal = szCal + "<tr bgcolor=#BDE6E8 onmouseup=\"mouseup();\" onmousedown=\"mousedown()\"><td colspan=6 align=center id=title style=\"cursor:default;\"><div style=\"display:none;\" id=\"whoactive\">"+MakeString(szStart.getMonth())+"10</div>" +"<font color=#7F7F7F>"+ MakeStringT(szMonth)+"</Font>" + " " +"<Font Color =#7F7F7F>"+ szYear + "年"+"</font>"+"</td><td><input type=button value=× style=\"background-color: #DFECEC; width: 18; height: 18\" onclick=\"calendar.style.visibility='hidden'\"></td></tr>";
szCal = szCal + "<tr id=rowTitle style=\"cursor:default;\"><td><font color=#53A46B>日</font></td><td><font color=#0A13C0>一</font></td><td><font color=#0A13C0>二</font></td><td><font color=#0A13C0>三</font></td><td><font color=#0A13C0>四</font></td><td><font color=#0A13C0>五</font></td><td><font color=#53A46B>六</font></td></tr>";
for (x=1; x<43; x++) {
if (x % 7 == 1) {
szCal = szCal + "<tr>"
}
szStart = new Date(szYear, szMonth, 1);
intTemp = (-(intDay - x));
szStart.setDate(intTemp);
szId = MakeString(szStart.getMonth()) + x;
if (!blSet) {
if (szStart.getMonth() == (szMonth + 1)) {
blSet = true;
max = x;
}
if (szStart.getFullYear() == (szYear + 1)) {
blSet = true;
max = x;
}
}
blntoday = 0;
if (szStart.getDate() == today.getDate()) {
if (szStart.getMonth() == today.getMonth()) {
if (szStart.getYear() == today.getYear()) {
todayx = x;
blntoday = 1;
}
}
}
szCal = szCal + "<td ";
if(intCount == 0){
if (szStart.getMonth() == (szMonth)) {
if (szStart.getDate() == today.getDate()) {
szCal = szCal + "onclick=\"setVal('" + (szStart.getMonth() + 1 ) + "/" + szStart.getDate() + "/" + szStart.getFullYear() + "','0');document.getElementById(whoactive.innerHTML).style.backgroundColor=\'#E7EAE6\';\"";
}
else
{
szCal = szCal + "onclick=\"setVal('" + (szStart.getMonth() + 1 ) + "/" + szStart.getDate() + "/" + szStart.getFullYear() + "','0');document.getElementById(whoactive.innerHTML).style.backgroundColor=\'#E7EAE6\';this.style.backgroundColor=\'#aaaaaa\';whoactive.innerHTML=this.id;\"";
}
}
else {
szCal = szCal + "onclick=\"MakeCal('" + (szStart.getMonth() + 1 ) + "/" + szStart.getDate() + "/" + szStart.getFullYear() + "','0')\"";
}
}
if(intCount == 1){
if (szStart.getMonth() == (szMonth)) {
if (szStart.getDate() == today.getDate()) {
szCal = szCal + "onclick=\"setVal('" + (szStart.getMonth() + 1 ) + "/" + szStart.getDate() + "/" + szStart.getFullYear() + "','1')document.getElementById(whoactive.innerHTML).style.backgroundColor=\'#E7EAE6\';\"";
}
else
{
szCal = szCal + "onclick=\"setVal('" + (szStart.getMonth() + 1 ) + "/" + szStart.getDate() + "/" + szStart.getFullYear() + "','1');document.getElementById(whoactive.innerHTML).style.backgroundColor=\'#E7EAE6\';this.style.backgroundColor=\

