var isInputDateInit = false;
var ne_wf_webInputDate_oPopup = window.createPopup();
function initInputDate(){
	if(isInputDateInit)
		return;
	else
		isInputDateInit = true;
	var inputDateStr = "";
	
	inputDateStr += '<div id=meizzDateLayer style="position: absolute;left:0; top:0; width: 142; height: 166; z-index: 9998; display: block;">';
	inputDateStr += '<span id=tmpSelectYearLayer style="z-index: 9999;position: absolute;top: 2; left: 18;display: none"></span>';
	
	inputDateStr += '<span id=tmpSelectMonthLayer style="z-index: 9999;position: absolute;top: 2; left: 75;display: none"></span>';
	
	inputDateStr += '<table border=0 cellspacing=1 cellpadding=0 width=142 height=160 bgcolor=#808080 onselectstart="return false">';

	inputDateStr += '<tr Author=meizz><td width=142 bgcolor=#FFFFFF align=center>';
	inputDateStr += '<div Author=meizz id="meizzHourMinute" style="z-index: 9997; display: none;text-align: center;font-size: 12px;">';
	inputDateStr += '时间:<select Author=meizz id="meizzHour" onchange="parent.meizzTheHour=this.value">';
	for(i=0;i<24;i++){var tmp =i>9?""+i:"0"+i; inputDateStr += '<option value="'+tmp+'">'+tmp+'</option>';}
	inputDateStr += '</select>:<select Author=meizz id="meizzMinute" onchange="parent.meizzTheMinute=this.value">>';
	for(i=0;i<60;i++){var tmp =i>9?""+i:"0"+i; inputDateStr += '<option value="'+tmp+'">'+tmp+'</option>';}
	inputDateStr += '</select>';
	inputDateStr += '</div>';
	inputDateStr += '</td></tr>';
	
	inputDateStr += '  <tr><td width=142 height=23 bgcolor=#FFFFFF><table border=0 cellspacing=1 cellpadding=0 width=140 height=23>';
	
	inputDateStr += '      <tr align=center><td width=20 align=center bgcolor=#808080 style="font-size:12px;cursor: hand;color: #FFD700" ';
	
	inputDateStr += '        onclick="parent.meizzPrevM()" title="向前翻 1 月" Author=meizz><b Author=meizz><<</b>';
	
	inputDateStr += '        </td><td width=100 align=center style="font-size:12px;cursor:default" Author=meizz><span ';
	
	inputDateStr += ' onmouseover="style.backgroundColor=\'#FFD700\'" onmouseout="style.backgroundColor=\'white\'" title="点击这里选择年份"';
	
	inputDateStr += '         Author=meizz id=meizzYearHead onclick="parent.tmpSelectYearInnerHTML(this.innerText)">2000</span> 年 <span';
	
	inputDateStr += ' onmouseover="style.backgroundColor=\'#FFD700\'" onmouseout="style.backgroundColor=\'white\'" title="点击这里选择月份"';
	
	inputDateStr += '         Author=meizz id=meizzMonthHead onclick="parent.tmpSelectMonthInnerHTML(this.innerText)">1</span> 月</td>';
	
	inputDateStr += '        <td width=20 bgcolor=#808080 align=center style="font-size:12px;cursor: hand;color: #FFD700" ';
	
	inputDateStr += '         onclick="parent.meizzNextM()" title="往后翻 1 月" Author=meizz><b Author=meizz>>></b></td></tr>';
	
	inputDateStr += '    </table></td></tr>';
	
	inputDateStr += '  <tr><td width=142 height=18 bgcolor=#808080>';
	
	inputDateStr += '<table border=0 cellspacing=0 cellpadding=0 width=140 height=1 style="cursor:default">';
	
	inputDateStr += '<tr align=center><td style="font-size:12px;color:#FFFFFF" Author=meizz>日</td>';
	
	inputDateStr += '<td style="font-size:12px;color:#FFFFFF" Author=meizz>一</td><td style="font-size:12px;color:#FFFFFF" Author=meizz>二</td>';
	
	inputDateStr += '<td style="font-size:12px;color:#FFFFFF" Author=meizz>三</td><td style="font-size:12px;color:#FFFFFF" Author=meizz>四</td>';
	
	inputDateStr += '<td style="font-size:12px;color:#FFFFFF" Author=meizz>五</td><td style="font-size:12px;color:#FFFFFF" Author=meizz>六</td></tr>';
	
	inputDateStr += '</table></td></tr><!-- Author:F.R.Huang(meizz) http://www.meizz.com/ mail: meizz@hzcnc.com 2002-10-8 -->';
	
	inputDateStr += '  <tr><td width=142 height=120>';
	
	inputDateStr += '    <table border=0 cellspacing=1 cellpadding=0 width=140 height=120 bgcolor=#FFFFFF>';
	
	var n=0; for (j=0;j<5;j++){ inputDateStr += ' <tr align=center>'; for (i=0;i<7;i++){
	
	inputDateStr += '<td width=20 height=20 id=meizzDay'+n+' style="font-size:12px" Author=meizz onclick=parent.meizzDayClick(this.innerText)></td>';n++;}
	
	inputDateStr += '</tr>';}
	inputDateStr += '      <tr align=center><td width=20 height=20 style="font-size:12px" id=meizzDay35 Author=meizz ';
	
	inputDateStr += '         onclick=parent.meizzDayClick(this.innerText)></td>';
	
	inputDateStr += '        <td width=20 height=20 style="font-size:12px" id=meizzDay36 Author=meizz onclick=parent.meizzDayClick(this.innerText)></td>';
	
	
	inputDateStr += '        <td colspan=5 align=right Author=meizz>';
	inputDateStr += '        <span onclick=parent.meizzDayClick(-1) style="font-size:12px;cursor: hand" Author=meizz"><u>确定</u></span>';
	inputDateStr += '        <span onclick=parent.closeLayer() style="font-size:12px;cursor: hand" Author=meizz"><u>取消</u></span>';
	inputDateStr += '        </td></tr>';
	
	inputDateStr += '    </table></td></tr><tr><td>';
	
	inputDateStr += '        <table border=0 cellspacing=1 cellpadding=0 width=100% bgcolor=#FFFFFF>';
	
	inputDateStr += '          <tr><td Author=meizz align=left><input Author=meizz type=button value="< " title="向前翻 1 年" onclick="parent.meizzPrevY()" ';
	
	inputDateStr += '             onfocus="this.blur()" style="font-size: 12px; height: 20px"><input Author=meizz title="向前翻 1 月" type=button ';
	
	inputDateStr += '             value="<<" onclick="parent.meizzPrevM()" onfocus="this.blur()" style="font-size: 12px; height: 20px"></td><td ';
	
	inputDateStr += '             Author=meizz align=center><input Author=meizz type=button value="今天" onclick="parent.meizzToday()" ';
	
	inputDateStr += '             onfocus="this.blur()" title="现在的年月" style="font-size: 12px; height: 20px"></td><td ';
	
	inputDateStr += '             Author=meizz align=right><input Author=meizz type=button value=">>" onclick="parent.meizzNextM()" ';
	
	inputDateStr += '             onfocus="this.blur()" title="往后翻 1 月" style="font-size: 12px; height: 20px"><input ';
	
	inputDateStr += '             Author=meizz type=button value=" >" title="往后翻 1 年" onclick="parent.meizzNextY()"';
	
	inputDateStr += '             onfocus="this.blur()" style="font-size: 12px; height: 20px"></td>';
	
	inputDateStr += '</tr></table>';
	inputDateStr += '</td></tr>';
	inputDateStr += '</table>';
	inputDateStr += '</div>';
	ne_wf_webInputDate_oPopup.document.body.innerHTML = inputDateStr;
}
 
