//改为全面兼容ns 随冰(2006.2.21)94kk.com
var date_start,date_end,g_object
var today = new Date();
var separator="-";
var inover=false;

//mode :时间变换的类型0-年 1-月 2-直接选择月
function change_date(temp,mode)
{var cdy=document.getElementById("cele_date_year")
var cdm=document.getElementById("cele_date_month")
	var t_month,t_year
    if (mode){
        if(mode==1)
        t_month=parseInt(cdm.value,10)+parseInt(temp,10);
        else
        t_month=parseInt(temp)
        if (t_month<cdm.options[0].text) {
            cdm.value=cdm.options[cdm.length-1].text;
            change_date(parseInt(cdy.value,10)-1,0);
            }
        else{
            if (t_month>cdm.options[cdm.length-1].text){
                cdm.value=cdm.options[0].text;
                change_date(parseInt(cdy.value,10)+1,0);
                }            
            else
                {cdm.value=t_month;
                 set_cele_date(cdy.value,cdm.value);                
                }
        }
    }  
    else{
        t_year=parseInt(temp,10);
        
        if (t_year<cdy.options[0].text) {
            cdy.value=cdy.options[0].text;
            set_cele_date(cdy.value,1);                
            }
        else{
            if (parseInt(t_year,10)>parseInt(cdy.options[cdy.length-1].text,10)){
                cdy.value=cdy.options[cdy.length-1].text;
                set_cele_date(cdy.value,12);                
                }            
            else
                {cdy.value=t_year;
                 set_cele_date(cdy.value,cdm.value);                
                }
        }
    }
}

//初始化日历
function init(d_start,d_end)
{
     var temp_str;
     var i=0
     var j=0
     date_start=new Date(1980,7,1)
     date_end=new Date(2004,8,1)
     document.writeln("<div name=\"cele_date\" id=\"cele_date\"  style=\"display:none;position: absolute;\"  onBlur=\"hilayer()\" onMouseout=\"lostlayerfocus()\">-</div>");
     temp_str="<table border=\"1\" bgcolor=\"#DDDDDD\" bordercolor=\"white\"><tr><td colspan=7 onmouseover=\"overcolor(this)\">";
     temp_str+="<input type=\"Button\" value=\"<<\" onclick=\"change_date(-1,1)\" onmouseover=\"getlayerfocus()\" style=\"color: #000099; background-color: #BFBFBF; cursor: pointer\">-";

     temp_str+=""
     temp_str+="<select name=\"cele_date_year\" id=\"cele_date_year\" language=\"javascript\" onchange=\"change_date(this.value,0)\" onmouseover=\"getlayerfocus()\" onblur=\"getlayerfocus()\" style=\"font-size: 9pt; border: 1px #666666 solid; background: #F4F8FB\">"

     for (i=1900;i<=2020;i++)
     {
     	temp_str+="<OPTION value=\""+i.toString()+"\">"+i.toString()+"</OPTION>";
     }
     temp_str+="</select>-";
     temp_str+=""
     temp_str+="<select name=\"cele_date_month\" id=\"cele_date_month\" language=\"javascript\" onchange=\"change_date(this.value,2)\" onmouseover=\"getlayerfocus()\" onblur=\"getlayerfocus()\" style=\"font-size: 9pt; border: 1px #666666 solid; background: #F4F8FB\">"

     for (i=1;i<=12;i++)
     {
     	temp_str+="<OPTION value=\""+i.toString()+"\">"+i.toString()+"</OPTION>";
     }
     temp_str+="</select>-";
     temp_str+=""
     temp_str+="<input type=\"Button\" value=\">>\" onclick=\"change_date(1,1)\" onmouseover=\"getlayerfocus()\"  style=\"color: #000099; background-color: #BFBFBF;cursor: pointer\">";

     temp_str+="</td></tr><tr><td onmouseover=\"overcolor(this)\">"
     temp_str+="<font color=red>日</font></td><td>";temp_str+="一</td><td>"; temp_str+="二</td><td>"; temp_str+="三</td><td>"
     temp_str+="四</td><td>";temp_str+="五</td><td>"; temp_str+="六</td></tr>";
     for (i=1 ;i<=6 ;i++)
     {
     temp_str+="<tr>";
        for(j=1;j<=7;j++){
            temp_str+="<td name=\"c"+i+"_"+j+"\" id=\"c"+i+"_"+j+"\" style=\"CURSOR: pointer\" style=\"COLOR:#000000\" language=\"javascript\" onmouseover=\"overcolor(this)\" onmouseout=\"outcolor(this)\" onclick=\"td_click(this)\">?</td>"
            }
     temp_str+="</tr>"        
     }
     temp_str+="</td></tr></table>";
     document.getElementById("cele_date").innerHTML=temp_str;
}
function set_cele_date(year,month)
{
   var i,j,p,k
   var nd=new Date(year,month-1,1);
   document.getElementById("cele_date_year").value=year;
   document.getElementById("cele_date_month").value=month;   
   k=nd.getDay()-1
   var temp;
   for (i=1;i<=6;i++)
      for(j=1;j<=7;j++)
      {
      document.getElementById("c"+i+"_"+j).innerHTML="";
      document.getElementById("c"+i+"_"+j).bgColor="#DDDDDD"
      document.getElementById("c"+i+"_"+j).style.cursor="pointer";
      }
   while(month-1==nd.getMonth())
    { j=(nd.getDay() +1);
      p=parseInt((nd.getDate()+k) / 7)+1;
      document.getElementById("c"+p+"_"+j).innerHTML=nd.getDate();
      if ((nd.getDate()==today.getDate())&&(document.getElementById("cele_date_month").value==today.getMonth()+1)&&(document.getElementById("cele_date_year").value==today.getYear())){
      	 document.getElementById("c"+p+"_"+j).bgColor="#EFFB64";
      }
      if (nd>date_end || nd<date_start)
      {
      document.getElementById("c"+p+"_"+j).bgColor="";
      document.getElementById("c"+p+"_"+j).style.cursor="text";
      }
      nd=new Date(nd.valueOf() + 86400000)
    }
}

