<!--
//----------------------------------------------------------------------------
//  这是我做的一个日历 Javascript 页面脚本控件，适用于微软的 IE （5.0以上）浏览器
//  主调用函数是 setday(this,[object])和setday(this)，[object]是控件输出的控件名，举两个例子：
//  一、<input name=txt><input type=button value=setday onclick="setday(this,document.all.txt)">
//  二、<input onfocus="setday(this)">
//  若有什么不足的地方，或者您有更好的建议，请与我联系：mail: meizz@hzcnc.com
//  本日历的年份限制是（1000 - 9999）
//  按ESC键关闭该控件
//  在年和月的显示地方点击时会分别出年与月的下拉框
//  控件外任意点击一点即可关闭该控件
/* 以下为walkingpoison的修改说明
walkingpoison联系方式：wayx@kali.com.cn

Ver 2.5 beta 4
修改日期：2004-4-16
1.*增加了调用的方法，最后一个参数允许是一段代码，用于在点击日历以后可以执行需要的代码。

Ver 2.5 beta 3
1.增加主题可以设置的参数，并在日历版本信息中同时显示主题的版本信息
2.将日历的一些方法集成在日历对象内部，以免与外部函数定义形成冲突
3.增加了DiabloII主题，希望各位喜欢^^
4.优化部分代码

Ver 2.5 beta 2
1.增加鼠标停止在日期上的渐变效果。需要ie5.5以上支持。
2.增加参数设置对以上效果进行自动判断和测试。
3.解决方法一选择日期后产生的焦点小问题。

Ver 2.5 beta
修改日期：2003-10-27
1.*修改日历的初始化方法，可以对多种参数进行设置。
2.*引入主题的概念，便于用户选择或者自由定制主题。
3.*控件已经内置了几个主题，用户可根据需要进行选用。

Ver 2.1+
1.继续修正根据目标在窗口的位置自动调整位置，调整了在窗口右方时的显示问题。

Ver 2.1
1.修正选择月份后下一月的提示内容错误
2.日历根据输出目标在窗口的位置自动调整显示位置。()
3.*自定义输入输出格式，并修改使得输入和输出的格式统一。
4.增加自定义的样式，可以使用"M"和"d"，并且日可以空缺。

Ver	2.0
修改日期：2002-12-13
1.*全新修改使用iframe作为日历的载体，不再被select和flash等控件挡住。
2.修正了移植到iframe后移动日历控件的问题。

Ver	1.5
修改日期：2002-12-4
1.选中的日期显示为凹下去的样式
2.修改了关闭层的方法，使得失去焦点的时候能够关闭日历。
3.修改按键处理，使得Tab切换焦点的时候可以关闭控件
4.*可以自定义日历是否可以拖动

Ver 1.4
修改日期：2002-12-3
1.修正选中年/月份下拉框后按Esc键导致年/月份不显示的问题
2.修正使用下拉框选择月份造成的日期错误（字符串转化为数字的问题）
3.*外观样式的改进，使得控件从丑小鸭变成了美丽的天鹅，从灰姑娘变成了高贵的公主，从……（读者可以自己进行恰当的比喻）
4.再次增大年/月份的点击空间，并对下拉框的位置稍作调整

Ver 1.3
修改日期：2002-11-29
1.*空白部分用灰色显示上个月的最后几天和下个月的前几天
2.*每个日期上面加上鼠标提示
3.修改使得当前日期和当前选择的日期的背景色在灰色日期部分也能正常显示

Ver 1.2
修改日期：2002-11-28
1.*修改年和月的点击都把中文包含在内，增大点击的空间
2.当前选择的日期在列表中显示不同的背景色
3.修正了点击单元格之间的分隔线导致控件关闭的问题

Ver 1.1
修改日期：2002-11-15
1.修正了方法二按Esc键关闭以后再次点击不会显示日历的问题
2.点击today直接选中当前的日期并关闭控件
3.*如果调用控件的输入框含有合法日期，则自动显示输入框的日期部分。
4.修改程序统一使用关闭的函数closeCalendar()来关闭日历控件，这样可以通过自定义关闭函数来完成用户自定义的功能。

注：*号表示比较关键的改动

说明：
1.受到iframe的限制，如果拖动出日历窗口，则日历会停止移动。
*/

document.writeln('<iframe id=wpCalendarLayer frameborder=0 style="position: absolute; width: 153; height: 208; z-index: 9998; display: none"></iframe>');

function ExecAfter(){
	return true;
}
function ExecBefore(){
	return true;
}

