﻿var show = false;
document.writeln('<div id=meizzDateLayer style="position: absolute; width: 142; z-index: 9998; display: none">');
document.writeln('<span id=tmpSelectYearLayer  style="z-index: 9999;position: absolute;top: 2; left: 18;display: none"></span>');
document.writeln('<span id=tmpSelectMonthLayer style="z-index: 9999;position: absolute;top: 2; left: 75;display: none"></span>');
document.writeln('<table class="table1" border=0 cellspacing=1 cellpadding=0 width=142 bgcolor=#808080 onselectstart="return false">');
document.writeln('<tr><td width=142 height=23 bgcolor=#FFFFFF><table border=0 cellspacing=1 cellpadding=0 width=140 height=23>');
document.writeln('<tr align=center><td width=20 align=center bgcolor=navy style="font-size:12px;cursor: pointer;color: #ffffff" ');
document.writeln('onclick="meizzPrevM()" class="TH" title="上一个月" Author=meizz><b Author=meizz>&lt;&lt;</b>');
document.writeln('</td><td class="TB" width=100 align=center style="font-size:12px;cursor:default" Author=meizz>');
document.writeln('<span Author=meizz id=meizzYearHead onclick="tmpSelectYearInnerHTML(this.innerText)"></span>&nbsp;年&nbsp;<span');
document.writeln('id=meizzMonthHead Author=meizz onclick="tmpSelectMonthInnerHTML(this.innerText)"></span>&nbsp;月</td>');
document.writeln('<td width=20 class="TH" bgcolor=navy align=center style="font-size:12px;cursor: pointer;color: #ffffff" ');
document.writeln('onclick="meizzNextM()" title="下一个月" Author=meizz><b Author=meizz>&gt;&gt;</b></td></tr>');
document.writeln('</table></td></tr>');
document.writeln('<tr><td width=142 height=18 class=TH>');
document.writeln('<table border=0 cellspacing=3 cellpadding=0 width=140 height=1 style="cursor:default">');
document.writeln('<tr align=center class="TH"><td width=20 style="font-size:12px;color:#FFFFFF" Author=meizz>日</td>');
document.writeln('<td width=20 style="font-size:12px;color:#FFFFFF" Author=meizz>一</td><td width=20 style="font-size:12px;color:#FFFFFF" Author=meizz>二</td>');
document.writeln('<td width=20 style="font-size:12px;color:#FFFFFF" Author=meizz>三</td><td width=20 style="font-size:12px;color:#FFFFFF" Author=meizz>四</td>');
document.writeln('<td width=20 style="font-size:12px;color:#FFFFFF" Author=meizz>五</td><td width=20 style="font-size:12px;color:#FFFFFF" Author=meizz>六</td></tr>');
document.writeln('</table></td></tr>');
document.writeln('  <tr><td width=142 height=120>');
document.writeln('    <table border=0 cellspacing=1 cellpadding=0 width=140 height=120 bgcolor=#ffffff>');
var n=0; for (var j=0;j<5;j++){
document.writeln (' <tr align=center>');
for (var i=0;i<7;i++){
document.writeln('<td width=20 height=20 id=meizzDay'+n+' style="font-size:12px" Author=meizz onclick=meizzDayClick(this.innerText)></td>');n++;}
document.writeln('</tr>');}
document.writeln('<tr align=center><td width=20 height=1 style="font-size:12px" id=meizzDay35 Author=meizz ');
document.writeln('onclick=meizzDayClick(this.innerText)></td>');
document.writeln('<td width=20 height=1 style="font-size:12px" id=meizzDay36 Author=meizz onclick=meizzDayClick(this.innerText)></td></tr>');
document.writeln('</table></td></tr><tr><td>');
document.writeln('<table class="TH" border=0 cellspacing=1 cellpadding=0 width=100% bgcolor=#FFFFFF>');
document.writeln('<tr><td Author=meizz align=left><input Author=meizz class="form1" type=button value="< " title="向前翻一年" onclick="meizzPrevY()" ');
document.writeln('onfocus="this.blur()" style="font-size: 12px; height: 20px"><input Author=meizz title="上一个月" type=button ');
document.writeln('value="<<" onclick="meizzPrevM()" class="form1" onfocus="this.blur()" style="font-size: 12px; height: 20px"></td><td ');
document.writeln('Author=meizz align=center><input Author=meizz class="form1" type=button value="今 天" onclick="meizzToday()"');
document.writeln('onfocus="this.blur()" title="现在的年月" style="font-size: 12px; height: 20px"> <!--<input Author=meizz type=button value="取 消" onclick="clsdiv()" onfocus="this.blur()" class="form1" title="取消当前的操作,不对日期进行任何更改!" style="font-size: 12px; height: 20px">--> </td><td ');
document.writeln('Author=meizz align=right><input Author=meizz class="form1" type=button value=">>" onclick="meizzNextM()" ');
document.writeln('onfocus="this.blur()" title="下一个月" style="font-size: 12px; height: 20px"><input ');
document.writeln('Author=meizz type=button class="form1" value=" >" title="往后翻一年" onclick="meizzNextY()"');
document.writeln('onfocus="this.blur()" style="font-size: 12px; height: 20px"></td>');
document.writeln('</tr></table></td></tr></table></div>');
var outObject;
 