var outObject;
var meizz_isShowTime = false;

function setday(tt,obj,isShowTime) //主调函数

{

  if (arguments.length >  3){alert("对不起！传入本控件的参数太多！");return;}

  if (arguments.length == 0){alert("对不起！您没有传回本控件任何参数！");return;}

  var th = tt;

  var ttop  = tt.offsetTop;     //TT控件的定位点高

  var thei  = tt.clientHeight;  //TT控件本身的高

  var tleft = tt.offsetLeft;    //TT控件的定位点宽

  var ttyp  = tt.type;          //TT控件的类型

  while (tt = tt.offsetParent){ttop+=tt.offsetTop; tleft+=tt.offsetLeft;}
  outObject = (arguments.length == 1) ? th : obj;

	meizzTheYear=(outObject!=null && outObject.value!=null && !outObject.value=="")?outObject.value.substr(0,4)/1 : new Date().getFullYear(); //定义年的变量的初始值
	meizzTheMonth=(outObject!=null && outObject.value!=null && !outObject.value=="")?outObject.value.substr(5,2)/1 : (new Date().getMonth()+1); //定义月的变量的初始值
	meizzTheDay=(outObject!=null && outObject.value!=null && !outObject.value=="")?outObject.value.substr(8,2)/1 : (new Date().getDate()); //定义月的变量的初始值
	
	if(isShowTime){
		meizz_isShowTime = true;
		ne_wf_webInputDate_oPopup.show(tleft,((ttyp=="image")? ttop+thei : ttop+thei+6),142,219,document.body);
		meizzTheHour=(outObject!=null && outObject.value!=null && outObject.value.length>11)?outObject.value.substr(11,2) : "12";
		meizzTheMinute=(outObject!=null && outObject.value!=null && outObject.value.length>13)?outObject.value.substr(14,2) : "30";
		ne_wf_webInputDate_oPopup.document.getElementById("meizzHourMinute").style.display = 'block';
		ne_wf_webInputDate_oPopup.document.getElementById("meizzHour").style.display = '';
		ne_wf_webInputDate_oPopup.document.getElementById("meizzMinute").style.display = '';
		ne_wf_webInputDate_oPopup.document.getElementById("tmpSelectYearLayer").style.top = '24';
		ne_wf_webInputDate_oPopup.document.getElementById("tmpSelectMonthLayer").style.top = '24';
	}else{
		meizz_isShowTime = false;
		ne_wf_webInputDate_oPopup.show(tleft,((ttyp=="image")? ttop+thei : ttop+thei+6),142,195,document.body);
		ne_wf_webInputDate_oPopup.document.getElementById("meizzHourMinute").style.display = 'none';
		ne_wf_webInputDate_oPopup.document.getElementById("meizzHour").style.display = 'none';
		ne_wf_webInputDate_oPopup.document.getElementById("meizzMinute").style.display = 'none';
		ne_wf_webInputDate_oPopup.document.getElementById("tmpSelectYearLayer").style.top = '4';
		ne_wf_webInputDate_oPopup.document.getElementById("tmpSelectMonthLayer").style.top = '4';
	}
	meizzSetDay(meizzTheYear,meizzTheMonth);
	ne_wf_webInputDate_oPopup.document.getElementById("meizzHour").value=meizzTheHour;
	ne_wf_webInputDate_oPopup.document.getElementById("meizzMinute").value=meizzTheMinute;
	
  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);               //定义写日期的数组
