//基础数据
var lunarInfo=new Array(
0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5,
0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930,
0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530,
0x05aa0,0x076a3,0x096d0,0x04bd7,0x04ad0,0x0a4d0,0x1d0b6,0x0d250,0x0d520,0x0dd45,
0x0b5a0,0x056d0,0x055b2,0x049b0,0x0a577,0x0a4b0,0x0aa50,0x1b255,0x06d20,0x0ada0
);
var sTermInfo=new Array(
0,21202,42459,63812,85302,106954,128791,150819,173029,195409,217918,240527,
263173,285822,308402,330888,353218,375387,397357,419146,440747,462198,483516,504757
);
var nStr1 = new Array('日','一','二','三','四','五','六','七','八','九','十',"十一","十二");
var nStr2 = new Array('初','十','廿','卅');

//公历
function calendar(objDate) {
 this.year=objDate.getFullYear();
 this.month=objDate.getMonth()+1;
 this.day=objDate.getDate();
 this.week=nStr1[objDate.getDay()];
}

//阴历
function lYearDays(y) {
 var i,sum=348;
 for (i=0x8000;i>0x8;i>>=1) sum+=(lunarInfo[y-2000] & i) ? 1:0;
 return (sum+leapDays(y));
}
function lMonthDays(y,m) {
 return ((lunarInfo[y-2000] & (0x10000>>m)) ? 30:29);
}
function leapDays(y) {
 if (leapMonth(y)) return ((lunarInfo[y-2000] & 0x10000) ? 30:29);
 else return (0);
}
function leapMonth(y) {
 return (lunarInfo[y-2000] & 0xf);
}
function lDayTrans(d) {
 var str;
 switch (d) {
  case 10: str="初十";break;
  case 20: str="二十";break;
  case 30: str="三十";break;
  default: 
   str=nStr2[Math.floor(d/10)];
   str+=nStr1[d%10];
 }
 return (str);
}
function lunar(objDate) {
 var i,leap=0,temp=0;
 var offset=(Date.UTC(objDate.getFullYear(),objDate.getMonth(),objDate.getDate())-Date.UTC(2000,1,5))/8.64E7;
 if (offset<0 || offset>((Date.UTC(2050,0,22)-Date.UTC(2000,1,5))/8.64E7)) {
  this.year=this.month=this.day="";
  this.isLeap=false;
  return;
 }
 for (i=2000;offset>0;i++) {
  temp=lYearDays(i);
  offset-=temp;
 }
 if (offset<0) {
  --i;
  offset+=temp;
 }
 this.year=i;
 leap=leapMonth(this.year);
 this.isLeap=false;
 for (i=1;i<13 && offset>0;i++) {
  if (leap>0 && i==leap+1 && this.isLeap==false) {
   --i;
   temp=leapDays(this.year);
   this.isLeap=true;
  }
  else {
   temp=lMonthDays(this.year,i);
  }
  if (i==leap+1 && this.isLeap==true) this.isLeap=false;
  offset-=temp;
 }
 if (offset==0 && leap>0 && i==leap+1) {
  if (this.isLeap) {
   this.isLeap=false;
  }
  else {
   this.isLeap=true;
   --i;
  }
 }
 if (offset<0) {
  --i;
  offset+=temp;
 }
 this.month=i;
 this.day=offset+1;
 this.isBig=((this.isLeap) ? leapDays(this.month):lMonthDays(this.year,this.month) == 30) ? true:false;
}

function output() {
 var today, cld, lun, result="";
 today=new Date();
 cld=new calendar(today);
 lun=new lunar(today);
 
 result += ""+cld.year+"年"+cld.month+"月"+cld.day+"日&nbsp;星期"+cld.week+"&nbsp;&nbsp;农历";
 result += ((lun.isLeap) ? "闰":"")+nStr1[lun.month]+"月"+((lun.isBig) ? "(大)":"(小)");
 result += lDayTrans(lun.day)+"日";
 return result;
}

document.write(output());


