function Webcalender(){
		this.todayDate=new Date();
		this.optTime=new Date();
		this.tmpTime=new Date();
		this.firstdayweek=0;//当月第一天的星期
		this.lastdate=0;// 当月有多少天
		this.lastdayweek=0;//月底星期
		this.lastmonthdate=0;//上个月最大天数
		this.bgcolor="#6633FF";
		this.TargetSrc=null;
	}
	var MyWEBCALENDER=new Webcalender();
	//创建年的下拉列表
	Webcalender.prototype.createYeatSelect=function(){
		var iframedocument=this.accessObject("document");
		var select="<select style='width:100%;height:100%;' onchange='parent.MyWEBCALENDER.changeYear(this)'>"
		var curyear=this.optTime.getFullYear();		
		for(var i=-5;i<5;i++){
			select+="<option value="+(curyear+i)+" "+((i==0)?"selected":"")+">"+(curyear+i)+"</option>";			
		}	
		select+="</select>";
		var target=this.accessObject("YearTb");
		target.innerHTML=select;
		//target.appendChild(selectobj);
	}
	Webcalender.prototype.changeYear=function(yearselect){	
		this.optTime.setFullYear(yearselect.value);
		this.accessObject("YearTb").innerHTML="";
		this.calederbody();	
		this.calederHead();
		
	}	
	//创建月的下拉列表
	Webcalender.prototype.createMonthSelect=function(obj){
		var iframedocument=this.accessObject("document");
		var select="<select style='width:100%;height:100%;'  onchange='parent.MyWEBCALENDER.changemonth(this)'>";
		var curmonth=this.optTime.getMonth();		
		for(var i=0;i<12;i++){
			select+="<option value="+i+" "+((i==curmonth)?"selected":"")+">"+(i+1)+" 月</option>";				
		}	
		select+="</select>";
		var target=this.accessObject("MonthTb");
		target.innerHTML=select;

	}
	
	Webcalender.prototype.changemonth=function(monthselect,target){				
		var kk=parseInt(monthselect.value);			
		this.optTime.setMonth(kk);
		this.calederbody();	
		this.calederHead();
	}
	Webcalender.prototype.changeyearmonth=function(year,month){
		var showyear=this.optTime.getFullYear();
		var showmonth=this.optTime.getMonth();
		showyear+=year;
		showmonth+=month;
		this.optTime.setFullYear(showyear);
		this.optTime.setMonth(showmonth);
		this.accessObject("YearTb").innerHTML=this.optTime.getFullYear()+"&nbsp;年";
		this.accessObject("MonthTb").innerHTML=(this.optTime.getMonth()+1)+"&nbsp;月";
		this.calederbody();	
	}

	Webcalender.prototype.calederHead=function(){	
		var showyear=this.optTime.getFullYear();
		var showmonth=this.optTime.getMonth();
		var iframedocument=this.accessObject("document");
		var html="<table border='0' width='140' id='table1' cellspacing='1' cellpadding='0' style='border:1px solid "+this.bgcolor+";font-size:12px'>";
			html+="	<tr  height='22' align=center>";
			html+="		<td width='15' style='cursor:hand;color:white;font-size:14px' bgcolor='"+this.bgcolor+"' onclick='parent.MyWEBCALENDER.changeyearmonth(0,-1)' title='向前翻 1 月'><b>&lt;</b></td>"
			html+="		<td width='60' id='YearTb'  onfocus='parent.MyWEBCALENDER.createYeatSelect()'>"+showyear+"&nbsp;年</td>";
			html+="		<td width='50' id='MonthTb'  onfocus='parent.MyWEBCALENDER.createMonthSelect(this.id)'>"+(showmonth+1)+"&nbsp;月</td>";
			html+="		<td width='15' style='cursor:hand;color:white;font-size:14px' bgcolor='"+this.bgcolor+"' onclick='parent.MyWEBCALENDER.changeyearmonth(0,-1)' title='向后翻 1 月'><b>&gt;</b></td>";
			html+="	</tr>";
			html+="</table>";			
		var contentobj=	this.accessObject("calendartop");
			contentobj.innerHTML=html;			
	}
	Webcalender.prototype.calederFoot=function(){		
		var iframedocument=this.accessObject("document");
		var html="<table border='0' width='140' id='table1' cellspacing='1' cellpadding='0' style='border:1px solid #6633FF;border-top:none'>";
			html+="	<tr  height='20'align= center>";
			html+="		<td width='15' style='cursor:hand;color:white;font-size:14px' bgcolor='"+this.bgcolor+"' title='向前翻 1 年'  onclick='parent.MyWEBCALENDER.changeyearmonth(-1,0)'>&lt;&lt;</td>";
			html+="		<td width='15' style='cursor:hand;color:white;font-size:14px' bgcolor='"+this.bgcolor+"' title='向前翻 1 月'  onclick='parent.MyWEBCALENDER.changeyearmonth(0,-1)'>&lt;</td>";
			html+="		<td width='80' onclick='parent.MyWEBCALENDER.getCalederTodayDataTime()'><table  border=0 width=60 height=100% cellspacing=0 cellpadding=0 style='border:1px solid "+this.bgcolor+";font-size:9pt' onmouseover='parent.MyWEBCALENDER.mouseover(this)'  onmouseout='parent.MyWEBCALENDER.mouseout(this)' bgcolor='#9977FF' iscolor='#9977FF'><tr><td align=center >今天</td></tr></table></td>";
			html+="		<td width='15' style='cursor:hand;color:white;font-size:14px' bgcolor='"+this.bgcolor+"' title='向后翻 1 月'  onclick='parent.MyWEBCALENDER.changeyearmonth(0,1)'>&gt;</td>";
			html+="		<td width='15' style='cursor:hand;color:white;font-size:14px' bgcolor='"+this.bgcolor+"' title='向后翻 1 年'  onclick='parent.MyWEBCALENDER.changeyearmonth(1,0)'>&gt;&gt;</td>";
			html+="	</tr>";
			html+="</table>";
		
			var contentobj=	this.accessObject("calendarfoot");
			contentobj.innerHTML=html;			
	}
	Webcalender.prototype.calederTime=function(){
		var hour=this.optTime.getHours();
		var minute=this.optTime.getMinutes();
		var second=this.optTime.getSeconds();
		var iframedocument=this.accessObject("document");
		var table=iframedocument.createElement("table");
			table.cellSpacing ="0"
			table.cellPadding="0"
			table.border="0";
			table.style.fontSize="9pt";
			table.style.border="1px solid "+this.bgcolor;		
			table.width="140"
		var tr=table.insertRow();
		var td=tr.insertCell();
			td.width="20"
			td.innerHTML="<input type='checkbox' name='C1' value='ON'>"
		var td=tr.insertCell();
			td.innerHTML="<input type='text' name='hour' style='width:100%;border:none;text-align:center;text-size:9pt' value="+hour+" >"
		var td=tr.insertCell();
			td.width="4"
			td.align="center"
			td.innerHTML=":"
		var td=tr.insertCell();
			td.innerHTML="<input type='text' name='minute' style='width:100%;border:none;text-align:center;text-size:9pt' value="+minute+" >"
		var td=tr.insertCell();
			td.width="4"
			td.align="center"
			td.innerHTML=":"
		var td=tr.insertCell();
			td.innerHTML="<input type='text' name='second' style='width:100%;border:none;text-align:center;text-size:9pt' value="+second+" >"
		var contentobj=	this.accessObject("calendartime");
			contentobj.innerHTML="";
			contentobj.appendChild(table);	
	}
	
	Webcalender.prototype.calederbody=function(){	
		this.refurbish()
		var iframedocument=this.accessObject("document");
		var table=iframedocument.createElement("table");
			table.cellSpacing ="0"
			table.cellPadding="0"
			table.border="0";
			table.style.fontSize="9pt";
			table.style.border="1px solid "+this.bgcolor;			
			table.width="140"			
		var w=1,tr,td,weekcode;
		////////////星期几显示BEGING/////////
		var weekshow=new Array("日","一","二","三","四","五","六");
		for(var i=0;i<7;i++){
			if(i==0){
				tr=table.insertRow();
				tr.height="20";
				tr.bgColor=this.bgcolor;
				tr.align="center";				
			}
			td=tr.insertCell();
			td.innerHTML=weekshow[i];
			if((i==0)||(i==6)){
				td.style.color="red";
			}else{
				td.style.color="white";
			}
		}
		////////////星期几显示END//////////
		//////////////当前的日期///////////
		var curyearmonth=this.todayDate.getFullYear()+"-"+this.todayDate.getMonth();
		var optyearmonth=this.optTime.getFullYear()+"-"+this.optTime.getMonth();
		var curday=this.todayDate.getDate();
		var flag=false;
		flag=(curyearmonth==optyearmonth);		
		/////////////////END///////////////
		for(var i=-this.firstdayweek+1;i<this.lastdate+(7-this.lastdayweek)+4;i++){				
			if(i<1) {
				weekcode="<font color='#dddddd'>"+(this.lastmonthdate+i)+"</font>";
			}else if(i<=this.lastdate){				
				weekcode=i;
				if(flag && curday==i) weekcode="<font color='white'>"+weekcode+"</font>";
			}else if(i>this.lastdate){
				weekcode="<font color='#dddddd'>"+(i-this.lastdate)+"</font>";
			}
			if(w%7==0){
				weekcode="<font color='red'>"+weekcode+"</font>";
				
			}else if(w%7==1){
				weekcode="<font color='red'>"+weekcode+"</font>";
				tr=table.insertRow();
				tr.height="20";
				tr.align="center";
			}else{	
				weekcode="<font color='#000000'>"+weekcode+"</font>";
			}
			td=tr.insertCell();				
			td.setAttribute("dd",i);	
			if(flag && curday==i){
				td.innerHTML="<table width=18 height=18 cellspacing=0 cellpadding=0 border=0><tr><td align='center' onclick='parent.MyWEBCALENDER.getCalederDataTime("+i+")' style='border:1px solid #dddddd;font-size:9pt;cursor:hand' onmouseover='parent.MyWEBCALENDER.mouseover(this)'  onmouseout='parent.MyWEBCALENDER.mouseout(this)' bgcolor='red' iscolor='red'>  "+weekcode+"</td></tr></table>";
			}else{
				td.innerHTML="<table width=18 height=18 cellspacing=0 cellpadding=0 border=0><tr><td align='center' onclick='parent.MyWEBCALENDER.getCalederDataTime("+i+")' style='border:1px solid #dddddd;font-size:9pt;cursor:hand' onmouseover='parent.MyWEBCALENDER.mouseover(this)'  onmouseout='parent.MyWEBCALENDER.mouseout(this)' bgcolor='' iscolor=''>  "+weekcode+"</td></tr></table>";
			}
			w++;
		}
		td=tr.insertCell();	
		td.colSpan=3
		td.attachEvent("onclick",function(){parent.MyWEBCALENDER.hiddenCalendar()})
		td.innerHTML="<table width=58 height=18 cellspacing=0 cellpadding=0 border=0><tr><td align='center' onclick='' style='border:1px solid #dddddd;font-size:9pt;cursor:hand' onmouseover='parent.MyWEBCALENDER.mouseover(this)'  onmouseout='parent.MyWEBCALENDER.mouseout(this)'  bgcolor='' iscolor='' >  "+"关闭"+"</td></tr></table>";
		this.accessObject("calendarcontent").innerHTML="";
		this.accessObject("calendarcontent").appendChild(table);
		document.getElementById("calendercontainer").style.height=MyWEBCALENDER.accessObject("calederadmin").offsetHeight;
	}

	Webcalender.prototype.getFirstdayweek=function(today,week){
			var firstdayweek=0;
			if(today-week-1>0){		
				firstdayweek=7-(today-week-1)%7;			
			}else{			
				firstdayweek=Math.abs((today-week-1)%7);
				if(firstdayweek==7)firstdayweek=0;
			}	
			return firstdayweek;
		}
	Webcalender.prototype.bigYear=function(year){
		if((year%4==0 && year%100!=0)||(year%400==0)) return true;
		return false;
	}
	Webcalender.prototype.getLargeday=function(year,month){
			var largeday=0;
			if(month<0) month=12+month;
			if(month==1){
				largeday=(this.bigYear(year))?29:28;
			}else{		
				if((month<=6 && month%2==0)||(month>6 && month%2!=0)){
					largeday=31;
				}else{
					largeday=30;
				}
			}
			return largeday;
		}

	Webcalender.prototype.getLastdayweek=function(today,lastday,week){
			var lastdayweek=0;
			lastdayweek=((lastday-today)+week)%7;
			return lastdayweek;
		}

	Webcalender.prototype.refurbish=function(){
		var tmpdate=this.optTime;
		var year=tmpdate.getFullYear();
		var	month=tmpdate.getMonth();
		var week=tmpdate.getDay();
		var today=tmpdate.getDate();
		
		this.firstdayweek=this.getFirstdayweek(today,week);//获取当前月头一天的星期数
		this.lastdate=this.getLargeday(year,month);// 当月有多少天
		this.lastdayweek=this.getLastdayweek(today,this.lastdate,week);//月底星期
		this.lastmonthdate=this.getLargeday(year,(month-1));//上个月最大天数
	}
	
	Webcalender.prototype.getformatfull=function(date){
		this.tmpTime.setFullYear(this.optTime.getFullYear());
		this.tmpTime.setMonth(this.optTime.getMonth());
		this.tmpTime.setDate(date);
		var curday=this.tmpTime.getFullYear()+"-"+this.appendZreo(this.tmpTime.getMonth()+1)+"-"+this.appendZreo(this.tmpTime.getDate());
		return curday;
	}
	Webcalender.prototype.mouseover=function(obj){ if(obj!=null)obj.bgColor="#3333FF";}
	Webcalender.prototype.mouseout=function(obj){ if(obj!=null)obj.bgColor=obj.getAttribute("iscolor");}	
	Webcalender.prototype.getCalederDataTime=function(date){
		var ret=this.getformatfull(date)
		if(this.TargetSrc!=null) this.TargetSrc.value=ret;
		this.hiddenCalendar();
	}
	Webcalender.prototype.getCalederTodayDataTime=function(){
		var ret=this.todayDate.getFullYear()+"-"+this.appendZreo(this.todayDate.getMonth()+1)+"-"+this.appendZreo(this.todayDate.getDate());
		if(this.TargetSrc!=null) this.TargetSrc.value=ret;
		this.hiddenCalendar();
	}
	Webcalender.prototype.hiddenCalendar=function (){
		var container=document.getElementById("calendercontainer");
		if(container!=null){
			container.style.display="none";
		}
	}
	Webcalender.prototype.showCalendar=function (){
		var container=document.getElementById("calendercontainer");
		if(container!=null){
			container.style.display="block";
		}
	}
	Webcalender.prototype.appendZreo=function(n){return (("00"+n).substr(("00"+n).length-2));}
	Webcalender.prototype.accessObject=function(name){
		var frame=document.frames("calenderFrame");
		if(name==""){
			return frame;
		}else if(name=="body"){
			return frame.document.body;
		}else if(name=="document"){
			return frame.document;
		}else{			
			return frame.document.getElementById(name);
		}
	}
	function calender(){
		var e = window.event.srcElement;

		MyWEBCALENDER.TargetSrc=e;
		var t = e.offsetTop,  l = e.offsetLeft,h=e.offsetHeight;
		while (e = e.offsetParent){t += e.offsetTop; l += e.offsetLeft;}
		var container=document.getElementById("calendercontainer");
		if(container==null){
			container=document.createElement("div");
			container.setAttribute("id","calendercontainer");
			container.style.width="140";
			container.style.height="100";
			container.style.position="absolute";	
			var frameobject=document.createElement("iframe");
				frameobject.setAttribute("id","calenderFrame");
				frameobject.style.width="100%";
				frameobject.style.height="100%";
				frameobject.scrolling="no";
				frameobject.frameBorder ="0";
			container.appendChild(frameobject);			
			document.body.appendChild(container);
			var frame=MyWEBCALENDER.accessObject("");
			frame.document.designMode = "off";
			frame.document.open("text/html", "replace");	
			frame.document.close();
			frame.document.body.contentEditable="false";
			frame.document.body.topMargin=0;
			frame.document.body.leftMargin =0;			
			var body=MyWEBCALENDER.accessObject("body");
			body.innerHTML="<table id='calederadmin' border='0' width='142' cellspacing='0' cellpadding='0'><tr><td id='calendartop'></td></tr><tr><td id='calendartime'></td></tr><tr><td id='calendarcontent'></td></tr><tr><td id='calendarfoot'></td></tr></table>";			
		}	
		container.style.top=t+h;
		container.style.left=l;
		MyWEBCALENDER.showCalendar();
		document.frames("calenderFrame").document.body.focus()
		document.onclick=function(){			
			if (MyWEBCALENDER.TargetSrc != window.event.srcElement) MyWEBCALENDER.hiddenCalendar();
		}		
		MyWEBCALENDER.calederHead();		
		//MyWEBCALENDER.calederTime();
		MyWEBCALENDER.calederFoot();
		MyWEBCALENDER.calederbody();			
	}