var meizzTheDay="1";
var meizzTheHour="12";
var meizzTheMinute="30";

//往 head 中写入当前的年与月
function meizzWriteHead(yy,mm){ 
	ne_wf_webInputDate_oPopup.document.getElementById("meizzYearHead").innerText=yy;
    ne_wf_webInputDate_oPopup.document.getElementById("meizzMonthHead").innerText=mm;
  }



function tmpSelectYearInnerHTML(strYear) //年份的下拉框

{

  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 - 5;//开始年份

  if (n < 1000) n = 1000;

  if (n + 26 > 9999) n = 9974;

  var s = "<select Author=meizz name=tmpSelectYear style='font-size: 12px' ";

     //s += "onblur='document.getElementById(\"tmpSelectYearLayer\").style.display=\"none\"' ";

     s += "onchange='document.getElementById(\"tmpSelectYearLayer\").style.display=\"none\";";

     s += "parent.meizzTheYear = this.value; parent.meizzSetDay(parent.meizzTheYear,parent.meizzTheMonth);return true;'>\r\n";

  var selectInnerHTML = s;
  var mt = (m/1)+5;
  for (var i = n; i <= mt; i++)//结束年份

  {

    if (i == m)

       {selectInnerHTML += "<option value='" + i + "' selected>" + i + "年" + "</option>\r\n";}

    else {selectInnerHTML += "<option value='" + i + "'>" + i + "年" + "</option>\r\n";}

  }

  selectInnerHTML += "</select>";

  ne_wf_webInputDate_oPopup.document.getElementById("tmpSelectYearLayer").style.display="";

  ne_wf_webInputDate_oPopup.document.getElementById("tmpSelectYearLayer").innerHTML = selectInnerHTML;
	try{
  		ne_wf_webInputDate_oPopup.document.getElementById("tmpSelectYear").focus();
	}catch(err){};
}



function tmpSelectMonthInnerHTML(strMonth) //月份的下拉框