function wpCalendar(){
	//==================================================== 参数设定部分 =======================================================
	this.bMoveable	= true;			//设置日历是否可以拖动
	this.datestyle	= "yyyy/MM/dd";		//added in Ver 2.1
	this.VersionInfo= "水晶日历 Version:2.5 beta 3&#13;2.0系列作者:WalkingPoison"	//版本信息
	this.tgtObject	= null;
	this.srcButton	= null;		//点击的按钮
	this.outerDate	= "";		//存放对象的日期
	this.oCalendar	= window.frames.wpCalendarLayer.document;			//存放日历对象
	this.Style		= document.getElementById("wpCalendarLayer").style;	//存放日历层的style
	this.MonthinMM	= this.datestyle.indexOf("MM")>=0?true:false;		//added in Ver 2.1
	this.Dateindd	= this.datestyle.indexOf("dd")>=0?true:false;
	this.theme		= theme["Classic"];			//主题设置，决定日历的外观

	try{this.IE6	= (parseFloat(window.navigator.appVersion.match(/MSIE (\d+\.\d+)/)[1])>=5.5)}
	catch(e){this.IE6 = false}
	this.TestSpeed	= false;					//测试机器速度，以便自动决定是否使用Filter。如果设置为true，则下面的PlayFitler参数设置无效。
	this.TestTimeout= 120;						//测试标准，单位是毫秒，小于这个数值的就认为机器速度足够快
	this.PlayFilter	= false;//this.IE6;					//设置是否使用Filter

	this.Year		= new Date().getFullYear();	//定义年的变量的初始值
	this.Month		= new Date().getMonth()+1;	//定义月的变量的初始值
	this.Date		= new Date().getDate();		//定义日的变量的初始值
	this.Days		= new Array(39);			//定义写日期的数组
	this.DateCell	= new Array(39);			//存放日期单元格
	
	this.followCodes= "ExecAfter();";						//存放执行完点击日历以后需要执行的操作代码

	this.tmpTdClass = "";
	this.Redraw		= function (){				//定义Redraw方法，用于重绘整个日历
		//==================================================== WEB 页面显示部分 =====================================================
		var strFrame;		//存放日历层的HTML代码
		strFrame='<style>';
		with(this.theme){
			strFrame+='BODY{font-family:'+fontFamily+';}';
			strFrame+='SELECT{color:'+headFontColor+';BACKGROUND-COLOR: '+headBgColor+';font-size:12px;font-family:'+fontFamily+';height:18px;}';
			strFrame+='INPUT{COLOR:'+buttonFontColor+';BORDER-RIGHT:'+buttonBorderColor+' 1px solid;BORDER-TOP:'+buttonBorderColor+' 1px solid;BORDER-LEFT:'+buttonBorderColor+' 1px solid;';
			strFrame+='BORDER-BOTTOM:'+buttonBorderColor+' 1px solid;BACKGROUND-COLOR:'+buttonColor+';font-family:'+fontFamily+';}';
			strFrame+='TD{FONT-SIZE: 9pt;}';
			strFrame+='TD.calendarhead{COLOR: '+headFontColor+'; BACKGROUND-COLOR: '+headBgColor+';}';
			strFrame+='TD.mouseover{COLOR: '+mouseOverFontColor+'; BACKGROUND-COLOR: '+mouseOverColor+';}';
			strFrame+='TD.dragbar{font-size:12px;color:'+dragBarFontColor+';width:21px;}';
			strFrame+='TD.normalday{color:'+normalDayFontColor+';background-color:'+normalDayColor+';}';
			strFrame+='TD.grayday{color:'+grayDayFontColor+';background-color:'+grayDayColor+';}';
			strFrame+='TD.today{color:'+todayFontColor+';background-color:'+todayColor+';}';
			strFrame+='TD.selectedday{color:'+selectedDayFontColor+';background-color:'+selectedDayColor+';}';
			strFrame+='TD.selectedgrayday{color:'+grayDayFontColor+';background-color:'+selectedDayColor+';}';
			//	'border-left-color:'+borderColor+';border-top-color:'+borderColor+';border-right-color:'+borderColorDark+';border-bottom-color:'+borderColorDark+';}';
			strFrame+='TD.graytoday{color:'+grayDayFontColor+';background-color:'+todayColor+';}';
			//	'border-left-color:'+borderColor+';border-top-color:'+borderColor+';border-right-color:'+borderColorDark+';border-bottom-color:'+borderColorDark+';}';
		}
		strFrame+='</style>';
		strFrame+='<scr' + 'ipt>';
		strFrame+='var datelayerx,datelayery;	/*存放日历控件的鼠标位置*/';
		strFrame+='var bDrag;	/*标记是否开始拖动*/';
		strFrame+='var DateLayer=parent.wpCalendar.Style;';
		strFrame+='function document.onmousemove()	/*在鼠标移动事件中，如果开始拖动日历，则移动日历*/';
		strFrame+='{if(bDrag && window.event.button==1)';
		strFrame+='	{';
		strFrame+='		DateLayer.posLeft += window.event.clientX-datelayerx;/*由于每次移动以后鼠标位置都恢复为初始的位置，因此写法与div中不同*/';
		strFrame+='		DateLayer.posTop += window.event.clientY-datelayery;}}';
		strFrame+='function DragStart()		/*开始日历拖动*/';
		strFrame+='{';
		strFrame+='	datelayerx=window.event.clientX;';
		strFrame+='	datelayery=window.event.clientY;';
		strFrame+='	bDrag=true;}';
		strFrame+='function DragEnd(){		/*结束日历拖动*/';
		strFrame+='	bDrag=false;}';
		strFrame+='</scr' + 'ipt>';
		with(this){
			strFrame+='<div style="z-index:9999;position: absolute; left:0; top:0;" onselectstart="return false"><span id=tmpSelectYearLayer style="z-index: 9999;position: absolute;top: 3; left: 19;display: none"></span>';
			strFrame+='<span id=tmpSelectMonthLayer style="z-index: 9999;position: absolute;top: 3;left: 81;display: none"></span>';
			strFrame+='<table border=1 cellspacing=0 cellpadding=0 width=151 height=160 bordercolor='+theme.borderColor+' bgcolor='+theme.bgColorMain+'>';
			strFrame+='  <tr><td width=151 height=20 bgcolor='+theme.headBgColor+'><table border=0 cellspacing=1 cellpadding=0 width=149 height=20>';
			strFrame+='      <tr align=center><td width=16><input title="向前翻 1 月" type=button ';
			strFrame+='             value="<" onclick="parent.wpCalendar.goPrevMonth()" onfocus="this.blur()" style="font-size: 12px; width: 16px; height: 18px">';
			strFrame+='        </td><td width=62 align=center class=calendarhead style="font-size:12px;cursor:default" ';
			strFrame+='onmouseover="className=\'mouseover\'" onmouseout="className=\'calendarhead\'" ';
			strFrame+='onclick="parent.wpCalendar.tmpSelectYearInnerHTML(this.innerText.substring(0,4))" title="点击这里选择年份"><span id=CalendarYearHead></span></td>';
			strFrame+='<td width=55 align=center class=calendarhead style="font-size:12px;cursor:default" onmouseover="className=\'mouseover\'" ';
			strFrame+=' onmouseout="className=\'calendarhead\'" onclick="parent.wpCalendar.tmpSelectMonthInnerHTML(this.innerText.length==3?this.innerText.substring(0,1):this.innerText.substring(0,2))"';
			strFrame+='        title="点击这里选择月份"><span id=CalendarMonthHead></span></td>';
			strFrame+='		<td width=16><input type=button value=">" onclick="parent.wpCalendar.goNextMonth()" ';
			strFrame+='             onfocus="this.blur()" title="向后翻 1 月" style="font-size: 12px; width:16px; height: 18px"></td></tr>';
			strFrame+='    </table></td></tr>';
			strFrame+='  <tr><td width=149 height=20 align=center>';
			strFrame+='<table align=center border=1 cellspacing=0 cellpadding=0 bgcolor='+theme.bgColorMain+' ' + (bMoveable? 'onmousedown="DragStart()" onmouseup="DragEnd()"':'');
			strFrame+=' BORDERCOLORLIGHT='+theme.dragBarColor+' BORDERCOLORDARK='+theme.dragBarColorDark+' width=147 height=20 style="cursor:' + (bMoveable ? 'move':'default') + '">';
			strFrame+='<tr align=center valign=bottom><td class=dragbar>日</td>';
			strFrame+='<td class=dragbar>一</td><td class=dragbar>二</td>';
			strFrame+='<td class=dragbar>三</td><td class=dragbar>四</td>';
			strFrame+='<td class=dragbar>五</td><td class=dragbar>六</td></tr>';
			strFrame+='</table></td></tr>';
			strFrame+='  <tr><td width=151 height=120 align=center>';
			strFrame+='    <table align=center border=1 cellspacing=2 cellpadding=0 BORDERCOLOR='+theme.borderColor+' bgcolor='+theme.bgColorLight+' width=149 height=120>';
			var n=0; for (j=0;j<5;j++){ strFrame+= ' <tr align=center>'; for (i=0;i<7;i++){
			strFrame+='<td width=21 height=20 id=wpDateCell'+n+' style="font-size:12px"></td>';n++;}
			strFrame+='</tr>';}
			strFrame+='      <tr align=center>';
			for (i=35;i<39;i++)strFrame+='<td width=21 height=20 id=wpDateCell'+i+' style="font-size:12px"></td>';
			strFrame+='        <td colspan=3 align=right class=calendarhead><span onclick=parent.wpCalendar.Close() style="font-size:12px;cursor: hand"';
			strFrame+='         title="' + VersionInfo + '&#13;' + theme.VersionInfo + '"><u>关闭</u></span>&nbsp;</td></tr>';
			strFrame+='    </table></td></tr><tr><td>';
			strFrame+='        <table border=0 cellspacing=1 cellpadding=0 width=100% bgcolor='+theme.headBgColor+'>';
			strFrame+='          <tr><td align=left><table border=0 cellspacing=0 cellpadding=0><tr><td><input type=button value="<<" title="向前翻 1 年" onclick="parent.wpCalendar.goPrevYear()" ';
			strFrame+='             onfocus="this.blur()" style="font-size: 12px; height: 20px"><td width="1"></td><td><input title="向前翻 1 月" type=button ';
			strFrame+='             value="< " onclick="parent.wpCalendar.goPrevMonth()" onfocus="this.blur()" style="font-size: 12px; height: 20px"></td></tr></table></td><td ';
			strFrame+='             align=center><input type=button value=Today onclick="parent.wpCalendar.selectToday()" ';
			strFrame+='             onfocus="this.blur()" title="当前日期" style="font-size: 12px; height: 20px; cursor:hand"></td><td ';
			strFrame+='             align=right><table border=0 cellspacing=0 cellpadding=0><tr><td><input type=button value=" >" onclick="parent.wpCalendar.goNextMonth()" ';
			strFrame+='             onfocus="this.blur()" title="向后翻 1 月" style="font-size: 12px; height: 20px"><td width="1"></td><td><input ';
			strFrame+='             type=button value=">>" title="向后翻 1 年" onclick="parent.wpCalendar.goNextYear()"';
			strFrame+='             onfocus="this.blur()" style="font-size: 12px; height: 20px"></td></tr></table></td>';
			strFrame+='</tr></table></td></tr></table></div>';
		}

		this.oCalendar.writeln(strFrame);
		this.oCalendar.close();		//解决ie进度条不结束的问题
		
		this.MonthinMM= this.datestyle.indexOf("MM")>=0?true:false;
		this.Dateindd	= this.datestyle.indexOf("dd")>=0?true:false;
		//测试速度
		if(this.TestSpeed){
			var t=new Date();var s="";
			for (var i=1;i<10000;i++){s=(s.length>=500?" ":s+" ");}
			if(new Date()-t<=this.TestTimeout)this.PlayFilter = this.IE6
			else this.PlayFilter = false;
			delete t;delete s;
		}

		for (i=0;i<39;i++)
		{
			this.DateCell[i] = eval("this.oCalendar.getElementById('wpDateCell"+i+"')");
			this.DateCell[i].style.cursor	= "hand";
			this.DateCell[i].style.filter	= "progid:DXImageTransform.Microsoft.Fade(duration=0.5,overlap=0.5)";
			this.DateCell[i].style.fontWeight = "bold";
			this.DateCell[i].onmouseover	= wpMouseOver;
			this.DateCell[i].onmouseout	= wpMouseOut;
		}

		//==================================================== WEB 页面显示部分 ======================================================
	}

	this.tmpSelectYearInnerHTML = function (strYear){	//年份的下拉框
		if (strYear.match(/\D/)!=null)return;
		var m = (strYear) ? strYear : new Date().getFullYear();
		if (m < 1000 || m > 9999)return;
		var n = m - 50;
		if (n < 1000) n = 1000;
		if (n + 100 > 9999) n = 9900;
		var s = "<select name=tmpSelectYear "
		s += "onblur=\"document.getElementById('tmpSelectYearLayer').style.display='none'\" "
		s += "onchange=\"document.getElementById('tmpSelectYearLayer').style.display='none';"
		s += "parent.wpCalendar.Year = parseInt(this.value); parent.wpCalendar.WriteCalendar()\">\r\n";
		var selectInnerHTML = s;
		for (var i = n; i < n + 100; i++)
		{
		if (i == m)
			{selectInnerHTML += "<option value='" + i + "' selected>" + i + "年" + "</option>\r\n";}
		else {selectInnerHTML += "<option value='" + i + "'>" + i + "年" + "</option>\r\n";}
		}
		selectInnerHTML += "</select>";
		this.oCalendar.getElementById("tmpSelectYearLayer").style.display="";
		this.oCalendar.getElementById("tmpSelectYearLayer").innerHTML = selectInnerHTML;
		this.oCalendar.getElementById("tmpSelectYear").focus();
	}

	this.tmpSelectMonthInnerHTML=function (strMonth) //月份的下拉框
	{
	  if (strMonth.match(/\D/)!=null)return;
	  var m = (strMonth) ? strMonth : new Date().getMonth() + 1;
	  var s = "<select name=tmpSelectMonth "
		 s += "onblur=\"document.getElementById('tmpSelectMonthLayer').style.display='none'\" "
		 s += "onchange=\"document.getElementById('tmpSelectMonthLayer').style.display='none';"
		 s += "parent.wpCalendar.Month = parseInt(this.value); parent.wpCalendar.WriteCalendar()\">\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>";
	  this.oCalendar.getElementById("tmpSelectMonthLayer").style.display="";
	  this.oCalendar.getElementById("tmpSelectMonthLayer").innerHTML = selectInnerHTML;
	  this.oCalendar.getElementById("tmpSelectMonth").focus();
	}

	this.Close = function(){			//关闭日历控件
		this.Style.display="none";
	}

	function getDaysOfMonth(year,month){	//得到某年某月的天数
		return((new Date(year,month,0)).getDate());
	}

	this.goPrevYear=function (){	//往前翻 Year
		if(this.Year > 1000 && this.Year <10000){this.Year--;
		this.WriteCalendar(this.Year,this.Month);}
	}
	this.goNextYear=function (){	//往后翻 Year
		if(this.Year > 999 && this.Year <9999){this.Year++;
		this.WriteCalendar(this.Year,this.Month);}
	}
	this.selectToday=function (){	//Today Button
		var today;
		this.Year = new Date().getFullYear();
		this.Month = new Date().getMonth()+1;
		today=new Date().getDate();
		if(this.Month<10 && this.MonthinMM)this.Month="0" + this.Month;	//added in Ver 2.1
		if(today<10 && this.Dateindd)today="0" + today;
		//WriteCalendar(wpCalendar.Year,wpCalendar.Month);
		if(this.tgtObject){
			this.tgtObject.value=this.datestyle.replace((this.Dateindd?"dd":"d"), today).replace("yyyy", this.Year).replace((this.MonthinMM?"MM":"M"), this.Month);
		}
		this.Close();
		if(this.followCodes!="")eval(this.followCodes);
	}
	this.goPrevMonth=function (){		//往前翻月份
		if(this.Month>1){this.Month--}else{this.Year--;this.Month=12;}
		this.WriteCalendar(this.Year,this.Month);
	}
	this.goNextMonth=function (){		//往后翻月份
		if(this.Month==12){this.Year++;this.Month=1}else{this.Month++}
		this.WriteCalendar(this.Year,this.Month);
	}

	this.WriteCalendar=function (){	//主要的写程序**********
		var yy = this.Year;
		var mm = this.Month;
		//写入头部的年月
		this.oCalendar.getElementById("CalendarYearHead").innerText	= yy + " 年";
		this.oCalendar.getElementById("CalendarMonthHead").innerText	= mm + " 月";
	  
		for (var i = 0; i < 39; i++){	//初始化边框
			this.DateCell[i].borderColorLight=this.theme.borderColor;
			this.DateCell[i].borderColorDark=this.theme.borderColorDark;
		}
		var day1 = 1,day2=1,firstday = new Date(yy,mm-1,1).getDay();  //某月第一天的星期几
		for (i=0;i<firstday;i++){	//上个月的部分
			this.Days[i]=getDaysOfMonth(mm==1?yy-1:yy,mm==1?12:mm-1)-firstday+i+1	//上个月的最后几天
			var da = this.DateCell[i];
			da.innerText=this.Days[i];
			da.title=(mm==1?12:mm-1) +"月" + this.Days[i] + "日";
			da.onclick=Function("wpCalendar.DateCellClick(this.innerText,-1)");
			if(this.outerDate && ((mm==1?yy-1:yy)==this.outerDate.getFullYear() && (mm==1?12:mm-1)== this.outerDate.getMonth() + 1 && this.Days[i]==this.outerDate.getDate())){
				da.className="selectedgrayday"
				da.borderColorLight=this.theme.borderColorDark;
				da.borderColorDark=this.theme.borderColor;
			}
			else if((mm==1?yy-1:yy) == new Date().getFullYear() && (mm==1?12:mm-1) == new Date().getMonth()+1 && this.Days[i] == new Date().getDate())
				da.className="graytoday"
			else da.className="grayday";
		}
		for (i = firstday; day1 < getDaysOfMonth(yy,mm)+1; i++){	//本月的部分
			this.Days[i]=day1;day1++;
			var da = this.DateCell[i];
			da.innerText=this.Days[i];
			da.title=mm +"月" + this.Days[i] + "日";
			da.onclick=Function("wpCalendar.DateCellClick(this.innerText,0)");		//给td赋予onclick事件的处理
			if(this.outerDate && (yy==this.outerDate.getFullYear() && mm== this.outerDate.getMonth() + 1 && this.Days[i]==this.outerDate.getDate())){
				da.className="selectedday"
				da.borderColorLight=this.theme.borderColorDark;
				da.borderColorDark=this.theme.borderColor;
			}
			else if(yy == new Date().getFullYear() && mm == new Date().getMonth()+1 && this.Days[i] == new Date().getDate())
				da.className="today"
			else da.className="normalday";
		}
		for (i=firstday+getDaysOfMonth(yy,mm);i<39;i++){	//下个月的部分
			this.Days[i]=day2;day2++;
			var da = this.DateCell[i];
			da.innerText=this.Days[i];
			da.title=(mm==12?1:parseInt(mm)+1) +"月" + this.Days[i] + "日";
			da.onclick=Function("wpCalendar.DateCellClick(this.innerText,1)");
			if(this.outerDate && ((mm==12?yy+1:yy)==this.outerDate.getFullYear() && (mm==12?1:mm+1)== this.outerDate.getMonth() + 1 && this.Days[i]==this.outerDate.getDate())){
				da.className="selectedgrayday"
				da.borderColorLight=this.theme.borderColorDark;
				da.borderColorDark=this.theme.borderColor;
			}
			else if((mm==12?yy+1:yy) == new Date().getFullYear() && (mm==12?1:mm+1) == new Date().getMonth()+1 && this.Days[i] == new Date().getDate())
				da.className="graytoday"
			else da.className="grayday";
		}
	}

	this.DateCellClick=function (n,ex){  //点击显示框选取日期，主输入函数*************
		var yy = this.Year;
		var mm = this.Month+ex;	//ex表示偏移量，用于选择上个月份和下个月份的日期
		//判断月份，并进行对应的处理
		if(mm<1){
			yy--;
			mm=12+mm;
		}
		else if(mm>12){
			yy++;
			mm=mm-12;
		}
		if (mm < 10 && this.MonthinMM)mm = "0" + mm;
		if (this.tgtObject){
			if (!n)return;
			if (n < 10 && this.Dateindd)n = "0" + n;
			this.tgtObject.value= this.datestyle.replace((this.Dateindd?"dd":"d"), n).replace("yyyy", yy).replace((this.MonthinMM?"MM":"M"), mm);	//added in Ver 2.1
			this.Close(); this.tgtObject.blur();
		}
		else {this.Close(); alert("您所要输出的控件对象并不存在！");}
		if(this.followCodes!="")eval(this.followCodes);
	}

	function wpMouseOver() {
		if(wpCalendar.PlayFilter)this.filters[0].Apply();
		// After you set Apply, changes to the oDiv object 
		//  are not displayed until Play is called.
		wpCalendar.tmpTdClass	= this.className;
		this.className			= "mouseover";
		if(wpCalendar.PlayFilter)this.filters[0].Play();
	}
	function wpMouseOut(){
		if(wpCalendar.PlayFilter)this.filters[0].Apply();
		this.className	= wpCalendar.tmpTdClass;
		if(wpCalendar.PlayFilter)this.filters[0].Play();
	}
}


