<!-- Hide
function killErrors() {
return true;
}
window.onerror = killErrors;
// -->
//获取div
function $(id)
{
  var ob=document.getElementById(id);
  return ob;
}

//初始化
function init(showid,inputid,Y,M)
{
	
	$(showid).innerHTML="";
	
	//定义月份
	var month=new Array;
	month[0]="一月";
	month[1]="二月";
	month[2]="三月";
	month[3]="四月";
	month[4]="五月";
	month[5]="六月";
	month[6]="七月";
	month[7]="八月";
	month[8]="九月";
	month[9]="十月";
	month[10]="十一月";
	month[11]="十二月";

  
  //获取当前日期
 var D=new Date();
 
 var this_day=D.getDate();
 
 if(Y==null)
 {
	Y=D.getFullYear(); 
 }
 else
 {
    Y=Y;	 
 }
 
  if(M==null)
 {
	M=D.getMonth();  
 }
 else
 {
    M=M;	 
 }



//月份
  var m="<select onchange='reloads(\""+showid+"\",\""+inputid+"\")' style='width:70px; height:18px; font-size:12px;' id='m"+showid+"' name='m"+showid+"'>";
	
	for(i=0;i<12;i++)
   {
	    if(i==M)
		{
			 n="<option selected='selected' value="+M+">"+month[M]+"</option>";
	    }
		else
		{
			 n="<option value="+i+">"+month[i]+"</option>";
		}
		
		 m+=n;
	  
   }
   
   m+="</select>";
 
   
   var showbg=showdiv.bg;
   var showwidth=showdiv.width;
   var showpadding=showdiv.padding;
   
   
   
   var table_width=table.table_width;
   var table_bg=table.table_bg;
   var td_space=table.td_space;
   var head_bg=table.head_bg;
   var head_color=table.head_color;
   var week_bg=table.week_bg;
   var week_color=table.week_color;
   var date_bg=table.date_bg;
   var date_color=table.date_color;
   var curre_date_bg=table.curre_date_bg;
   var curre_date_color=table.curre_date_color;
   var up=table.up;

   
  var table_str="<div style='margin-top:5px;text-align:center; font-size:12px;font-weight:600; background-color:"+showbg+"; width:"+showwidth+"; padding:"+showpadding+"'><div style='width:"+table_width+"; padding:1px;'><table bgcolor='"+table_bg+"' border='0'  width='"+table_width+"' cellpadding='0' cellspacing='"+td_space+"'><tr style='text-align:center;background-color:"+head_bg+"; color:"+head_color+";'><td height='25px' align='left' valign='middle' colspan='7'><span>&nbsp;<input value='"+Y+"' align='absmiddle' type='text' id='y"+showid+"' onblur='reloads(\""+showid+"\",\""+inputid+"\")' name='y"+showid+"' style='height:16px; font-size:12px; width:30px' /> <font style='font-size:12px;'>年</font>&nbsp;"+m+" &nbsp;<span onclick='toup(\""+showid+"\",\""+inputid+"\")'><font style='cursor:pointer;font-size:12px; color:"+up+"'>&uarr;</font></span><span onclick='todown(\""+showid+"\",\""+inputid+"\")'><font style='cursor:pointer;font-size:12px; color:"+up+"'>&darr;</font></span><span onclick=hid(\""+showid+"\") style='cursor:pointer'>&nbsp;&nbsp;&times;</span></td></tr> <tr align='center' style='background-color:"+week_bg+";color:#FFFFFF;font-size:13px'><td style='color:#FFFFFF' valign=middle height=20px>日</td><td style='color:#FFFFFF' valign=middle  height=20px>一</td><td style='color:#FFFFFF' valign=middle height=20px>二</td><td style='color:#FFFFFF' valign=middle height=20px>三</td><td style='color:#FFFFFF' valign=middle height=20px>四</td><td style='color:#FFFFFF' valign=middle height=20px>五</td><td valign=middle style='color:#FFFFFF' height=20px>六</td></tr><tr>";
 
 //将其转换成整型
  Y=parseInt(Y);
  M=parseInt(M)+1;

//获取每月共多少天
 var alldays=getAllDays(Y,M);
 
 
 //获取每月的第一天是星期几
 var first_week=getFirstWeek(Y,M,"1");
 
 if(first_week>0)
 {
  table_str+="<td colspan='"+first_week+"'>&nbsp;</td>";
 }
 
	 for(k=1;k<=alldays;k++)
	{
			  
	   if(this_day==k)
	   {
		   table_str+="<td align='center' onmousedown='mousedown(\""+showid+k+"\")' onmouseup='mouseup(\""+showid+k+"\"),hid(\""+showid+"\")' height='18px'  id='"+showid+k+"' onclick='getValue(\""+showid+k+"\",\""+inputid+"\",\""+showid+"\")' style='font-size:14px;cursor:pointer;;color:"+curre_date_color+";background-color:"+curre_date_bg+"'>"+k+"</td>";   
	   }
	   else 
	   {
		 table_str+="<td align='center' onmousedown='mousedown(\""+showid+k+"\")' onmouseup='mouseup(\""+showid+k+"\"),hid(\""+showid+"\")' height='18px' onmouseout='mouseout(\""+showid+k+"\")' onmouseover='mouseover(\""+showid+k+"\")'  id='"+showid+k+"' onclick='getValue(\""+showid+k+"\",\""+inputid+"\",\""+showid+"\")' style='cursor:pointer;font-size:14px;background-color:"+date_bg+";color:"+date_color+"'>"+k+"</td>";   
	   }
		   
	  
	   var this_week=getFirstWeek(Y,M,k);//获取当前日期在星期几
  
	   if(this_week==6)
	  {
		  table_str+="</tr><tr>"; 
	  }
		 
	}

	  table_str+="</tr></table></div></div>";
	  var showid=$(showid);
	  showid.innerHTML=table_str;

      showid.style.display="block";
}