function setday(tt,obj){
	window.event.cancelBubble = true;
	if(show = !show){
		setday1(tt,obj);
	}
	else {
		closeLayer();
	}
}
function setSearchday(tt,obj){
	window.event.cancelBubble = true;
	if(show = !show){
		setday1(tt,obj);
	}
	else {
		closeLayer();
	}
}
function setSelectVisible(display){
	var sels = document.getElementsByTagName("SELECT");
	for(var i = 0; i < sels.length; i++){
		sels[i].style.display = display;
	}
}

function setday1(tt,obj)
{
  window.event.cancelBubble = true;
  if (arguments.length >  2){alert("对不起！传入本控件的参数太多！");return;}
  if (arguments.length == 0){alert("对不起！您没有传回本控件任何参数！");return;}
  var dads  = document.getElementById("meizzDateLayer").style;var th = tt;
  var ttop  = tt.offsetTop;
  var thei  = tt.clientHeight;
  var tleft = tt.offsetLeft;
  var ttyp  = tt.type;
  while (tt = tt.offsetParent){ttop+=tt.offsetTop; tleft+=tt.offsetLeft;}
  dads.top  = ((ttyp=="image")? ttop+thei : ttop+thei+6) + "px";
  dads.left = tleft + "px";
  outObject = (arguments.length == 1) ? th : obj;
  dads.display = '';
  event.returnValue=false;
}
var MonHead = new Array(12);
    MonHead[0] = 31; MonHead[1] = 28; MonHead[2] = 31; MonHead[3] = 30; MonHead[4]  = 31; MonHead[5]  = 30;
    MonHead[6] = 31; MonHead[7] = 31; MonHead[8] = 30; MonHead[9] = 31; MonHead[10] = 30; MonHead[11] = 31;
var meizzTheYear=new Date().getFullYear();
var meizzTheMonth=new Date().getMonth()+1;
var meizzWDay=new Array(37);
/*
function click()
{
  with(window.event.srcElement)
  { if (getAttribute("Author")==null && tagName != "input")
    document.getElementById("meizzDateLayer").style.display="none";
  }
}*/
function meizzWriteHead(yy,mm)
  { document.getElementById("meizzYearHead").innerHTML  = yy;
    document.getElementById("meizzMonthHead").innerHTML = mm;
  }
 
function tmpSelectYearInnerHTML(strYear)
{
	window.event.cancelBubble = true;
  if (strYear.match(/\D/)!=null){alert("年份输入参数不是数字！");return;}
  var m = (strYear) ? strYear : new Date().getFullYear();
  if (m < 1000 || m > 9999) {alert("年份值不在 1000 到 9999 之间！");return;}
  var n = m - 16;
  if (n < 1000) n = 1000;
  if (n + 26 > 9999) n = 9974;
  var s = "<select Author=meizz name=tmpSelectYear id=tmpSelectYear class='form1' style='font-size: 12px' "
     s += "ondblclick='document.getElementById('tmpSelectYear').style.display=\"none\"' "
	 s += "onblur='document.getElementById('tmpSelectYearLayer').style.display=\"none\"' onclick='window.event.cancelBubble = true;'"
     s += "onchange='document.getElementById('tmpSelectYearLayer').style.display=\"none\";"
     s += "meizzTheYear = this.value; meizzSetDay(meizzTheYear,meizzTheMonth)'>\r\n";
  var selectInnerHTML = s;
  for (var i = n; i < n + 26; i++)
  {
    if (i == m)
       {selectInnerHTML += "<option value='" + i + "' selected>" + i + "年" + "</option>\r\n";}
    else {selectInnerHTML += "<option value='" + i + "'>" + i + "年" + "</option>\r\n";}
  }
  selectInnerHTML += "</select>";
  document.getElementById("tmpSelectYearLayer").style.display="";
  document.getElementById("tmpSelectYearLayer").innerHTML = selectInnerHTML;
  document.getElementById("tmpSelectYear").focus();
}
function tmpSelectMonthInnerHTML(strMonth)
{
	window.event.cancelBubble = true;
  if (strMonth.match(/\D/)!=null){alert("月份输入参数不是数字！");return;}
  var m = (strMonth) ? strMonth : new Date().getMonth() + 1;
  var s = "<select Author=meizz class='form1' name=tmpSelectMonth id=tmpSelectMonth style='font-size: 12px' "
     s += "ondblclick='document.getElementById('tmpSelectMonth').style.display=\"none\"' "
	 s += "onblur='document.getElementById('tmpSelectMonthLayer').style.display=\"none\"' "
     s += "onchange='document.getElementById('tmpSelectMonthLayer').style.display=\"none\";"
     s += "meizzTheMonth = this.value; meizzSetDay(meizzTheYear,meizzTheMonth)'>\r\n";
  var selectInnerHTML = s;
  for (var i = 1; i < 13; i++)
  {
    if (i == m)
       {selectInnerHTML += "<option value='"+i+"' selected>"+i+"月"+"</option>\r\n";}
    else {selectInnerHTML += "<option value='"+i+"'>"+i+"月"+"</option>\r\n";}
  }
  selectInnerHTML += "</select>";
  document.getElementById("tmpSelectMonthLayer").style.display="";
  
  document.getElementById("tmpSelectMonthLayer").innerHTML = selectInnerHTML;
  document.getElementById("tmpSelectMonth").focus();
}
function closeLayer()
  {
  	if(document.getElementById("meizzDateLayer")){
    	document.getElementById("meizzDateLayer").style.display="none";
    	setSelectVisible('inline');
    	show = false;
    }
  }