function CalendarTheme(){
	this.VersionInfo		= "";	//主题的版本信息
	this.fontFamily			= "";	//字体
	this.borderColor		= "";	//边框颜色
	this.borderColorDark	= "";	//边框暗部颜色
	this.bgColorMain		= "";	//日历主背景色
	this.bgColorLight		= "";	//日历的浅背景色
	this.headBgColor		= "";	//日历头部背景色
	this.headFontColor		= "";	//日历头部字体颜色
	this.mouseOverColor		= "";	//鼠标移动的背景色
	this.mouseOverFontColor = "";	//鼠标移动的字体颜色
	this.buttonBorderColor	= "";	//按钮边框颜色
	this.buttonColor		= "";	//按钮的主色调
	this.buttonFontColor	= "";	//按钮文字颜色
	this.dragBarFontColor	= "";	//拖动条的文字颜色
	this.dragBarColor		= "";	//拖动条的边框颜色
	this.dragBarColorDark	= "";	//拖动条的边框暗部颜色
	this.normalDayColor		= "";	//日期的背景颜色
	this.normalDayFontColor	= "";	//日期的字体颜色
	this.grayDayColor		= "";	//非本月日期的背景颜色
	this.grayDayFontColor	= "";	//非本月日期的字体颜色
	this.todayColor			= "";	//当前日期的背景颜色
	this.todayFontColor		= "";	//当前日期的字体颜色
	this.selectedDayColor	= "";	//选中日期的背景颜色
	this.selectedDayFontColor="";	//选中日期的字体颜色
}