//定义显示区域的属性
function showBg()
{
   this.bg="#0080FF";
   this.width="214px";
   this.padding="2px"
   return this;
}


//定义表格的属性
function tab()
{

//定义背景

  //定义表格背景
   this.table_bg="#C0C0C0";
   
   //定义表格头背景
   this.head_bg="#C8E3FF";
   
   //定义星期的表格行背景
   this.week_bg="#0080FF";
   
   //定义日期的表格行背景
   this.date_bg="#FFFFFF";
   
   //定义当前日期的表格背景
   this.curre_date_bg="#FF8040";
   
//定义背景END
 
//定义字体颜色
  
  //定义表格头字体颜色
  this.head_color="#330099";
  
  //定义星期的字体颜色
   this.week_color="#FFFFFF";
   
   
   //定义日期的字体颜色
   this.date_color="#330066";
   
    //定义当前日期的表格背景
   this.curre_date_color="#FFFFFF";
   
   //定义年月上下翻动的字体颜色
   this.up="#277327"; 

//定义字体颜色END

  //定义表格的宽
   this.table_width="212px";
 
  //定义表格之间的距离、
  this.td_space="1px";

 return this;
 
}
	
	
//获取每月共多少天
function getAllDays(Y,M)
{   

	var   d   =   new   Date(   Y   +"/"+  (M+1)  +"/0");  
      return   d.getDate();  
	return days;
}

//获取每月的第一天是星期几
function getFirstWeek(Y,M,i)
{
	var d=new Date(Y+"/"+M+"/"+i);   
     var week=d.getDay();
     return week;
}
	
//填入年份或下拉选择时调用的函数
function reloads(showid,inputid)
{
    var Y=$('y'+showid);
	Y=Y.value;
    var M=$('m'+showid);
	M=M.value;
	init(showid,inputid,Y,M);
	
}
	
//当点击年份向上的箭头时

function toup(showid,inputid)
{
   var Y=$('y'+showid);
	Y=Y.value;
	Y=parseInt(Y)+1;
	$('y'+showid).value=Y;
    var M=$('m'+showid);
	M=M.value;
	init(showid,inputid,Y,M);
}
	
	
//当点击年份向下的箭头时
function todown(showid,inputid)
{
   var Y=$('y'+showid);
	Y=Y.value;
	Y=parseInt(Y)-1;
	$('y'+showid).value=Y;
    var M=$('m'+showid);
	M=M.value;
	init(showid,inputid,Y,M);
}
	
//获取值
function getValue(value,inputid,showid)
{
	 var Y=$('y'+showid);
	 Y=Y.value;
	  var M=$('m'+showid);
	  M=M.value;
	  M=parseInt(M);
	  M=M+1;
	  var D=$(value).innerHTML;
	 var input_value=Y+"-"+M+"-"+D;
	 	 
	$(inputid).value=input_value;
	
}

//当鼠标移动到方格上时，将字体变大
function mouseover(id)
{
   $(id).style.fontSize="12px";
   $(id).style.color="#277327";
}

//当鼠标移出方格，将字体变小
function mouseout(id)
{
   $(id).style.fontSize="14px";  
   $(id).style.color="#330066";
}

//鼠标按下
function mousedown(id)
{
   $(id).style.fontSize="10px";  
   $(id).style.color="#277327";
}

//鼠标弹起
function mouseup(id)
{
   var D=new Date();
  var this_day=D.getDate();
 $(id).style.fontSize="14px"; 
  if(id==this_day)
  {
	 
      $(id).style.color="#FFFFFF";
  }
  else
  {
	 
      $(id).style.color="#330066";
   }
   
}



//隐藏
function hid(showid)
{
  var t=200;
  setTimeout("wait(\""+showid+"\")",t);
}

//延长时间隐藏
function wait(showid)
{
 $(showid).style.display="none";
}

////////////////////////////////////////

//调用显示属性，可以自由设置，见showBg()和tab(),设置方法：showdiv.属性=属性值  table.属性=属性值
var showdiv=showBg();
var table=tab();