/*
function document.onkeydown()
  {
    if (window.event.keyCode==27)document.getElementById("meizzDateLayer").style.display="none";
  }
  */
function IsPinYear(year)
  {
    if (0==year%4&&((year%100!=0)||(year%400==0))) return true;else return false;
  }
function GetMonthCount(year,month)
  {
    var c=MonHead[month-1];if((month==2)&&IsPinYear(year)) c++;return c;
  }
function GetDOW(day,month,year)
  {
    var dt=new Date(year,month-1,day).getDay()/7; return dt;
  }
function meizzPrevY()
  {
  	window.event.cancelBubble = true;
    if(meizzTheYear > 999 && meizzTheYear <10000){meizzTheYear--;}
    else{alert("年份超出范围（1000-9999）！");}
    meizzSetDay(meizzTheYear,meizzTheMonth);
  }
function meizzNextY()
  {
  	window.event.cancelBubble = true;
    if(meizzTheYear > 999 && meizzTheYear <10000){meizzTheYear++;}
    else{alert("年份超出范围（1000-9999）！");}
    meizzSetDay(meizzTheYear,meizzTheMonth);
  }
function meizzToday()
  {
  	window.event.cancelBubble = true;
    meizzTheYear = new Date().getFullYear();
    meizzTheMonth = new Date().getMonth()+1;
    meizzSetDay(meizzTheYear,meizzTheMonth);
  }
function meizzPrevM()
  {
  	window.event.cancelBubble = true;
    if(meizzTheMonth>1){meizzTheMonth--}else{meizzTheYear--;meizzTheMonth=12;}
    meizzSetDay(meizzTheYear,meizzTheMonth);
  }
function meizzNextM()
  {
  	window.event.cancelBubble = true;
    if(meizzTheMonth==12){meizzTheYear++;meizzTheMonth=1}else{meizzTheMonth++}
    meizzSetDay(meizzTheYear,meizzTheMonth);
  }
function meizzSetDay(yy,mm)
{
  meizzWriteHead(yy,mm);

  for (var i = 0; i < 37; i++){meizzWDay[i]=""};
  var day1 = 1,firstday = new Date(yy,mm-1,1).getDay();
  for (var i = firstday; day1 < GetMonthCount(yy,mm)+1; i++){meizzWDay[i]=day1;day1++;}
  for (var i = 0; i < 37; i++)
  { var da = eval("document.getElementById('meizzDay"+i+"')")
    if (meizzWDay[i]!="")
      { da.innerHTML = "<b>" + meizzWDay[i] + "</b>";
        da.className = (yy == new Date().getFullYear() &&
        mm == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate()) ? "TH" : "TB";
        da.style.cursor="pointer"
      }
    else{da.innerHTML="";da.style.backgroundColor="";da.style.cursor="default"}
  }
}
function meizzDayClick(n)
{
	window.event.cancelBubble = true;
  var yy = meizzTheYear;
  var mm = meizzTheMonth;
  if (mm < 10){mm = "0" + mm;}
  if (outObject)
  {
    if (!n) {outObject.value=""; return;}
    if ( n < 10){n = "0" + n;}
    outObject.value= yy + "-" + mm + "-" + n ;
    closeLayer();
  }
  else {closeLayer(); alert("您所要输出的控件对象并不存在！");}
}
function clsdiv()
{
 closeLayer();
}
meizzSetDay(meizzTheYear,meizzTheMonth);