//s_object：点击的对象；d_start-d_end有效的时间区段；需要存放值的控件；
function show_cele_date(eP,d_start,d_end,t_object)
{
var MaoDiv=document.getElementById("cele_date").style
t_obj=document.getElementById(eP);
MaoDiv.top=getOffsetTop(t_obj)+ 18+"px";
MaoDiv.left=getOffsetLeft(t_obj)+"px";
MaoDiv.display="";
MaoDiv.zIndex=99;
if (d_start!=""){
    if (d_start=="today"){
        date_start=new Date(today.getYear(),today.getMonth(),today.getDate());
    }else{
        s=d_start.split(separator);
        date_start=new Date(s[0],s[1]-1,s[2]);
    }
}else{
    date_start=new Date(1900,1,1);
}

if (d_end!=""){
    s=d_end.split(separator);
    date_end=new Date(s[0],s[1]-1,s[2]);
}else{
    date_end=new Date(3000,1,1);
}

g_object=t_object

cur_d=new Date()
set_cele_date(cur_d.getYear(),cur_d.getMonth()+1);
document.getElementById("cele_date").style.display="block";

}
function td_click(t_object)
{
var t_d
if (parseInt(t_object.innerHTML,10)>=1 && parseInt(t_object.innerHTML,10)<=31 ) 
{ t_d=new Date(document.getElementById("cele_date_year").value,document.getElementById("cele_date_month").value-1,t_object.innerHTML)
if (t_d<=date_end && t_d>=date_start)
{
var year = document.getElementById("cele_date_year").value;
var month = document.getElementById("cele_date_month").value;
var day = t_object.innerHTML;
if (parseInt(month)<10) month = "0" + month;
if (parseInt(day)<10) day = "0" + day;

g_object.value=year+separator+month+separator+day;
document.getElementById("cele_date").style.display="none";};
}

}
function h_cele_date()
{
document.getElementById("cele_date").style.display="none";
}

function overcolor(obj)
{
  if (obj.style.cursor=="pointer"){obj.style.color = "#FFFFFF";}
  inover=true;

}

function outcolor(obj)
{
	obj.style.color = "#000000";
	inover=false;

}

function getNow(o){
    var Stamp=new Date();
    var year = Stamp.getYear();
    var month = Stamp.getMonth()+1;
    var day = Stamp.getDate();
    if(month<10){
	month="0"+month;
    }
    if(day<10){
	day="0"+day;
    }
    o.value=year+separator+month+separator+day;
}

function hilayer()
{
	if (inover==false)
	{
		document.getElementById("cele_date").style.display="none";
	}
}
function getlayerfocus()
{
	inover=true;
}
function lostlayerfocus()
{
	inover=false;
}
init();
//日历结束