<!--
//************通用函数 ************//
function fobj(fctId){
	return document.getElementById(fctId);
}

//取得某对象，若提供ID下的对象不存在则自动创建
function c$(fctId,fctClassName){
	var varTempDivObj=fobj(fctId);
	if(!varTempDivObj){
		GetPyzyIframe("ifm"+fctId);
		varTempDivObj=document.createElement("div");
		varTempDivObj.id=fctId;
		varTempDivObj.style.position="absolute";
		varTempDivObj.style.visibility="hidden";
		varTempDivObj.style.zIndex="2";
		if(fctClassName && fctClassName!="")varTempDivObj.className=fctClassName;
		document.body.appendChild(varTempDivObj);
	}
	return varTempDivObj;
}

//取得某ID的iframe对象，若不存在该ID的对象则自动创建
function GetPyzyIframe(fctIfmId,fctVisibility,fctTop,fctLeft,fctWidth,fctHeight){
	var varTempIfmObj=fobj(fctIfmId);
	if(!varTempIfmObj){
		varTempIfmObj=document.createElement("iframe");
		varTempIfmObj.id=fctIfmId;
		varTempIfmObj.style.position="absolute";
		varTempIfmObj.style.zIndex="1";
		varTempIfmObj.style.top="0px";
		varTempIfmObj.style.visibility="hidden";
		document.body.appendChild(varTempIfmObj);
	}
	if(fctTop)varTempIfmObj.style.top=fctTop+"px";
	if(fctLeft)varTempIfmObj.style.left=fctLeft+"px";
	if(fctWidth)varTempIfmObj.style.width=fctWidth+"px";
	if(fctHeight)varTempIfmObj.style.height=fctHeight+"px";
	if(fctVisibility)varTempIfmObj.style.visibility=(document.all?fctVisibility:"hidden	");
	return varTempIfmObj;
}

//取得某对象的坐标位置、宽、高
function getPosition(obj){
	var top=0;
	var left=0;
	var width=obj.offsetWidth;
	var height=obj.offsetHeight;
	while(obj.offsetParent){
		top+=obj.offsetTop;
		left+=obj.offsetLeft;
		obj=obj.offsetParent;
	}
	return{"top":top,"left":left,"width":width,"height":height};
}

//取得编码存储框对象
function GetValueToInputObj(fctThisObj){
	if(!fctThisObj)return null;
	var varThisObjAutoInput=(fctThisObj.getAttributeNode("value_to_input")?fctThisObj.getAttributeNode("value_to_input").value:"");
	if(varThisObjAutoInput=="")return null;
	return fobj(varThisObjAutoInput);
}

//自动触发下一个对象的Act事件
function AutoNextInputAct(fctThisObj,fctAct){
	var varNextInput=fctThisObj.getAttributeNode("nextinput");
	if(varNextInput && varNextInput!=""){
		if(fobj(varNextInput.value)){
			if(document.all){
				eval("fobj('"+varNextInput.value+"')."+fctAct+"()");
			}else{
				var evt = document.createEvent("MouseEvents");
				evt.initEvent(fctAct,true,true);
				fobj(varNextInput.value).dispatchEvent(evt);
			}
			fobj(varNextInput.value).focus();
			return true;
		}
	}
	return false;
}

//给某对象的某事件增加处理函数AddFunToObj(document,"onclick","alert('1');")
function AddFunToObj(fctObj,fctAct,fctFunction){
	if(fctObj.addEventListener){ //!IE
		fctObj.addEventListener(fctAct.replace("on",""),function(e){
			e.cancelBubble=!eval(fctFunction);
		},false);
	}else if(fctObj.attachEvent){ //IE
		fctObj.attachEvent(fctAct,function(){
			return eval(fctFunction);
		});
	}
}
//************通用函数 End ************//


