function L_calendar(){}
L_calendar.prototype={
    _VersionInfo:"Version:1.0",
    Moveable:true,
    NewName:"",
    insertId:"",
    ClickObject:null,
    InputObject:null,
    InputDate:null,
    IsOpen:false,
    MouseX:0,
    MouseY:0,
    GetDateLayer:function(){
        if(window.parent){
            return window.parent.L_DateLayer;
            }
        else{return window.L_DateLayer;}
        },
    L_TheYear:new Date().getFullYear(),
    L_TheMonth:new Date().getMonth()+1,
    L_WDay:new Array(42),
    MonHead:new Array(31,28,31,30,31,30,31,31,30,31,30,31),	
	EnMonth:new Array("","Jan","Feb","March","April","May","June","July","Aug","Sep","Oct","Nov","Dec"),
    GetY:function(){
        var obj;
        if (arguments.length > 0){
            obj==arguments[0];
            }
        else{
            obj=this.ClickObject;
            }
        if(obj!=null){
            var y = obj.offsetTop;
            while (obj = obj.offsetParent) y += obj.offsetTop;
            return y;}
        else{return 0;}
        },
    GetX:function(){
        var obj;
        if (arguments.length > 0){
            obj==arguments[0];
            
            }
        else{
            obj=this.ClickObject;
            }
        if(obj!=null){
            var y = obj.offsetLeft;
            while (obj = obj.offsetParent) y += obj.offsetLeft;
            return y;}
        else{return 0;}
        },
    CreateHTML:function(){
        var htmlstr="";
        htmlstr+="<div id=\"L_calendar\">\r\n";
        htmlstr+="<span id=\"SelectYearLayer\" style=\"z-index: 9999;position: absolute;top: 3; left: 19;display: none\"></span>\r\n";
        htmlstr+="<span id=\"SelectMonthLayer\" style=\"z-index: 9999;position: absolute;top: 3; left: 78;display: none\"></span>\r\n";
        htmlstr+="<div id=\"L_calendar-year-month\"><div id=\"L_calendar-PrevY\" onclick=\"parent."+this.NewName+".PrevY()\" title=\"往前一年\"><img src=\"/js/Cal/leftArrow.gif\" \/></div><div id=\"L_calendar-PrevM\" onclick=\"parent."+this.NewName+".PrevM()\" title=\"往前一月\"><img src=\"/js/Cal/AriLeft.gif\" \/></div><div id=\"L_calendar-year\"></div><div id=\"L_calendar-month\"></div><div id=\"L_calendar-NextM\" onclick=\"parent."+this.NewName+".NextM()\" title=\"往后一月\"><img src=\"/js/Cal/AriRight.gif\" \/></div><div id=\"L_calendar-NextY\" onclick=\"parent."+this.NewName+".NextY()\" title=\"往后一年\"><img src=\"/js/Cal/rightArrow.gif\" \/></div></div>\r\n";
        htmlstr+="<div id=\"L_calendar-week\"><ul onmouseup=\"StopMove()\"><li>日</li><li>一</li><li>二</li><li>三</li><li>四</li><li>五</li><li>六</li></ul></div>\r\n";
        htmlstr+="<div id=\"L_calendar-day\">\r\n";
        for(var i=0;i<this.L_WDay.length;i++){
            htmlstr+="<a href=\"javascript:void(0);\" id=\"L_calendar-day_"+i+"\"></a>\r\n";
            }
        htmlstr+="<span id=\"L_calendar-today\" onclick=\"parent."+this.NewName+".Today()\" onmouseover=\"this.className='on'\" onmouseout=\"this.className=''\" title=\"获取今日时间\">今天</span>\r\n";
        htmlstr+="<span id=\"L_calendar-close\" onclick=\"parent."+this.NewName+".Close()\" onmouseover=\"this.className='on'\" onmouseout=\"this.className=''\" title=\"关闭时间控件\">关闭</span>\r\n";
        htmlstr+="</div>\r\n";
      // htmlstr+="<div id=\"L_calendar-control\"></div>\r\n";
        htmlstr+="</div>\r\n";
        htmlstr+="<scr" + "ipt type=\"text/javas" + "cript\">\r\n";
        htmlstr+="var MouseX,MouseY;";
        htmlstr+="var Moveable="+this.Moveable+";\r\n";
        htmlstr+="var MoveaStart=false;\r\n";
        htmlstr+="document.onmousemove=function(e)\r\n";
        htmlstr+="{\r\n";
        htmlstr+="var DateLayer=parent.document.getElementById(\"L_DateLayer\");\r\n";
        htmlstr+="    e = window.event || e;\r\n";
        htmlstr+="var DateLayerLeft=DateLayer.style.posLeft || parseInt(DateLayer.style.left.replace(\"px\",\"\"));\r\n";
        htmlstr+="var DateLayerTop=DateLayer.style.posTop || parseInt(DateLayer.style.top.replace(\"px\",\"\"));\r\n";
        htmlstr+="if(MoveaStart){DateLayer.style.left=(DateLayerLeft+e.clientX-MouseX)+\"px\";DateLayer.style.top=(DateLayerTop+e.clientY-MouseY)+\"px\"}\r\n";
        htmlstr+=";\r\n";
        htmlstr+="}\r\n";
        
        htmlstr+="document.getElementById(\"L_calendar-week\").onmousedown=function(e){\r\n";
        htmlstr+="if(Moveable){MoveaStart=true;}\r\n";
        htmlstr+="    e = window.event || e;\r\n";
        htmlstr+=" MouseX = e.clientX;\r\n";
        htmlstr+=" MouseY = e.clientY;\r\n";
        htmlstr+="    }\r\n";
        
        htmlstr+="function StopMove(){\r\n";
        htmlstr+="MoveaStart=false;\r\n";
        htmlstr+="    }\r\n";
        htmlstr+="document.oncontextmenu=new Function(\"event.returnValue=false;\");\r\n";
        htmlstr+="document.onselectstart=new Function(\"event.returnValue=false;\");\r\n";
        htmlstr+="</scr"+"ipt>\r\n";
        var stylestr="";
		stylestr+="<style type=\"text/css\">";
		stylestr+="body{background:#fff;font-size:12px;margin:0px;padding:0px;text-align:left}\r\n";
		stylestr+="#L_calendar{border:1px solid #7C9EBC;width:168px;padding:1px;height:190px;z-index:9998;text-align:center;background:#F4FAFC;}\r\n";
		stylestr+="#L_calendar-year-month{width:154px;height:21px;line-height:21px;z-index:9998;border:#E4E2E4 solid 1px;margin:3px auto;background:#FCFEFC;position:relative;overflow:hidden;}\r\n";
		stylestr+="#L_calendar-year{line-height:16px;width:35px;float:left;z-index:9998;position: absolute;top:1;left: 85;cursor:default;font-family:Arial, Helvetica, sans-serif;color:#252525;font-weight:bold;}\r\n";
		stylestr+="#L_calendar-month{line-height:18px;width:62px;float:left;z-index:9998;position: absolute;top:1;left: 26;cursor:default;font-family:Arial, Helvetica, sans-serif;color:#252525;font-weight:bold;}\r\n";
		stylestr+="#L_calendar-NextY{position:absolute;top:3;left:137;cursor:pointer}\r\n";
		stylestr+="#L_calendar-PrevY{position:absolute;top:3;left:5;cursor:pointer}\r\n";
		stylestr+="#L_calendar-PrevM{position:absolute;top:3;left:17;cursor:pointer}\r\n";
		stylestr+="#L_calendar-NextM{position:absolute;top:3;left:125;cursor:pointer}\r\n";
		stylestr+="#L_calendar-week{height:23px;line-height:23px;z-index:9998;color:#646664;font-weight:bold;font-family:Arial, Helvetica, sans-serif;}\r\n";
		stylestr+="#L_calendar-day{width:155px;height:115px;z-index:9998;margin:0px auto;}\r\n";
		stylestr+="#L_calendar-week ul{cursor:move;list-style:none;margin:0px;padding:0px;}\r\n";
		stylestr+="#L_calendar-week li{width:20px;height:20px;float:left;;margin:1px;padding:0px;text-align:center;}\r\n";
		stylestr+="#L_calendar-day a{color:#043EBC;font-weight:normal;display:block;float:left;width:22px;height:19px;line-height:17px;text-align:center;background:#FCFEFC;border:#E4E2E4 solid 1px;text-decoration:none;}\r\n";
		stylestr+="#L_calendar-day a.now{background:#9CD9FC;border:#046DFC solid 1px;}\r\n";
		stylestr+="#L_calendar-day a.zol{background:#ECEEEC;color:#9C9A9C;}\r\n";
		stylestr+="#L_calendar-day a:hover{border:#666 solid 1px;}\r\n";
		stylestr+="#L_calendar-day ul{list-style:none;margin:0px;padding:0px;}\r\n";
		stylestr+="#L_calendar-day li{cursor:pointer;width:20px;height:20px;float:left;;margin:1px;padding:0px;}\r\n";
		stylestr+="#L_calendar-control{height:25px;z-index:9998;}\r\n";
		stylestr+="#L_calendar-today{cursor:pointer;float:left;width:50px;height:17px;line-height:17px;margin:4px 0px 4px 0px;border:#E4E2E4 solid 1px;color:#646664;text-align:center;background:#FFFFFF;}\r\n";
		stylestr+="#L_calendar-close{cursor:pointer;float:right;width:50px;height:17px;line-height:17px;margin:4px 1px 4px 0px;border:#E4E2E4 solid 1px;color:#646664;text-align:center;background:#FFFFFF;}\r\n";
		stylestr+="#L_calendar-today.on,#L_calendar-close.on{border:#666666 solid 1px;}";
		stylestr+="</style>\r\n";
        var TempLateContent="<html>\r\n";
        TempLateContent+="<head>\r\n";
        TempLateContent+="<title></title>\r\n";
        TempLateContent+=stylestr;
        TempLateContent+="</head>\r\n";
        TempLateContent+="<body onload=\"parent."+this.NewName+".ResizeElem(168,203)\">\r\n";
        TempLateContent+=htmlstr;
        TempLateContent+="</body>\r\n";
        TempLateContent+="</html>\r\n";
        this.GetDateLayer().document.writeln(TempLateContent);
        this.GetDateLayer().document.close();
        },
    InsertHTML:function(id,htmlstr){
        var L_DateLayer=this.GetDateLayer();
        if(L_DateLayer){L_DateLayer.document.getElementById(id).innerHTML=htmlstr;}
        },
    WriteHead:function (yy,mm)
    {
        this.InsertHTML("L_calendar-year",yy + "");
        this.InsertHTML("L_calendar-month",mm + "月"+this.EnMonth[mm]);
    },
    IsPinYear:function(year)
    {
        if (0==year%4&&((year%100!=0)||(year%400==0))) return true;else return false;
    },
    GetMonthCount:function(year,month)
    {
        var c=this.MonHead[month-1];if((month==2)&&this.IsPinYear(year)) c++;return c;
    },
    GetDOW:function(day,month,year)
    {
        var dt=new Date(year,month-1,day).getDay()/7; return dt;
    },
    GetText:function(obj){
        if(obj.innerText){return obj.innerText}
        else{return obj.textContent}
        },
    PrevM:function()
    {
        if(this.L_TheMonth>1){this.L_TheMonth--}else{this.L_TheYear--;this.L_TheMonth=12;}
        this.SetDay(this.L_TheYear,this.L_TheMonth);
    },
    NextM:function()
    {
        if(this.L_TheMonth==12){this.L_TheYear++;this.L_TheMonth=1}else{this.L_TheMonth++}
        this.SetDay(this.L_TheYear,this.L_TheMonth);
    },
    PrevY:function()
    {
        if(this.L_TheYear>2005){
		this.L_TheYear--;
        this.SetDay(this.L_TheYear,this.L_TheMonth);
		}else{
			alert("时间太前面了吧!");
		}
    },
    NextY:function()
    {
        if(this.L_TheYear<2020){
			this.L_TheYear++;
        	this.SetDay(this.L_TheYear,this.L_TheMonth);
		}else{
			alert("时间太后面了吧!");
		}
    },
    Today:function()
    {
        var today;
        this.L_TheYear = new Date().getFullYear();
        this.L_TheMonth = new Date().getMonth()+1;
        today=new Date().getDate();
        if(this.InputObject){
        this.InputObject.value=this.L_TheYear + "-" + this.L_TheMonth + "-" + today;
        }
        this.CloseLayer();
    },
	Close:function()
	{
        this.CloseLayer();
	},
    SetDay:function (yy,mm)
    {
        this.WriteHead(yy,mm);
        this.L_TheYear=yy;
        this.L_TheMonth=mm;
        for (var i = 0; i < 42; i++){this.L_WDay[i]=""};
        var day1 = 1,day2=1,firstday = new Date(yy,mm-1,1).getDay();
        for (i=0;i<firstday;i++)this.L_WDay[i]=this.GetMonthCount(mm==1?yy-1:yy,mm==1?12:mm-1)-firstday+i+1
        for (i = firstday; day1 < this.GetMonthCount(yy,mm)+1; i++){this.L_WDay[i]=day1;day1++;}
        for (i=firstday+this.GetMonthCount(yy,mm);i<42;i++){this.L_WDay[i]=day2;day2++}
        for (i = 0; i < 42; i++)
        {
            var da=this.GetDateLayer().document.getElementById("L_calendar-day_"+i+"");
            var month,day;
            if (this.L_WDay[i]!="")
            { 
                if(i<firstday){
                    da.innerHTML=this.L_WDay[i];
                    month=(mm==1?12:mm-1);
					da.className="zol";
                    day=this.L_WDay[i];
                }
                else if(i>=firstday+this.GetMonthCount(yy,mm)){
                    da.innerHTML=this.L_WDay[i];
					da.className="zol";
                    month=(mm==1?12:mm+1);
                    day=this.L_WDay[i];
                }
                else{
                    da.innerHTML=this.L_WDay[i];
                    month=(mm==1?12:mm);
                    day=this.L_WDay[i];
                    if(document.all){
                        da.onclick=Function("parent."+this.NewName+".DayClick("+month+","+day+")");
                    }
                    else{
                        da.setAttribute("onclick","parent."+this.NewName+".DayClick("+month+","+day+")");
                    }
                }
                da.title=this.L_TheYear+"年"+month+"月"+day+"日";
                if(this.InputDate!=null){
                    if(yy==this.InputDate.getFullYear() && month== this.InputDate.getMonth() + 1 && day==this.InputDate.getDate()){
						da.className="now";
                        }
                    }
              }
        }
    },
    SelectYearInnerHTML:function (strYear)
    {
          if (strYear.match(/\D/)!=null){alert("年份输入参数不是数字！");return;}
          var m = (strYear) ? strYear : new Date().getFullYear();
        if (m < 1000 || m > 9999) {alert("年份值不在 1000 到 9999 之间！");return;}
        var n = m - 10;
        if (n < 1000) n = 1000;
        if (n + 26 > 9999) n = 9974;
        var s = "<select name=\"L_SelectYear\" id=\"L_SelectYear\" style='font-size: 12px' "
             s += "onblur='document.getElementById(\"SelectYearLayer\").style.display=\"none\"' "
             s += "onchange='document.getElementById(\"SelectYearLayer\").style.display=\"none\";"
             s += "parent."+this.NewName+".L_TheYear = this.value; parent."+this.NewName+".SetDay(parent."+this.NewName+".L_TheYear,parent."+this.NewName+".L_TheMonth)'>\r\n";
        var selectInnerHTML = s;
        for (var i = n; i < n + 26; i++)
        {
            if (i == m)
               {selectInnerHTML += "<option value='" + i + "' selected>" + i + "年" + "</option>\r\n";}
            else {selectInnerHTML += "<option value='" + i + "'>" + i + "年" + "</option>\r\n";}
         }
        selectInnerHTML += "</select>";
        var DateLayer=this.GetDateLayer();
        DateLayer.document.getElementById("SelectYearLayer").style.display="";
        DateLayer.document.getElementById("SelectYearLayer").innerHTML = selectInnerHTML;
        DateLayer.document.getElementById("L_SelectYear").focus();
        },
    SelectMonthInnerHTML:function (strMonth) //月份的下拉框
    {
        if (strMonth.match(/\D/)!=null){alert("月份输入参数不是数字！");return;}
        var m = (strMonth) ? strMonth : new Date().getMonth() + 1;
         var s = "<select name=\"L_SelectYear\" id=\"L_SelectMonth\" style='font-size: 12px' "
             s += "onblur='document.getElementById(\"SelectMonthLayer\").style.display=\"none\"' "
             s += "onchange='document.getElementById(\"SelectMonthLayer\").style.display=\"none\";"
             s += "parent."+this.NewName+".L_TheMonth = this.value; parent."+this.NewName+".SetDay(parent."+this.NewName+".L_TheYear,parent."+this.NewName+".L_TheMonth)'>\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>";
        var DateLayer=this.GetDateLayer();
        DateLayer.document.getElementById("SelectMonthLayer").style.display="";
        DateLayer.document.getElementById("SelectMonthLayer").innerHTML = selectInnerHTML;
        DateLayer.document.getElementById("L_SelectMonth").focus();
    },
    DayClick:function(mm,dd)
    {
        var yy=this.L_TheYear;
        if(mm<1){yy--;mm=12+mm;}
        else if(mm>12){yy++;mm=mm-12;}
        if (mm < 10){mm = "0" + mm;}
        if (this.ClickObject)
        {if (!dd) {return;}
        if ( dd < 10){dd = "0" + dd;}
        this.InputObject.value= yy + "-" + mm + "-" + dd ;
		//var tc = new paramcontrol();
		//tc.setCookies(this.FloatData,this.InputObject.value);
        this.CloseLayer();
         }
        else {this.CloseLayer(); alert("您所要输出的控件对象并不存在！");}
    },
    SetDate:function(srcEnt){
        if (arguments.length < 1){alert("对不起！传入参数太少！");return;}
        else if (arguments.length > 2){alert("对不起！传入参数太多！");return;}
        //this.InputObject=(arguments.length==1) ? arguments[0] : arguments[1];
		this.InputObject=arguments[0];
        this.ClickObject=arguments[0];
		//this.FloatData=arguments[1];
        var reg = /^(\d+)-(\d{1,2})-(\d{1,2})$/;
        var r = this.InputObject.value.match(reg); 
        if(r!=null){
            r[2]=r[2]-1; 
            var d= new Date(r[1], r[2],r[3]); 
            if(d.getFullYear()==r[1] && d.getMonth()==r[2] && d.getDate()==r[3]){
                this.InputDate=d;        //保存外部传入的日期
            }
            else this.InputDate="";
            this.L_TheYear=r[1];
            this.L_TheMonth=r[2]+1;
            }
        else{
            this.L_TheYear=new Date().getFullYear();
            this.L_TheMonth=new Date().getMonth() + 1
            }
        this.CreateHTML();
        var top=this.GetY();
        var left=this.GetX();
        var DateLayer=document.getElementById("L_DateLayer");
        DateLayer.style.top=top+this.ClickObject.clientHeight+5+"px";
        DateLayer.style.left=left+"px";
        DateLayer.style.display="block";
        this.SetDay(this.L_TheYear,this.L_TheMonth);
        },
	ResizeElem:function(w,h){
		document.getElementById("L_DateLayer").style.width=w;
		document.getElementById("L_DateLayer").style.height=h;
		},
    CloseLayer:function(){
        try{
            var DateLayer=document.getElementById("L_DateLayer");
            if((DateLayer.style.display=="" || DateLayer.style.display=="block") && arguments[0]!=this.ClickObject && arguments[0]!=this.InputObject){
                DateLayer.style.display="none";
            }
        }
        catch(e){}
        }
    }