function setday() //主调函数
{
	var obj;
	if (arguments.length == 0){alert("对不起！您没有传回本控件任何参数！");return;}
	var tt=arguments[0];
	if(arguments.length==2){
		if(typeof(arguments[1])=="object")obj=arguments[1]
		else if(typeof(arguments[1])=="string")wpCalendar.followCodes=arguments[1];
	}else if(arguments.length==3){
		obj=arguments[1];
		wpCalendar.followCodes=arguments[1];
	}
	
	var dads  = wpCalendar.Style;
	var th = tt;
	var ttop  = tt.offsetTop;		//TT控件的定位点高
	var thei  = tt.clientHeight;	//TT控件本身的高
	var twid  = tt.clientWidth;		//TT控件本身的宽	//added in Ver 2.2
	var tleft = tt.offsetLeft;		//TT控件的定位点宽
	var ttyp  = tt.type;			//TT控件的类型
	while (tt = tt.offsetParent){ttop+=tt.offsetTop; tleft+=tt.offsetLeft;}
	//同时满足1.总高度足以放得下日历控件；2.下方剩余高度不足日历控件高度；3.上方高度大于日历控件高度 这3个条件的时候日历将会显示在上方
	if(document.body.clientHeight>211 + thei && document.body.clientHeight-(ttop-document.body.scrollTop)<211+thei && ttop-document.body.scrollTop>211)	//added in Ver 2.1
		dads.top = ttop-211
	else dads.top  = (ttyp=="image")? ttop+thei : ttop+thei+6;
	if(document.body.clientWidth-(tleft-document.body.scrollLeft)<144 && tleft-document.body.scrollLeft>144)	//added in Ver 2.2
		dads.left = tleft + twid - 144 + ((ttyp=="image")? 0:4)
	else dads.left = tleft;
	wpCalendar.tgtObject = !obj ? th : obj;
	wpCalendar.srcButton = !obj ? null : th;	//设定外部点击的按钮
	//根据当前输入框的日期显示日历的年月
	var reg = new RegExp("^" + wpCalendar.datestyle.replace((wpCalendar.Dateindd?"dd":"d"),"(\\d{1,2})").replace("yyyy","(\\d{4})").replace((wpCalendar.MonthinMM?"MM":"M"), "(\\d{1,2})")+"$");	//added in Ver 2.1
	var r = wpCalendar.tgtObject.value.match(reg); 
	if(r!=null){
		var t=getIndex();
		r[t[2]]=r[t[2]]-1; 
		if(wpCalendar.datestyle.indexOf("d")<0)r[t[3]]=1;			//使用一个"d"就可以包括两种情况	 //added in Ver 2.1
		var d= new Date(r[t[1]], r[t[2]],r[t[3]]);
		if(d.getFullYear()==r[t[1]] && d.getMonth()==r[t[2]] && d.getDate()==r[t[3]]){
			wpCalendar.outerDate=d;		//保存外部传入的日期
		}
		else wpCalendar.outerDate="";
		wpCalendar.Year	=r[t[1]];
		wpCalendar.Month=r[t[2]]+1;
	}
	else{
		wpCalendar.outerDate="";
		wpCalendar.Year	=new Date().getFullYear();
		wpCalendar.Month=new Date().getMonth() + 1;
	}
	wpCalendar.WriteCalendar();
	dads.display = '';

	event.returnValue=false;

	function getIndex(){	//根据日期格式设置返回年月日分别所在的位置 //added in Ver 2.1
		var i,j;
		var m=eval("new Array(wpCalendar.datestyle.indexOf(\"yyyy\"), wpCalendar.datestyle.indexOf(\"M\")" + (wpCalendar.datestyle.indexOf("d")>=0?", wpCalendar.datestyle.indexOf(\"d\")":"") + ")");	//使用一个"M"和一个"d"就可以包括两种情况
		var t=new Array();
		for(i=1;i<=m.length;i++){
			t[i]=1;
			for(j=1;j<=m.length;j++)if(i!=j && m[i-1]>m[j-1])t[i]++;
		}
		if(m.length<3)t[3]=3;
		return t;
	}
}