//输出日历样式表
document.write('\
	<style type="text/css">\
		.DateListBox{float:left;border:solid #95CAFF 1px;width:147px !important;width:149px;height:174px !important;height:184px;font-size:12px;font-family:宋体;text-align:center;}\
		.DateListBox h1{background-color:#EEF7FF;color:#0055aa;font-size:12px;height:24px;font-weight:bold;line-height:24px;vertical-align:middle;margin:0px;}\
		.DateListBox div{float:left;border:solid #4DA6FF 1px;background-color:#4DA6FF;color:#FFFFFF;width:19px !important;width:21px;height:20px;font-size:12px;font-weight:bold;line-height:20px;vertical-align:middle;}\
		.DateListBox a{float:left;font-family:宋体;color:#990000;border:solid #ffffff 1px;background-color:#ffffff;width:19px !important;width:21px;height:19px !important;height:22px;font-size:12px;line-height:20px;vertical-align:middle;}\
		.DateListBox a:hover{font-family:宋体;border:solid #F2C2BD 1px;background-color:#FBEDEC;}\
		.DateListBox .aSelect{cursor:pointer;font-family:宋体;border:solid #DEB4B4 1px;background-color:#FBEDEC;color:#CC6600;}\
		.PyzyDateBox{position:absolute;z-index:2;visibility:hidden;top:0;background-color:#FFFFFF;border:solid #95CAFF 1px;height:174px !important;height:184px;width:298px !important;width:300px;}\
		.PyzyDateBox span{font-weight:bold;font-size:12px;font-family:宋体;}\
	</style>\
	<div id="divPyzyDateBox" class="PyzyDateBox"></div><iframe id="ifmdivPyzyDateBox" style="position:absolute;visibility:hidden;z-index:1;top:0;"></iframe>\
');

