var cal;var isFocus=false;var noTime=true;function SelectDate(D){var B=new Date();var A=B.getFullYear()-2;var C=B.getFullYear()+2;cal=(cal==null)?new Calendar(A,C,0):cal;cal.show(D)}String.prototype.toDate=function(style){var y=this.substring(style.indexOf("y"),style.lastIndexOf("y")+1);var m=this.substring(style.indexOf("M"),style.lastIndexOf("M")+1);var d=this.substring(style.indexOf("d"),style.lastIndexOf("d")+1);if(isNaN(y)){y=new Date().getFullYear()}if(isNaN(m)){m=new Date().getMonth()}if(isNaN(d)){d=new Date().getDate()}var dt;eval("dt = new Date('"+y+"', '"+(m-1)+"','"+d+"')");return dt};Date.prototype.format=function(B){var A={"M+":this.getMonth()+1,"d+":this.getDate(),"h+":this.getHours(),"m+":this.getMinutes(),"s+":this.getSeconds(),"w+":"天一二三四五六".charAt(this.getDay()),"q+":Math.floor((this.getMonth()+3)/3),"S":this.getMilliseconds()};if(/(y+)/.test(B)){B=B.replace(RegExp.$1,(this.getFullYear()+"").substr(4-RegExp.$1.length))}for(var C in A){if(new RegExp("("+C+")").test(B)){B=B.replace(RegExp.$1,RegExp.$1.length==1?A[C]:("00"+A[C]).substr((""+A[C]).length))}}return B};function Calendar(D,B,A,C){this.beginYear=1990;this.endYear=2010;this.lang=0;this.dateFormatStyle="yyyy-MM-dd";this.noTime=noTime;if(D!=null&&B!=null){this.beginYear=D;this.endYear=B}if(A!=null){this.lang=A}if(C!=null){this.dateFormatStyle=C}this.dateControl=null;this.panel=this.getElementById("calendarPanel");this.container=this.getElementById("ContainerPanel");this.form=null;this.date=new Date();this.year=this.date.getFullYear();this.month=this.date.getMonth();this.colors={"cur_word":"#FFFFFF","cur_bg":"#83A6F4","sel_bg":"#FFCCCC","sun_word":"#FF0000","sat_word":"#0000FF","td_word_light":"#333333","td_word_dark":"#CCCCCC","td_bg_out":"#EFEFEF","td_bg_over":"#FFCC00","tr_word":"#FFFFFF","tr_bg":"#666666","input_border":"#CCCCCC","input_bg":"#ccc"};this.draw();this.bindYear();this.bindMonth();this.changeSelect();this.bindData()}Calendar.language={"year":[[""],[""]],"months":[["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"]],"weeks":[["日","一","二","三","四","五","六"],["SUN","MON","TUR","WED","THU","FRI","SAT"]],"clear":[["清空"],["CLS"]],"today":[["今天"],["TODAY"]],"close":[["关闭"],["CLOSE"]]};Calendar.prototype.draw=function(){calendar=this;var mvAry=[];mvAry[mvAry.length]=' <div name="calendarForm" style="margin: 0px; width: 200px; background: #EFEFEF; border: solid 1px #077ac7;">';mvAry[mvAry.length]='    <table width="100%" border="0" cellpadding="0" cellspacing="1">';mvAry[mvAry.length]="      <tr>";mvAry[mvAry.length]='        <th align="left" width="1%"><button style="border: 1px outset '+calendar.colors["input_border"]+";background-color:"+calendar.colors["input_bg"]+';width:25px;height:20px;text-align: center;" name="prevMonth" type="button" id="prevMonth">&lt;</button></th>';mvAry[mvAry.length]='        <th align="center" width="98%" nowrap="nowrap"><select name="calendarYear" id="calendarYear" style="font-size:12px;"></select><select name="calendarMonth" id="calendarMonth" style="font-size:12px;"></select></th>';mvAry[mvAry.length]='        <th align="right" width="1%"><button style="border: 1px outset '+calendar.colors["input_border"]+";background-color:"+calendar.colors["input_bg"]+';width:25px;height:20px;text-align: center;" name="nextMonth" type="button" id="nextMonth">&gt;</button></th>';mvAry[mvAry.length]="      </tr>";mvAry[mvAry.length]="    </table>";mvAry[mvAry.length]='    <table id="calendarTable" width="100%" style="border:0px solid #CCCCCC;background-color:#FFFFFF" border="0" cellpadding="3" cellspacing="1">';mvAry[mvAry.length]="      <tr>";for(var i=0;i<7;i++){mvAry[mvAry.length]='      <th style="font-weight:normal;background-color:'+calendar.colors["tr_bg"]+";color:"+calendar.colors["tr_word"]+';">'+Calendar.language["weeks"][this.lang][i]+"</th>"}mvAry[mvAry.length]="      </tr>";for(var i=0;i<6;i++){mvAry[mvAry.length]='    <tr align="center">';for(var j=0;j<7;j++){if(j==0){mvAry[mvAry.length]=' <td style="cursor:default;color:'+calendar.colors["sun_word"]+';"></td>'}else{if(j==6){mvAry[mvAry.length]=' <td style="cursor:default;color:'+calendar.colors["sat_word"]+';"></td>'}else{mvAry[mvAry.length]=' <td style="cursor:default;"></td>'}}}mvAry[mvAry.length]="    </tr>"}if(!calendar.noTime){var tm=new Date();var h1=tm.getHours();var m1=tm.getMinutes();var s1=tm.getSeconds();mvAry[mvAry.length]="<tr>";mvAry[mvAry.length]='<td colspan="7" style="text-align: center;">';mvAry[mvAry.length]='<select id="calendarHour" size="1">';for(var x=0;x<=23;x++){mvAry[mvAry.length]='<option value="'+x+'"'+(h1-x==0?" selected='selected'":"")+">"+(x<=9?"0"+x:x)+"</option>"}mvAry[mvAry.length]="</select> : ";mvAry[mvAry.length]='<select id="calendarMinute" size="1">';for(var x=0;x<=59;x++){mvAry[mvAry.length]='<option value="'+x+'"'+(m1-x==0?" selected='selected'":"")+">"+(x<=9?"0"+x:x)+"</option>"}mvAry[mvAry.length]="</select>";mvAry[mvAry.length]=' <input type="checkbox" value="1" id="getTime" title="包括时间" style="border: 0;" checked="checked" />';mvAry[mvAry.length]="</td>";mvAry[mvAry.length]="</tr>"}mvAry[mvAry.length]='      <tr style="background-color:'+calendar.colors["input_bg"]+';">';mvAry[mvAry.length]='        <th colspan="2"><input name="calendarClear" type="button" id="calendarClear" value="'+Calendar.language["clear"][this.lang]+'" style="border: 1px solid '+calendar.colors["input_border"]+";background-color:"+calendar.colors["input_bg"]+';width:100%;height:20px;font-size:12px;"/></th>';mvAry[mvAry.length]='        <th colspan="3"><input name="calendarToday" type="button" id="calendarToday" value="'+Calendar.language["today"][this.lang]+'" style="border: 1px solid '+calendar.colors["input_border"]+";background-color:"+calendar.colors["input_bg"]+';width:100%;height:20px;font-size:12px;"/></th>';mvAry[mvAry.length]='        <th colspan="2"><input name="calendarClose" type="button" id="calendarClose" value="'+Calendar.language["close"][this.lang]+'" style="border: 1px solid '+calendar.colors["input_border"]+";background-color:"+calendar.colors["input_bg"]+';width:100%;height:20px;font-size:12px;"/></th>';mvAry[mvAry.length]="      </tr>";mvAry[mvAry.length]="    </table>";mvAry[mvAry.length]=" </div>";this.panel.innerHTML=mvAry.join("");var obj=this.getElementById("prevMonth");obj.onclick=function(){calendar.goPrevMonth(calendar)};obj.onblur=function(){calendar.onblur()};this.prevMonth=obj;obj=this.getElementById("nextMonth");obj.onclick=function(){calendar.goNextMonth(calendar)};obj.onblur=function(){calendar.onblur()};this.nextMonth=obj;obj=this.getElementById("calendarClear");obj.onclick=function(){calendar.dateControl.value=calendar.dateControl.defaultValue;calendar.dateControl.style.color="#ccc";calendar.hide()};this.calendarClear=obj;obj=this.getElementById("calendarClose");obj.onclick=function(){if(calendar.dateControl.value==""){calendar.dateControl.value=calendar.dateControl.defaultValue;calendar.dateControl.style.color="#ccc"}calendar.hide()};this.calendarClose=obj;obj=this.getElementById("calendarYear");obj.onchange=function(){calendar.update(calendar)};obj.onblur=function(){calendar.onblur()};this.calendarYear=obj;obj=this.getElementById("calendarMonth");with(obj){onchange=function(){calendar.update(calendar)};onblur=function(){calendar.onblur()}}this.calendarMonth=obj;obj=this.getElementById("calendarToday");obj.onclick=function(){var today=new Date();calendar.date=today;calendar.year=today.getFullYear();calendar.month=today.getMonth();calendar.changeSelect();calendar.bindData();if(!calendar.noTime){if(document.getElementById("getTime").checked){calendar.dateControl.value=today.format(calendar.dateFormatStyle)+" "+document.getElementById("calendarHour").value+":"+document.getElementById("calendarMinute").value}else{calendar.dateControl.value=today.format(calendar.dateFormatStyle)}}else{calendar.dateControl.value=today.format(calendar.dateFormatStyle)}calendar.hide()};this.calendarToday=obj};Calendar.prototype.bindYear=function(){var A=this.calendarYear;A.length=0;for(var B=this.beginYear;B<=this.endYear;B++){A.options[A.length]=new Option(B+Calendar.language["year"][this.lang],B)}};Calendar.prototype.bindMonth=function(){var B=this.calendarMonth;B.length=0;for(var A=0;A<12;A++){B.options[B.length]=new Option(Calendar.language["months"][this.lang][A],A)}};Calendar.prototype.goPrevMonth=function(A){if(this.year==this.beginYear&&this.month==0){return}this.month--;if(this.month==-1){this.year--;this.month=11}this.date=new Date(this.year,this.month,1);this.changeSelect();this.bindData()};Calendar.prototype.goNextMonth=function(A){if(this.year==this.endYear&&this.month==11){return}this.month++;if(this.month==12){this.year++;this.month=0}this.date=new Date(this.year,this.month,1);this.changeSelect();this.bindData()};Calendar.prototype.changeSelect=function(){var A=this.calendarYear;var C=this.calendarMonth;for(var B=0;B<A.length;B++){if(A.options[B].value==this.date.getFullYear()){A[B].selected=true;break}}for(var B=0;B<C.length;B++){if(C.options[B].value==this.date.getMonth()){C[B].selected=true;break}}};Calendar.prototype.update=function(A){this.year=A.calendarYear.options[A.calendarYear.selectedIndex].value;this.month=A.calendarMonth.options[A.calendarMonth.selectedIndex].value;this.date=new Date(this.year,this.month,1);this.changeSelect();this.bindData()};Calendar.prototype.bindData=function(){var D=this;var A=this.getMonthViewArray(this.date.getFullYear(),this.date.getMonth());var B=this.getElementById("calendarTable").getElementsByTagName("td");for(var C=0;C<B.length;C++){B[C].style.backgroundColor=D.colors["td_bg_out"];B[C].onclick=function(){return};B[C].onmouseover=function(){return};B[C].onmouseout=function(){return};if(C>A.length-1){break}B[C].innerHTML=A[C];if(A[C]!="&nbsp;"){B[C].onclick=function(){if(D.dateControl!=null){var E=new Date(D.date.getFullYear(),D.date.getMonth(),this.innerHTML).format(D.dateFormatStyle);if(!D.noTime){if(document.getElementById("getTime").checked){D.dateControl.value=E+" "+document.getElementById("calendarHour").value+":"+document.getElementById("calendarMinute").value}else{D.dateControl.value=E}}else{D.dateControl.value=E}}D.hide()};B[C].onmouseover=function(){this.style.backgroundColor=D.colors["td_bg_over"]};B[C].onmouseout=function(){this.style.backgroundColor=D.colors["td_bg_out"]};if(new Date().format(D.dateFormatStyle)==new Date(D.date.getFullYear(),D.date.getMonth(),A[C]).format(D.dateFormatStyle)){B[C].style.backgroundColor=D.colors["cur_bg"];B[C].onmouseover=function(){this.style.backgroundColor=D.colors["td_bg_over"]};B[C].onmouseout=function(){this.style.backgroundColor=D.colors["cur_bg"]}}if(D.dateControl!=null&&D.dateControl.value==new Date(D.date.getFullYear(),D.date.getMonth(),A[C]).format(D.dateFormatStyle)){B[C].style.backgroundColor=D.colors["sel_bg"];B[C].onmouseover=function(){this.style.backgroundColor=D.colors["td_bg_over"]};B[C].onmouseout=function(){this.style.backgroundColor=D.colors["sel_bg"]}}}}};Calendar.prototype.getMonthViewArray=function(B,A){var C=[];var E=new Date(B,A,1).getDay();var D=new Date(B,A+1,0).getDate();for(var F=0;F<42;F++){C[F]="&nbsp;"}for(var F=0;F<D;F++){C[F+E]=F+1}return C};Calendar.prototype.getElementById=function(id){if(typeof(id)!="string"||id==""){return null}if(document.getElementById){return document.getElementById(id)}if(document.all){return document.all(id)}try{return eval(id)}catch(e){return null}};Calendar.prototype.getElementsByTagName=function(A,B){if(document.getElementsByTagName){return document.getElementsByTagName(B)}if(document.all){return document.all.tags(B)}};Calendar.prototype.getAbsPoint=function(C){var A=C.offsetLeft;var B=C.offsetTop;while(C=C.offsetParent){A+=C.offsetLeft;B+=C.offsetTop}return{"x":A,"y":B}};Calendar.prototype.show=function(C,A){if(C==null){throw new Error("arguments[0] is necessary")}this.dateControl=C;this.date=(C.value.length>0)?new Date(C.value.toDate(this.dateFormatStyle)):new Date();this.year=this.date.getFullYear();this.month=this.date.getMonth();this.changeSelect();this.bindData();if(A==null){A=C}var B=this.getAbsPoint(A);this.panel.style.left=B.x-25+"px";this.panel.style.top=(B.y+C.offsetHeight)+"px";this.panel.style.display="";this.container.style.display="";C.onblur=function(){calendar.onblur()};this.container.onmouseover=function(){isFocus=true};this.container.onmouseout=function(){isFocus=false}};Calendar.prototype.hide=function(){this.panel.style.display="none";this.container.style.display="none";isFocus=false};Calendar.prototype.onblur=function(){};document.write('<div id="ContainerPanel" style="display:none;"><div id="calendarPanel" style="position: absolute;display: none;z-index: 9999;');document.write('background-color: #FFFFFF;border: 1px solid #CCCCCC;width:175px;font-size:12px;margin-left:25px;"></div>');if(document.all){document.write('<iframe style="position:absolute;z-index:2000;width:expression(this.previousSibling.offsetWidth);');document.write("height:expression(this.previousSibling.offsetHeight);");document.write("left:expression(this.previousSibling.offsetLeft);top:expression(this.previousSibling.offsetTop);");document.write('display:expression(this.previousSibling.style.display);" scrolling="no" frameborder="no"></iframe>')}document.write("</div>");