{

  if (strMonth.match(/\D/)!=null){alert("月份输入参数不是数字！");return;}

  var m = (strMonth) ? strMonth : new Date().getMonth() + 1;

  var s = "<select Author=meizz name=tmpSelectMonth style='font-size: 12px' "

     //s += "onblur='document.getElementById(\"tmpSelectMonthLayer\").style.display=\"none\"' "

     s += "onchange='document.getElementById(\"tmpSelectMonthLayer\").style.display=\"none\";"

     s += "parent.meizzTheMonth = this.value; parent.meizzSetDay(parent.meizzTheYear,parent.meizzTheMonth);return true;'>\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>";

  ne_wf_webInputDate_oPopup.document.getElementById("tmpSelectMonthLayer").style.display="";

  ne_wf_webInputDate_oPopup.document.getElementById("tmpSelectMonthLayer").innerHTML = selectInnerHTML;

	try{
	  ne_wf_webInputDate_oPopup.document.getElementById("tmpSelectMonth").focus();
	}catch(err){};
}



function closeLayer()               //这个层的关闭

  {
	ne_wf_webInputDate_oPopup.hide();
  }



function IsPinYear(year)            //判断是否闰平年

  {

    if (0==year%4&&((year%100!=0)||(year%400==0))) return true;else return false;

  }



function GetMonthCount(year,month)  //闰年二月为29天

  {

    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()  //往前翻 Year

  {

    if(meizzTheYear > 999 && meizzTheYear <10000){meizzTheYear--;}

    else{alert("年份超出范围（1000-9999）！");}

    meizzSetDay(meizzTheYear,meizzTheMonth);

  }

function meizzNextY()  //往后翻 Year

  {

    if(meizzTheYear > 999 && meizzTheYear <10000){meizzTheYear++;}

    else{alert("年份超出范围（1000-9999）！");}

    meizzSetDay(meizzTheYear,meizzTheMonth);

  }

function meizzToday()  //Today Button

  {

    meizzTheYear = new Date().getFullYear();

    meizzTheMonth = new Date().getMonth()+1;

    meizzTheDay = new Date().getDate();

    meizzSetDay(meizzTheYear,meizzTheMonth);

  }

function meizzPrevM()  //往前翻月份

  {

    if(meizzTheMonth>1){meizzTheMonth--}else{meizzTheYear--;meizzTheMonth=12;}

    meizzSetDay(meizzTheYear,meizzTheMonth);

  }

function meizzNextM()  //往后翻月份

  {

    if(meizzTheMonth==12){meizzTheYear++;meizzTheMonth=1}else{meizzTheMonth++}

    meizzSetDay(meizzTheYear,meizzTheMonth);

  }



function meizzSetDay(yy,mm)   //主要的写程序**********

{

  ne_wf_webInputDate_oPopup.document.getElementById("tmpSelectYearLayer").style.display="none";
  ne_wf_webInputDate_oPopup.document.getElementById("tmpSelectMonthLayer").style.display="none";
  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("ne_wf_webInputDate_oPopup.document.getElementById('meizzDay"+i+"')");     //书写新的一个月的日期星期排列

    if (meizzWDay[i]!="")

      { da.innerHTML = "<b>" + meizzWDay[i] + "</b>";

        da.style.backgroundColor = (yy == new Date().getFullYear() &&

        mm == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate()) ? "#FFD700" : "#ADD8E6";

        da.style.cursor="hand"

      }

    else{da.innerHTML="";da.style.backgroundColor="";da.style.cursor="default"}

  }
}

function meizzDayClick(n)  //点击显示框选取日期，主输入函数*************

{

  var yy = meizzTheYear;

  var mm = meizzTheMonth;

  if (mm < 10){mm = "0" + mm;}

  if (outObject)

  {

    if (!n) {return;}
	if(n == -1){
		n = meizzTheDay;
	}
	if ( n < 10){
		n = "0" + n;
	}
	if(!meizz_isShowTime){
    	outObject.value= yy + "-" + mm + "-" + n ; //注：在这里你可以输出改成你想要的格式
    }else{
		outObject.value= yy+"-"+mm+"-"+n+" "+meizzTheHour + ":" + meizzTheMinute;
	}
    closeLayer(); 

  }

  else {closeLayer(); alert("您所要输出的控件对象并不存在！");}

}

function ne_wf_WebInputDate_getDate(obj){
	initInputDate();
	setday(obj,obj,false);
}
function ne_wf_WebInputDate_getDateTime(obj){
	initInputDate();
	setday(obj,obj,true);
}
function webInputDate_getDate(obj){
	initInputDate();
	setday(obj,obj,false);
}
function webInputDate_getDateTime(obj){
	initInputDate();
	setday(obj,obj,true);
}