//取得日历列表，该函数输出的内容需要根据需求放置到特定的容器中，如浮动层、固定DIV…
function GetMonthHTML(fctStaDate,fctDate){
	if(!fctDate)fctDate=new Date(); //默认为当前日期
	var varYear=fctDate.getFullYear();
	var varMonth=fctDate.getMonth();
	var varNextMonth=new Date(varYear,varMonth+1,1);
	var varThisMonthButDay = new Date(varNextMonth-86400000); //本月最后一天

	var varThisDate,varThisWeekDay,varThisMonthHTML="";
	varThisMonthHTML+="<h1>"+varYear+"年"+(varMonth+1)+"月</h1>"
	varThisMonthHTML+="<div>日</div><div>一</div><div>二</div><div>三</div><div>四</div><div>五</div><div>六</div>"
	for(var DayI=1;DayI<=varThisMonthButDay.getDate();DayI++){
		varThisDate=new Date(varYear,varMonth,DayI);
		varThisWeekDay=varThisDate.getDay();
		if(DayI==1){
			for(var spcI=0;spcI<varThisWeekDay;spcI++){
				varThisMonthHTML+="<a></a>"
			}
		}
		varThisMonthHTML+="<a "+((fctStaDate && fctStaDate!="")?(varThisDate<fctStaDate?"old":""):"")+" href=javascript:; onclick='SelectDate(this)' title='"+varYear+"-"+(varMonth+1)+"-"+DayI+"'>"+DayI+"</a>";
	}
	return '<div class="DateListBox">'+varThisMonthHTML+'</div>';
}
//选择日期
function SelectDate(fctAObj){
	if(fctAObj.href||fctAObj.className=="aSelect"){
		var varValueObj=fobj("divPyzyDateBox").Obj;
		var varValueToObj=GetValueToInputObj(varValueObj);
		if(varValueToObj)varValueObj=varValueToObj;
		if(varValueObj.value==fctAObj.title){
			varValueObj.value="";
		}else{
			varValueObj.value=fctAObj.title;
		}
		fobj("divPyzyDateBox").style.visibility="hidden";
		fobj("divPyzyDateBox").bodyclick="";
		GetPyzyIframe("ifmdivPyzyDateBox","hidden");
		AutoNextInputAct(fobj("divPyzyDateBox").Obj,"click");
	}
}
//隐藏日历
function HiddenDateBox(){
	if(fobj("divPyzyDateBox")){
		if(fobj("divPyzyDateBox").style.visibility!="hidden" && fobj("divPyzyDateBox").bodyclick=="1"){
			fobj("divPyzyDateBox").style.visibility="hidden";
			fobj("divPyzyDateBox").bodyclick="";
			GetPyzyIframe("ifmdivPyzyDateBox","hidden");
		}else{
			fobj("divPyzyDateBox").bodyclick="1";
		}
	}
}
//显示日历
function ShowTwoMonthList(fctThisObj,fctJNum,fctStaDate){
	if(!fctJNum)fctJNum=0;
	if(!fctThisObj)fctThisObj="";
	var varStaDate=null,varTheDate=new Date();
	if(fctStaDate||fctStaDate==""){
		varStaDate=new Date(new Date()-86400000); //如果没有定义具体可使用的开始时间则自定义为今天
		var varStaDateSplit=fctStaDate.split("-");
		if(varStaDateSplit.length==3){
			varStaDate=new Date(varStaDateSplit[0],parseInt(varStaDateSplit[1],10)-1,varStaDateSplit[2]);//fctStaDate=new Date();
		}
		varTheDate=varStaDate;
		if(fctStaDate=="")fctStaDate=varStaDate.getFullYear()+"-"+(varStaDate.getMonth()+1)+"-"+varStaDate.getDate();
	}
	var varShowTwoMonthHTML="";
	for(var i=0+fctJNum;i<2+fctJNum;i++){
		varShowTwoMonthHTML+=GetMonthHTML((varStaDate?varStaDate:""),new Date(varTheDate.getFullYear(),varTheDate.getMonth()+i,1));
	}
	if(varStaDate)varShowTwoMonthHTML=varShowTwoMonthHTML.replace(/old href/g,"style=color:#999 old");
	if(fctThisObj.value!=""){ //对已选日期样式进行改变
		if(/^((\d{4})|(\d{2}))-(\d{1,2})-(\d{1,2})$/g.test(fctThisObj.value))varShowTwoMonthHTML=varShowTwoMonthHTML.replace(fctThisObj.value,fctThisObj.value+"' class='aSelect");
	}
	var varDateBoxObj = c$("divPyzyDateBox","PyzyDateBox");
	varDateBoxObj.bodyclick="";
	if(fctThisObj!=""){ //调整坐标到合适位置
		var varThisObjPosition=getPosition(fctThisObj);
		varDateBoxObj.style.top=(varThisObjPosition.top+varThisObjPosition.height)+"px";
		varDateBoxObj.style.left=varThisObjPosition.left+"px";
		varDateBoxObj.style.visibility="visible"; //hidden
		varDateBoxObj.Obj=fctThisObj;
	}
	varDateBoxObj.innerHTML=varShowTwoMonthHTML+'<div style="margin-top:'+(document.all?'-182':'-1')+'px;color:#B42929;font-size:12px;font-weight:bold;line-height:24px;vertical-align:bottom;">&nbsp;<span style="padding:0 '+(document.all?'232':'232')+'px 0 5px;cursor:pointer;" onclick="ShowTwoMonthList(null,'+(fctJNum-1)+(fctStaDate?',\''+fctStaDate+'\'':'')+')" title="上月"><--</span><span style="cursor:pointer;" onclick="ShowTwoMonthList(null,'+(fctJNum+1)+(fctStaDate?',\''+fctStaDate+'\'':'')+')" title="下月">--></span></div>';
	
	if(fctThisObj!=""){
		var varDateBoxPosition=getPosition(varDateBoxObj);
		if(varDateBoxPosition.left+varDateBoxPosition.width>document.body.offsetWidth){
			varDateBoxObj.style.left=(varDateBoxPosition.left-varDateBoxPosition.width+fctThisObj.offsetWidth+2)+"px";
			varDateBoxPosition=getPosition(varDateBoxObj);
		}
		GetPyzyIframe("ifmdivPyzyDateBox","visible",varDateBoxPosition.top,varDateBoxPosition.left,varDateBoxPosition.width,varDateBoxPosition.height); //取Iframe
	}
}

AddFunToObj(window,"onload","AddFunToObj(document,'onclick','HiddenDateBox();');");


//-->