function document.onclick(){		//任意点击时关闭该控件
	with(window.event)
		if (srcElement != wpCalendar.tgtObject && srcElement != wpCalendar.srcButton)
		wpCalendar.Close();
}

function document.onkeyup(){		//按Esc键关闭，切换焦点关闭
	if (window.event.keyCode==27){
		if(wpCalendar.tgtObject)wpCalendar.tgtObject.blur();
		wpCalendar.Close();
	}
	else if(document.activeElement)
		if(document.activeElement != wpCalendar.tgtObject && document.activeElement != wpCalendar.srcButton)
			wpCalendar.Close();
}

var theme=new Object();

	theme["Classic"]=new CalendarTheme();
	theme["Classic"].VersionInfo		= "主题：Classic 作者：WalkingPoison";	//主题的版本信息
	theme["Classic"].fontFamily			= "宋体";		//字体
	theme["Classic"].borderColor		= "#FF9900";	//边框颜色
	theme["Classic"].borderColorDark	= "#FFFFFF";	//边框暗部颜色
	theme["Classic"].bgColorMain		= "#FF9900";	//日历主背景色
	theme["Classic"].bgColorLight		= "#FFF8EC";	//日历的浅背景色
	theme["Classic"].headBgColor		= "#FFFFFF";	//日历头部背景色
	theme["Classic"].headFontColor		= "#000000";	//日历头部字体颜色
	theme["Classic"].mouseOverColor		= "#FFD700";	//鼠标移动的背景色
	theme["Classic"].mouseOverFontColor = "#000000";	//鼠标移动的字体颜色
	theme["Classic"].buttonBorderColor	= "#FF9900";	//按钮边框颜色
	theme["Classic"].buttonColor		= "#FFF8EC";	//按钮的主色调
	theme["Classic"].buttonFontColor	= "#000000";	//按钮文字颜色
	theme["Classic"].dragBarFontColor	= "#FFFFFF";	//拖动条的文字颜色
	theme["Classic"].dragBarColor		= "#FF9900";	//拖动条的边框颜色
	theme["Classic"].dragBarColorDark	= "#FFFFFF";	//拖动条的边框暗部颜色
	theme["Classic"].normalDayColor		= "#E0E0E0";	//日期的背景颜色
	theme["Classic"].normalDayFontColor	= "#000000";	//日期的字体颜色
	theme["Classic"].grayDayColor		= "#E0E0E0";	//非本月日期的背景颜色
	theme["Classic"].grayDayFontColor	= "#808080";	//非本月日期的字体颜色
	theme["Classic"].todayColor			= "#FFD700";	//当前日期的背景颜色
	theme["Classic"].todayFontColor		= "#000000";	//当前日期的字体颜色
	theme["Classic"].selectedDayColor	= "#00FFFF";	//选中日期的背景颜色
	theme["Classic"].selectedDayFontColor="#000000";	//选中日期的字体颜色

	theme["NewAge"]=new CalendarTheme();
	theme["NewAge"].VersionInfo			= "主题：NewAge 作者：WalkingPoison";	//主题的版本信息
	theme["NewAge"].fontFamily			= "宋体";		//字体
	theme["NewAge"].borderColor			= "#336699";	//边框颜色
	theme["NewAge"].borderColorDark		= "#FFFFFF";	//边框暗部颜色
	theme["NewAge"].bgColorMain			= "#336699";	//日历主背景色
	theme["NewAge"].bgColorLight		= "#F0F8FF";	//日历的浅背景色
	theme["NewAge"].headBgColor			= "#FFFFFF";	//日历头部背景色
	theme["NewAge"].headFontColor		= "#000000";	//日历头部字体颜色
	theme["NewAge"].mouseOverColor		= "#add8e6";	//鼠标移动的背景色
	theme["NewAge"].mouseOverFontColor	= "#000000";	//鼠标移动的字体颜色
	theme["NewAge"].buttonBorderColor	= "#336699";	//按钮边框颜色
	theme["NewAge"].buttonColor			= "#F0F8FF";	//按钮的主色调
	theme["NewAge"].buttonFontColor		= "#000000";	//按钮文字颜色
	theme["NewAge"].dragBarFontColor	= "#FFFFFF";	//拖动条的文字颜色
	theme["NewAge"].dragBarColor		= "#336699";	//拖动条的边框颜色
	theme["NewAge"].dragBarColorDark	= "#336699";	//拖动条的边框暗部颜色
	theme["NewAge"].normalDayColor		= "#fff0f5";	//日期的背景颜色
	theme["NewAge"].normalDayFontColor	= "#000000";	//日期的字体颜色
	theme["NewAge"].grayDayColor		= "#fff0f5";	//非本月日期的背景颜色
	theme["NewAge"].grayDayFontColor	= "#808080";	//非本月日期的字体颜色
	theme["NewAge"].todayColor			= "#add8e6";	//当前日期的背景颜色
	theme["NewAge"].todayFontColor		= "#000000";	//当前日期的字体颜色
	theme["NewAge"].selectedDayColor	= "#336699";	//选中日期的背景颜色
	theme["NewAge"].selectedDayFontColor= "#FFFFFF";	//选中日期的字体颜色

	theme["Nostalgia"]=new CalendarTheme();
	theme["Nostalgia"].VersionInfo			= "主题：Nostalgia 作者：WalkingPoison";	//主题的版本信息
	theme["Nostalgia"].fontFamily			= "宋体";		//字体
	theme["Nostalgia"].borderColor			= "#CC3300";	//边框颜色
	theme["Nostalgia"].borderColorDark		= "#CC3300";	//边框暗部颜色
	theme["Nostalgia"].bgColorMain			= "#CC3300";	//日历主背景色
	theme["Nostalgia"].bgColorLight			= "#FFF8EC";	//日历的浅背景色
	theme["Nostalgia"].headBgColor			= "#FFFFFF";	//日历头部背景色
	theme["Nostalgia"].headFontColor		= "#000000";	//日历头部字体颜色
	theme["Nostalgia"].mouseOverColor		= "#FFD700";	//鼠标移动的背景色
	theme["Nostalgia"].mouseOverFontColor	= "#000000";	//鼠标移动的字体颜色
	theme["Nostalgia"].buttonBorderColor	= "#CC3300";	//按钮边框颜色
	theme["Nostalgia"].buttonColor			= "#FFF8EC";	//按钮的主色调
	theme["Nostalgia"].buttonFontColor		= "#000000";	//按钮文字颜色
	theme["Nostalgia"].dragBarFontColor		= "#FFFFFF";	//拖动条的文字颜色
	theme["Nostalgia"].dragBarColor			= "#CC3300";	//拖动条的边框颜色
	theme["Nostalgia"].dragBarColorDark		= "#FFFFFF";	//拖动条的边框暗部颜色
	theme["Nostalgia"].normalDayColor		= "#ffefd5";	//日期的背景颜色
	theme["Nostalgia"].normalDayFontColor	= "#000000";	//日期的字体颜色
	theme["Nostalgia"].grayDayColor			= "#ffefd5";	//非本月日期的背景颜色
	theme["Nostalgia"].grayDayFontColor		= "#808080";	//非本月日期的字体颜色
	theme["Nostalgia"].todayColor			= "#FFD700";	//当前日期的背景颜色
	theme["Nostalgia"].todayFontColor		= "#000000";	//当前日期的字体颜色
	theme["Nostalgia"].selectedDayColor		= "#CCFFFF";	//选中日期的背景颜色
	theme["Nostalgia"].selectedDayFontColor	= "#000000";	//选中日期的字体颜色

	theme["Icicle"]=new CalendarTheme();
	theme["Icicle"].VersionInfo			= "主题：Icicle 作者：WalkingPoison";	//主题的版本信息
	theme["Icicle"].fontFamily			= "宋体";		//字体
	theme["Icicle"].borderColor			= "#00bfff";	//边框颜色
	theme["Icicle"].borderColorDark		= "#ffffff";	//边框暗部颜色
	theme["Icicle"].bgColorMain			= "#00bfff";	//日历主背景色
	theme["Icicle"].bgColorLight		= "#f0faff";	//日历的浅背景色
	theme["Icicle"].headBgColor			= "#FFFFFF";	//日历头部背景色
	theme["Icicle"].headFontColor		= "#000000";	//日历头部字体颜色
	theme["Icicle"].mouseOverColor		= "#e0e9ff";	//鼠标移动的背景色
	theme["Icicle"].mouseOverFontColor	= "#000000";	//鼠标移动的字体颜色
	theme["Icicle"].buttonBorderColor	= "#87cefa";	//按钮边框颜色
	theme["Icicle"].buttonColor			= "#FFF8EC";	//按钮的主色调
	theme["Icicle"].buttonFontColor		= "#000000";	//按钮文字颜色
	theme["Icicle"].dragBarFontColor	= "#336699";	//拖动条的文字颜色
	theme["Icicle"].dragBarColor		= "#00bfff";	//拖动条的边框颜色
	theme["Icicle"].dragBarColorDark	= "#FFFFFF";	//拖动条的边框暗部颜色
	theme["Icicle"].normalDayColor		= "#e0e9ff";	//日期的背景颜色
	theme["Icicle"].normalDayFontColor	= "#336699";	//日期的字体颜色
	theme["Icicle"].grayDayColor		= "#e0e9ff";	//非本月日期的背景颜色
	theme["Icicle"].grayDayFontColor	= "#808080";	//非本月日期的字体颜色
	theme["Icicle"].todayColor			= "#FFD700";	//当前日期的背景颜色
	theme["Icicle"].todayFontColor		= "#336699";	//当前日期的字体颜色
	theme["Icicle"].selectedDayColor	= "#CCFFFF";	//选中日期的背景颜色
	theme["Icicle"].selectedDayFontColor= "#336699";	//选中日期的字体颜色

	theme["Custom"]=new CalendarTheme();
	theme["Custom"].VersionInfo			= "主题：Custom 作者：WalkingPoison";	//主题的版本信息
	theme["Custom"].fontFamily			= "宋体";		//字体
	theme["Custom"].borderColor			= "#666666";	//边框颜色
	theme["Custom"].borderColorDark		= "#FFFFFF";	//边框暗部颜色
	theme["Custom"].bgColorMain			= "#666666";	//日历主背景色
	theme["Custom"].bgColorLight		= "#F0F0F0";	//日历的浅背景色
	theme["Custom"].headBgColor			= "#F0F0F0";	//日历头部背景色
	theme["Custom"].headFontColor		= "#000000";	//日历头部字体颜色
	theme["Custom"].mouseOverColor		= "#666666";	//鼠标移动的背景色
	theme["Custom"].mouseOverFontColor	= "#000000";	//鼠标移动的字体颜色
	theme["Custom"].buttonBorderColor	= "#000000";	//按钮边框颜色
	theme["Custom"].buttonColor			= "#F0F0F0";	//按钮的主色调
	theme["Custom"].buttonFontColor		= "#000000";	//按钮文字颜色
	theme["Custom"].dragBarFontColor	= "#FFFFFF";	//拖动条的文字颜色
	theme["Custom"].dragBarColor		= "#666666";	//拖动条的边框颜色
	theme["Custom"].dragBarColorDark	= "#666666";	//拖动条的边框暗部颜色
	theme["Custom"].normalDayColor		= "#F0F0F0";	//日期的背景颜色
	theme["Custom"].normalDayFontColor	= "#000000";	//日期的字体颜色
	theme["Custom"].grayDayColor		= "#F0F0F0";	//非本月日期的背景颜色
	theme["Custom"].grayDayFontColor	= "#808080";	//非本月日期的字体颜色
	theme["Custom"].todayColor			= "#666666";	//当前日期的背景颜色
	theme["Custom"].todayFontColor		= "#000000";	//当前日期的字体颜色
	theme["Custom"].selectedDayColor	= "#666666";	//选中日期的背景颜色
	theme["Custom"].selectedDayFontColor= "#FFFFFF";	//选中日期的字体颜色

	theme["DiabloII"]=new CalendarTheme();
	theme["DiabloII"].VersionInfo			= "主题：DiabloII 作者：WalkingPoison";	//主题的版本信息
	theme["DiabloII"].fontFamily			= "宋体";		//字体
	theme["DiabloII"].borderColor			= "#928a70";	//边框颜色
	theme["DiabloII"].borderColorDark		= "#928a70";	//边框暗部颜色
	theme["DiabloII"].bgColorMain			= "#333333";	//日历主背景色
	theme["DiabloII"].bgColorLight			= "#333333";	//日历的浅背景色
	theme["DiabloII"].headBgColor			= "#333333";	//日历头部背景色
	theme["DiabloII"].headFontColor			= "#928a70";	//日历头部字体颜色
	theme["DiabloII"].mouseOverColor		= "#666666";	//鼠标移动的背景色
	theme["DiabloII"].mouseOverFontColor	= "#afafaf";	//鼠标移动的字体颜色
	theme["DiabloII"].buttonBorderColor		= "#333333";	//按钮边框颜色
	theme["DiabloII"].buttonColor			= "#333333";	//按钮的主色调
	theme["DiabloII"].buttonFontColor		= "#928a70";	//按钮文字颜色
	theme["DiabloII"].dragBarFontColor		= "#928a70";	//拖动条的文字颜色
	theme["DiabloII"].dragBarColor			= "#333333";	//拖动条的边框颜色
	theme["DiabloII"].dragBarColorDark		= "#333333";	//拖动条的边框暗部颜色
	theme["DiabloII"].normalDayColor		= "#333333";	//日期的背景颜色
	theme["DiabloII"].normalDayFontColor	= "#928a70";	//日期的字体颜色
	theme["DiabloII"].grayDayColor			= "#333333";	//非本月日期的背景颜色
	theme["DiabloII"].grayDayFontColor		= "#afafaf";	//非本月日期的字体颜色
	theme["DiabloII"].todayColor			= "#333333";	//当前日期的背景颜色
	theme["DiabloII"].todayFontColor		= "#2e8b57";	//当前日期的字体颜色
	theme["DiabloII"].selectedDayColor		= "#666666";	//选中日期的背景颜色
	theme["DiabloII"].selectedDayFontColor	= "#ffcc33";	//选中日期的字体颜色

var wpCalendar=new wpCalendar();
wpCalendar.Redraw();

// -->
