calendar.js
上传用户:tjxpgg
上传日期:2017-05-14
资源大小:2244k
文件大小:29k
源码类别:

SilverLight

开发平台:

ASP/ASPX

  1. /*****************************************************
  2.  * My97 DatePicker Ver 3.0.1
  3.  * BLOG: http://blog.csdn.net/my97/
  4.  * MAIL: smallcarrot@163.com
  5.  ****************************************************/
  6. if(navigator.product=='Gecko')
  7. {Document.prototype.attachEvent=function(sType,fHandler){var shortTypeName=sType.replace(/on/,"");
  8. fHandler._ieEmuEventHandler=function(e){window.event=e;return fHandler();};
  9. this.addEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);};
  10. Event.prototype.__defineSetter__("returnValue",function(value){if(!value){this.preventDefault();}return value;});
  11. Event.prototype.__defineGetter__("srcElement",function(){var node=this.target;
  12. while(node.nodeType!=1){node=node.parentNode;}
  13. return node;});
  14. HTMLElement.prototype.attachEvent=function(sType,fHandler)
  15. {var shortTypeName=sType.replace(/on/,"");
  16. fHandler._ieEmuEventHandler=function(e){window.event=e;return fHandler();};
  17. this.addEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);};
  18. HTMLElement.prototype.insertAdjacentElement=function(where,parsedNode){switch(where){case"beforeBegin":
  19. this.parentNode.insertBefore(parsedNode,this);
  20. break;
  21. case"afterBegin":
  22. this.insertBefore(parsedNode,this.firstChild);
  23. break;
  24. case"beforeEnd":
  25. this.appendChild(parsedNode);
  26. break;
  27. case"afterEnd":
  28. if(this.nextSibling){this.parentNode.insertBefore(parsedNode,this.nextSibling);}
  29. else{this.parentNode.appendChild(parsedNode);}
  30. break;}};}
  31. $BindAsEventListener=function(sender,listener){var __method=sender;
  32. return function(event){return __method.call(listener,event||window.event);}}
  33. function __sb()
  34. {this.s=new Array();
  35. this.i=0;
  36. this.a=function(t){this.s[this.i++]=t;};
  37. this.j=function(){return this.s.join('');};}
  38. if(!window.$){$ = function(){var elements = new Array();for (var i=0;i<arguments.length;i++){var element=arguments[i];
  39. if (typeof element=='string'){element=document.getElementById(element);}if (arguments.length==1){return element;}elements.push(element);}return elements;}}
  40. var $d=null;
  41. function My97DatePicker(){if(parent==window)return;
  42. if(navigator.product!='Gecko'){
  43. if(location.href.substring(location.href.length-3).toLowerCase()=='#97'){location.replace(location.href.substring(0,location.href.length-3));
  44. return;}
  45. else{location.replace(location.href+"#97");}
  46. history.go(-1);}
  47. this.init();
  48. this.dd=document.createElement("DIV");
  49. this.dd.style.cssText='position:absolute;z-index:197;display:block;';
  50. this.dd.obj=this;
  51. this.dd.className="WdateDiv";
  52. this.dd.innerHTML=this._createPickerHTML();
  53. var tmpImgs=this.dd.getElementsByTagName('img');
  54. this.dd.navLeftImg=tmpImgs[0];
  55. this.dd.leftImg=tmpImgs[1];
  56. this.dd.rightImg=tmpImgs[2];
  57. this.dd.navRightImg=tmpImgs[3];
  58. this.dd.navLeftImg.onclick=function(){$d.yInput.value=parseInt($d.yInput.value)-1;
  59. $d.obj.redraw();}
  60. this.dd.leftImg.onclick=function(){if(parseInt($d.mInput.getAttribute("realValue"))>1){$d.mInput.setAttribute("realValue",parseInt($d.mInput.getAttribute("realValue"))-1);}
  61. else{$d.mInput.setAttribute("realValue",12);
  62. $d.yInput.value=parseInt($d.yInput.value)-1;}
  63. $d.mInput.value=dpcfg.aMonStr[parseInt($d.mInput.getAttribute("realValue"))-1];
  64. $d.obj.redraw();}
  65. this.dd.rightImg.onclick=function(){if(parseInt($d.mInput.getAttribute("realValue"))<12){$d.mInput.setAttribute("realValue",parseInt($d.mInput.getAttribute("realValue"))+1);}
  66. else{$d.mInput.setAttribute("realValue",1);
  67. $d.yInput.value=parseInt($d.yInput.value)+1;}
  68. $d.mInput.value=dpcfg.aMonStr[parseInt($d.mInput.getAttribute("realValue"))-1];
  69. $d.obj.redraw();}
  70. this.dd.navRightImg.onclick=function(){$d.yInput.value=parseInt($d.yInput.value)+1;
  71. $d.obj.redraw();}
  72. var tmpInputs=this.dd.getElementsByTagName('input');
  73. this.dd.mInput=tmpInputs[0];
  74. this.dd.yInput=tmpInputs[1];
  75. this.dd.mInput.setAttribute('realValue',this.month);
  76. this.dd.mInput.value=dpcfg.aMonStr[this.month-1];
  77. this.dd.yInput.value=this.year;
  78. var tmpDivs=this.dd.getElementsByTagName('div');
  79. this.dd.titleDiv=tmpDivs[0];
  80. this.dd.mDiv=tmpDivs[3];
  81. this.dd.yDiv=tmpDivs[5];
  82. this.dd.dDiv=tmpDivs[7];
  83. this.dd.tDiv=tmpDivs[8].firstChild;
  84. this.dd.bDiv=tmpDivs[10];
  85. this.dd.dDiv.innerHTML=this._createDateTable();
  86. this._inputKeydown=function(){var evt=event;
  87. var k=(evt.which==undefined)?evt.keyCode:evt.which;
  88. if(!((k>=48&&k<=57)||(k>=96&&k<=105)||k==8||k==46||k==37||k==39||k==9)){evt.returnValue=false;}};
  89. this.dd.mInput.attachEvent('onkeydown',function(){var evt=event;
  90. var k=(evt.which==undefined)?evt.keyCode:evt.which;
  91. if(k==9){$d.mDiv.style.display='none';}
  92. if(event.srcElement.value.length-document.selection.createRange().text.length==2){event.returnValue=false;};});
  93. this.dd.yInput.attachEvent('onkeydown',function(){var evt=event;
  94. var k=(evt.which==undefined)?evt.keyCode:evt.which;
  95. if(k==9){$d.yDiv.style.display='none';}});
  96. this.dd.mInput.attachEvent('onkeydown',this._inputKeydown);
  97. this.dd.yInput.attachEvent('onkeydown',this._inputKeydown);
  98. this.dd.yInput.onblur=function(){var v=parseInt(this.value);
  99. if(v<$d.obj.minDate.year){this.value=$d.obj.minDate.year;}
  100. else if(v>$d.obj.maxDate.year){this.value=$d.obj.maxDate.year;}
  101. if(v!=$d.obj.year){$d.obj.redraw();}
  102. this.className='yminput';};
  103. this.dd.mInput.onblur=function(){if(parseInt(this.value)>12){this.value='12';}
  104. else if(v<1){this.value='1';}
  105. var tmpYM=$d.obj.year*100+parseInt(this.value)*1;
  106. if(tmpYM<($d.obj.minDate.year*100+$d.obj.minDate.month*1)){this.value=$d.obj.minDate.month;}
  107. else if(tmpYM>($d.obj.maxDate.year*100+$d.obj.maxDate.month*1)){this.value=$d.obj.maxDate.month;}
  108. var v=parseInt(this.value);
  109. this.setAttribute('realValue',v);
  110. this.value=dpcfg.aMonStr[v-1]
  111. if(v!=$d.obj.month){$d.obj.redraw();}
  112. this.className='yminput';};
  113. this.dd.mInput.onfocus=function(){this.className='yminputfocus';
  114. this.value=this.getAttribute("realValue");
  115. this.select();
  116. if($d.obj.hasDate){$d.obj._fillmonth();
  117. $d.mDiv.style.display='block';}};
  118. this.dd.yInput.onfocus=function(){this.className='yminputfocus';
  119. this.select();
  120. if($d.obj.hasDate){$d.obj._fillyear();
  121. $d.yDiv.style.display='block';}};
  122. this.dd.hhInput=tmpInputs[2];
  123. this.dd.hmSplitInput=tmpInputs[3];
  124. this.dd.mmInput=tmpInputs[4];
  125. this.dd.msSplitInput=tmpInputs[5];
  126. this.dd.ssInput=tmpInputs[6];
  127. this.dd.clearInput=tmpInputs[7];
  128. this.dd.todayInput=tmpInputs[8];
  129. this.dd.okInput=tmpInputs[9];
  130. this.dd.hhInput.onfocus=this.dd.mmInput.onfocus=this.dd.ssInput.onfocus=function(){this.select();$d.obj.currFocus=this;};
  131. this.dd.hhInput.onblur=function(){if(parseInt(this.value)>23){this.value='23';}
  132. else if(parseInt(this.value)<0){this.value='0';}};
  133. this.dd.mmInput.onblur=this.dd.ssInput.onblur=function(){if(parseInt(this.value)>59){this.value='59';}
  134. else if(parseInt(this.value)<0){this.value='0';}};
  135. this.dd.hmSplitInput.attachEvent('onfocus',function(){$d.mmInput.focus();});
  136. this.dd.msSplitInput.attachEvent('onfocus',function(){$d.ssInput.focus();});
  137. this.dd.ssInput.attachEvent('onkeydown',function(){var evt=event;
  138. var k=(evt.which==undefined)?evt.keyCode:evt.which;
  139. if(k==9){$d.downButton.focus();}});
  140. this.dd.hhInput.attachEvent('onkeydown',this._inputKeydown);
  141. this.dd.mmInput.attachEvent('onkeydown',this._inputKeydown);
  142. this.dd.ssInput.attachEvent('onkeydown',this._inputKeydown);
  143. var tmpBtn=this.dd.getElementsByTagName('button');
  144. this.dd.upButton=tmpBtn[0];
  145. this.dd.downButton=tmpBtn[1];
  146. this.dd.upButton.onclick=function(){if($d.obj.currFocus==undefined){$d.obj.currFocus=$d.mmInput;}
  147. if(($d.obj.currFocus==$d.hhInput&&parseInt($d.obj.currFocus.value)<23)||($d.obj.currFocus!=$d.hhInput&&parseInt($d.obj.currFocus.value)<59)){$d.obj.currFocus.value=parseInt($d.obj.currFocus.value)+1;}
  148. else{$d.obj.currFocus.value='0';}
  149. $d.obj.currFocus.focus();};
  150. this.dd.downButton.onclick=function(){if($d.obj.currFocus==undefined){$d.obj.currFocus=$d.mmInput;}
  151. if(parseInt($d.obj.currFocus.value)>0){$d.obj.currFocus.value=parseInt($d.obj.currFocus.value)-1;}
  152. else{if($d.obj.currFocus==$d.hhInput){$d.obj.currFocus.value='23';}
  153. else{$d.obj.currFocus.value='59';}}
  154. $d.obj.currFocus.focus();};
  155. $d=this.dd;
  156. document.body.insertAdjacentElement('beforeEnd',this.dd);
  157. this._setOkInput();
  158. this._setShowAndHide();}
  159. My97DatePicker.prototype.init=function(){this._todayDate=new Date();
  160. this.t_year=this._todayDate.getFullYear();
  161. this.t_month=this._todayDate.getMonth()+1;
  162. this.t_date=this._todayDate.getDate();
  163. this.t_hour=this._todayDate.getHours();
  164. this.t_minute=this._todayDate.getMinutes();
  165. this.t_sec=this._todayDate.getSeconds();
  166. var tmpdd=parent.$dp;
  167. this.eCont=tmpdd.obj.eCont;
  168. this.dateFmt=tmpdd.obj.dateFmt||dpcfg.dateFmt;
  169. this.showTime=(tmpdd.obj.showTime==true)?tmpdd.obj.showTime:dpcfg.showTime;
  170. this.skin=tmpdd.obj.skin||dpcfg.skin;
  171. this.onPicked=new parent.$dp.obj.win.Function(this.eCont.getAttribute("ONPICKED"));
  172. this.onPicked=$BindAsEventListener(this.onPicked,this.eCont);
  173. this.hasYear=(this.dateFmt.indexOf('%Y')==-1)?false:true;
  174. this.hasMonth=(this.dateFmt.indexOf('%M')==-1)?false:true;
  175. this.hasDate=(this.dateFmt.indexOf('%D')==-1)?false:true;
  176. this.hasHour=(this.dateFmt.indexOf('%h')==-1)?false:true;
  177. this.hasMin=(this.dateFmt.indexOf('%m')==-1)?false:true;
  178. this.hasSec=(this.dateFmt.indexOf('%s')==-1)?false:true;
  179. this.minDate=this._doCustomDate(this.eCont.getAttribute("MINDATE"),dpcfg.realValueShortFmt,"min");
  180. this.maxDate=this._doCustomDate(this.eCont.getAttribute("MAXDATE"),dpcfg.realValueShortFmt,"max");
  181. if((this.minDate.year*10000+this.minDate.month*100+this.minDate.date*1)>(this.maxDate.year*10000+this.maxDate.month*100+this.maxDate.date*1)){alert('u6700u5C0Fu65E5u671Fu4E0Du80FDu5927u4E8Eu6700u5927u65E5u671F(MinDate Cannot be bigger than MaxDate)!')
  182. parent.$dp.obj.eCont.onfocus=function(){};
  183. parent.$dp.obj.eCont.onclick=function(){alert('u6700u5C0Fu65E5u671Fu4E0Du80FDu5927u4E8Eu6700u5927u65E5u671F(MinDate Cannot be bigger than MaxDate)!')};}
  184. this._setActiveCSS();
  185. this._initDate(this.eCont.value,this.dateFmt);
  186. if(this.eCont.value!=''&&this.eCont.getAttribute("REALVALUE")==null&&this._judgeCorrectDateTime(this.eCont.value)){this._setRealValue();}
  187. this.s_year=this.year;
  188. this.s_month=this.month;
  189. this.s_date=this.date;
  190. this.eCont.getValue=function(){if(this.value==''){return'';}
  191. else{return this.getAttribute("REALVALUE");}};};
  192. My97DatePicker.prototype._setShowAndHide=function(){if(!(this.hasYear||this.hasMonth)){this.dd.titleDiv.style.display='none';}
  193. else{this.dd.titleDiv.style.display='';}
  194. if(!this.hasYear){this.dd.yInput.style.display=this.dd.navLeftImg.style.display=this.dd.navRightImg.style.display='none';}
  195. else{this.dd.yInput.style.display=this.dd.navLeftImg.style.display=this.dd.navRightImg.style.display='';}
  196. if(!this.hasMonth){this.dd.mInput.style.display=this.dd.leftImg.style.display=this.dd.rightImg.style.display='none';}
  197. else{this.dd.mInput.style.display=this.dd.leftImg.style.display=this.dd.rightImg.style.display='';}
  198. if(!this.hasDate){this.dd.dDiv.style.display='none';}
  199. else{this.dd.dDiv.style.display='';}
  200. if(!this.hasHour){this.dd.hhInput.disabled='disabled';}
  201. else{this.dd.hhInput.disabled='';}
  202. if(!this.hasMin){this.dd.mmInput.disabled='disabled';}
  203. else{this.dd.mmInput.disabled='';}
  204. if(!this.hasSec){this.dd.ssInput.disabled='disabled';}
  205. else{this.dd.ssInput.disabled='';}}
  206. My97DatePicker.prototype._setActiveCSS=function(){var i,a,main;
  207. for(i=0;(a=document.getElementsByTagName("link")[i]);i++){if(a.getAttribute("rel").indexOf("style")!=-1&&a.getAttribute("title")){a.disabled=true;
  208. if(a.getAttribute("title")==this.skin)a.disabled=false;}}};
  209. My97DatePicker.prototype.redraw=function(){this.year=this.dd.yInput.value;
  210. this.month=this.dd.mInput.getAttribute("realValue");
  211. this.dd.dDiv.innerHTML=this._createDateTable();
  212. autoSizeIframe();};
  213. My97DatePicker.prototype._initDate=function(str,fmt)
  214. {this.year=this.month=this.date=this.hour=this.minute=this.sec=-1;
  215. var v=str.split(/W+/);
  216. var f=fmt.match(/%./g);
  217. for(var i=0;i<f.length;i++){if(v[i]){if(f[i].toLowerCase()=='%y'){this.year=parseInt(v[i],10);
  218. if(isNaN(this.year)){this.year=this.t_year;}}
  219. else if(f[i]=='%M'){this.month=parseInt(v[i],10);
  220. if(isNaN(this.month)){this.month=this.t_month;}}
  221. else if(f[i].toLowerCase()=='%d'){this.date=parseInt(v[i],10);
  222. if(isNaN(this.date)){this.date=this.t_date;}}
  223. else if(f[i].toLowerCase()=='%h'){this.hour=parseInt(v[i],10);
  224. if(isNaN(this.hour)){this.hour=this.t_hour;}}
  225. else if(f[i]=='%m'){this.minute=parseInt(v[i],10);
  226. if(isNaN(this.minute)){this.minute=this.t_minute;}}
  227. else if(f[i].toLowerCase()=='%s'){this.sec=parseInt(v[i],10);
  228. if(isNaN(this.sec)){this.sec=this.t_sec;}}}}
  229. if(!this._isDate(this.year+'-'+this.month+'-'+this.date)){this.year=this.t_year;this.month=this.t_month;this.date=this.t_date;}
  230. if((this.hour<0)||(this.hour>23)){this.hour=this.t_hour;}
  231. if((this.minute<0)||(this.minute>59)){this.minute=this.t_minute;}
  232. if((this.sec<0)||(this.sec>59)){this.sec=this.t_sec;}};
  233. My97DatePicker.prototype._isDate=function(sDate){return sDate.match(/^((d{2}(([02468][048])|([13579][26]))[-/s]?((((0?[13578])|(1[02]))[-/s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[-/s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[-/s]?((0?[1-9])|([1-2][0-9])))))|(d{2}(([02468][1235679])|([13579][01345789]))[-/s]?((((0?[13578])|(1[02]))[-/s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[-/s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[-/s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(s(((0?[0-9])|([1-2][0-3])):([0-5]?[0-9])((s)|(:([0-5]?[0-9])))))?$/);};
  234. My97DatePicker.prototype._createPickerHTML=function()
  235. {var s=new __sb();
  236. s.a("<div id=dpTitle>");
  237. s.a("<div style='float:left;margin:2px;width:45px'><img style='cursor:pointer;' src='skin/"+this.skin+"/navLeft.gif' width=14 height=16 /><img style='cursor:pointer;' src='skin/"+this.skin+"/left.gif' width=14 height=16 /></div>");
  238. s.a("<div style='float:left;margin:2px;'><div style='margin-left:0px;width:62px' class='ymsel'></div><input class='yminput' style='margin-top:1px;width:30px;' maxlength=3></div>");
  239. s.a("<div style='float:left;margin:2px'><div style='margin-left:0px' class='ymsel'></div><input class='yminput' style='margin-top:-1px;width:40px;' maxlength=4></div>");
  240. s.a("<div style='float:right;margin:2px'><img style='cursor:pointer;' src='skin/"+this.skin+"/right.gif' width=14 height=16 /><img style='cursor:pointer;' src='skin/"+this.skin+"/navRight.gif' width=14 height=16 /></div></div>");
  241. s.a("<div></div>");
  242. s.a("<div>");
  243. s.a(this._createTimeTable());
  244. s.a("</div>");
  245. return s.j();};
  246. My97DatePicker.prototype._createDateTable=function(){var tempYear,tempMonth;
  247. if((this.year*100+this.month*1)<(this.minDate.year*100+this.minDate.month*1)){this.dd.yInput.value=tempYear=this.minDate.year;
  248. tempMonth=this.minDate.month;
  249. this.dd.mInput.value=dpcfg.aMonStr[tempMonth-1];
  250. this.dd.mInput.setAttribute('realValue',tempMonth);}
  251. else if((this.year*100+this.month*1)>(this.maxDate.year*100+this.maxDate.month*1)){this.dd.yInput.value=tempYear=this.maxDate.year;
  252. tempMonth=this.maxDate.month;
  253. this.dd.mInput.value=dpcfg.aMonStr[tempMonth-1];
  254. this.dd.mInput.setAttribute('realValue',tempMonth);}
  255. else{tempYear=this.year;
  256. tempMonth=this.month;}
  257. var firstDay,firstDate,lastDay,lastDate;
  258. var s=new __sb();
  259. var i,j,k;
  260. firstDay=new Date(tempYear,tempMonth-1,1).getDay();
  261. firstDate=1-firstDay;
  262. lastDay=new Date(tempYear,tempMonth,0).getDay();
  263. lastDate=new Date(tempYear,tempMonth,0).getDate();
  264. s.a("<table id=dpDayTable width=100% border=0 cellspacing=0 cellpadding=0>");
  265. s.a("<tr id=dpWeekTitle align=center>");
  266. var ss=new Array();
  267. for(i=0;i<7;i++){s.a("<td>"+dpcfg.aWeekStr[i]+"</td>");}
  268. var classStr='';
  269. var chassOnStr='';
  270. var isThisMonth=((tempYear==this.t_year)&&(tempMonth==this.t_month));
  271. var isSelMonth=((tempYear==this.s_year)&&(tempMonth==this.s_month));
  272. var needCompareMinDate=((tempYear*100+tempMonth*1)==(this.minDate.year*100+this.minDate.month));
  273. var needCompareMaxDate=((tempYear*100+tempMonth*1)==(this.maxDate.year*100+this.maxDate.month));
  274. var needCompareBoth=needCompareMinDate&&needCompareMaxDate;
  275. var isValidDate=!needCompareMinDate&&!needCompareMaxDate;
  276. for(i=1,j=firstDate;i<7;i++){s.a("<tr>");
  277. for(k=0;k<7;k++){if(j>=1&&j<=lastDate){if(isSelMonth&&(j==this.s_date)){classStr='Wselday';}
  278. else if(isThisMonth&&(j==this.t_date)){classStr='Wtoday';}
  279. else{classStr=((dpcfg.highLineWeekDay&&(k==0||k==6))?'Wwday':'Wday');}
  280. classOnStr=((dpcfg.highLineWeekDay&&(k==0||k==6))?'WwdayOn':'WdayOn');
  281. s.a("<td align=center ");
  282. if(isValidDate||(!needCompareBoth&&((needCompareMinDate&&j>=this.minDate.date)||(needCompareMaxDate&&j<=this.maxDate.date)))||(needCompareBoth&&(j>=this.minDate.date)&&(j<=this.maxDate.date))){s.a("onclick="$d.obj.pickDate(null,null,"+j+");" ");
  283. s.a("onmouseover="this.className='"+classOnStr+"'" ");
  284. s.a("onmouseout="this.className='"+classStr+"'" ");}
  285. else{classStr='WinvalidDay';}
  286. s.a("class='"+classStr+"'");
  287. s.a("><span>"+j+"</span>");}
  288. else{s.a("<td><span></span>");}
  289. j++;
  290. s.a("</td>");}
  291. s.a("</tr>");}
  292. s.a("</table>");
  293. return s.j();};
  294. My97DatePicker.prototype._createTimeTable=function(){var s=new __sb();
  295. s.a("<div id=dpTime style='"+((this.showTime)?'':'display:none;')+"float:left;margin-top:3px'><table cellspacing=0 cellpadding=0 border=0><tr><td rowspan=2><span id=dpTimeStr>"+dpcfg.timeStr+"</span>");
  296. s.a(" <input class=tB maxlength=2 value="+this.hour+"><input value=':' class=tm readonly>");
  297. s.a("<input class=tE maxlength=2 value="+this.minute+"><input value=':' class=tm readonly>");
  298. s.a("<input class=tE maxlength=2 value="+this.sec+"></td><td>");
  299. s.a("<button id=dpTimeUp></button></td></tr><tr><td><button id=dpTimeDown></button></td></tr></table></div>");
  300. s.a("<div id=dpButton style='float:right;margin-top:3px;text-align:right;'>");
  301. s.a("<input id=dpClearInput type=button value='"+dpcfg.clearStr+"'> <input id=dpTodayInput type=button value='"+dpcfg.todayStr+"'> <input id=dpOkInput type=button value='"+dpcfg.okStr+"'>");
  302. s.a("</div>");
  303. return s.j();};
  304. My97DatePicker.prototype._fillmonth=function()
  305. {var s=new __sb();
  306. s.a("<table cellspacing=0 cellpadding=2 border=0>");
  307. var i,n=0,v=parseInt(this.dd.mInput.getAttribute("realValue"));
  308. var aMonStrT=new Array(12);
  309. var aMonStrV=new Array(12);
  310. for(i=0;i<11;i++){if(i+1==v){n=1;}
  311. aMonStrT[i]=dpcfg.aMonStr[n+i];
  312. aMonStrV[i]=n+i+1;}
  313. this.year=parseInt(this.dd.yInput.value);
  314. var needCompareMinMonth=this.year==this.minDate.year;
  315. var needCompareMaxMonth=this.year==this.maxDate.year;
  316. var needCompareBoth=needCompareMinMonth&&needCompareMaxMonth;
  317. var validMonth=(this.year>this.minDate.year&&this.year<this.maxDate.year);
  318. var isValidMonth;
  319. for(i=0;i<6;i++){s.a("<tr><td ");
  320. isValidMonth=(validMonth)||(!needCompareBoth&&((needCompareMinMonth&&aMonStrV[i]>=this.minDate.month)||(needCompareMaxMonth&&aMonStrV[i]<=this.maxDate.month)))||(needCompareBoth&&(aMonStrV[i]>=this.minDate.month&&aMonStrV[i]<=this.maxDate.month));
  321. s.a((isValidMonth)?"class='Wym' onmouseover="this.className='WdayOn'" onmouseout="this.className='Wym'" onmousedown="$d.mInput.value="+aMonStrV[i]+";$d.mDiv.style.display='none';$d.mInput.blur();"":"class='Winvalidym'");
  322. s.a(">"+aMonStrT[i]+"</td>");
  323. if(i==5){break;}
  324. s.a("<td ");
  325. isValidMonth=(validMonth)||(!needCompareBoth&&((needCompareMinMonth&&aMonStrV[i+6]>=this.minDate.month)||(needCompareMaxMonth&&aMonStrV[i+6]<=this.maxDate.month)))||(needCompareBoth&&(aMonStrV[i+6]>=this.minDate.month&&aMonStrV[i+6]<=this.maxDate.month));
  326. s.a((isValidMonth)?"class='Wym' onmouseover="this.className='WymOn'" onmouseout="this.className='Wym'" onmousedown="$d.mInput.value="+aMonStrV[i+6]+";$d.mDiv.style.display='none';$d.mInput.blur();"":"class='Winvalidym'");
  327. s.a(">"+aMonStrT[i+6]+"</td></tr>");}
  328. s.a("<td align=center onmouseover="this.className='WymOn'" onmouseout="this.className='Wym'" onmousedown="$d.mDiv.style.display='none';">×</td></tr>");
  329. s.a("</table>");
  330. this.dd.mDiv.innerHTML=s.j();};
  331. My97DatePicker.prototype._fillyear=function(minV,maxV)
  332. {if(minV==null||maxV==null){var v=parseInt(this.dd.yInput.value);
  333. minV=v-5;maxV=v+4;}
  334. var i;
  335. var a=new Array(maxV-minV);
  336. for(i=minV;i<=maxV;i++){a[i-minV]=i;}
  337. var n=(a.length/2);
  338. var s=new __sb();
  339. var isValidYear;
  340. s.a("<table cellspacing=0 cellpadding=2 border=0>");
  341. for(i=0;i<n;i++){isValidYear=(a[i]>=this.minDate.year&&a[i]<=this.maxDate.year);
  342. s.a("<tr><td ");
  343. s.a((isValidYear)?"class='Wym' onmouseover="this.className='WymOn'" onmouseout="this.className='Wym'" onmousedown="$d.yInput.value='"+a[i]+"';$d.yDiv.style.display='none';$d.yInput.blur();"":"class='Winvalidym'");
  344. s.a(">"+a[i]+"</td><td ");
  345. isValidYear=(a[i+n]>=this.minDate.year&&a[i+n]<=this.maxDate.year);
  346. s.a((isValidYear)?"class='Wym' onmouseover="this.className='WymOn'" onmouseout="this.className='Wym'" onmousedown="$d.yInput.value='"+a[i+n]+"';$d.yDiv.style.display='none';$d.yInput.blur();"":"class='Winvalidym'");
  347. s.a(">"+a[i+n]+"</td></tr>");}
  348. s.a("</table>");
  349. s.a("<table cellspacing=0 cellpadding=3 border=0><tr><td ");
  350. s.a((this.minDate.year<minV)?"class='Wym' onmouseover="this.className='WymOn'" onmouseout="this.className='Wym'" onmousedown='$d.obj._fillyear("+(minV-10)+","+(maxV-10)+")'":"class='Winvalidym'");
  351. s.a(">u2190</td><td class='Wym' onmouseover="this.className='WymOn'" onmouseout="this.className='Wym'" onmousedown="$d.yDiv.style.display='none';$d.yInput.blur();">×</td><td ");
  352. s.a((this.maxDate.year>maxV)?"class='Wym' onmouseover="this.className='WymOn'" onmouseout="this.className='Wym'" onmousedown='$d.obj._fillyear("+(minV+10)+","+(maxV+10)+")'":"class='Winvalidym'");
  353. s.a(">u2192</td></tr></table>");
  354. this.dd.yDiv.innerHTML=s.j();};
  355. My97DatePicker.prototype._setOkInput=function(){this.dd.clearInput.onclick=function(){$d.obj.eCont.value='';};
  356. this.dd.todayInput.onclick=function(){var d=$d.obj;d.pickDate(d.t_year,d.t_month,d.t_date,d.t_hour,d.t_minute,d.t_sec);};
  357. this.dd.okInput.onclick=function(){$d.obj.modifyDate();};
  358. if(this.eCont.value==""&&this.hasDate){if(((this.t_year*10000+this.t_month*100+this.t_date*1)>=(this.minDate.year*10000+this.minDate.month*100+this.minDate.date*1))&&((this.t_year*10000+this.t_month*100+this.t_date*1)<=(this.maxDate.year*10000+this.maxDate.month*100+this.maxDate.date*1))){this.dd.todayInput.style.display='inline';
  359. this.dd.clearInput.style.display=this.dd.okInput.style.display='none';}
  360. else{this.dd.okInput.style.display='inline';
  361. this.dd.todayInput.style.display=this.dd.clearInput.style.display='none';}
  362. this.dd.bDiv.onmouseover=function(){};
  363. this.dd.bDiv.onmouseout=function(){};}
  364. else{this.dd.okInput.style.display='inline';
  365. this.dd.clearInput.style.display=this.dd.todayInput.style.display='none';
  366. this.dd.bDiv.onmouseover=function(){$d.tDiv.style.display='none';
  367. $d.clearInput.style.display='inline';
  368. if((($d.obj.t_year*10000+$d.obj.t_month*100+$d.obj.t_date*1)>=($d.obj.minDate.year*10000+$d.obj.minDate.month*100+$d.obj.minDate.date*1))&&(($d.obj.t_year*10000+$d.obj.t_month*100+$d.obj.t_date*1)<=($d.obj.maxDate.year*10000+$d.obj.maxDate.month*100+$d.obj.maxDate.date*1))){$d.obj.dd.todayInput.style.display='inline';}
  369. else{$d.obj.dd.todayInput.style.display='none';}};
  370. this.dd.bDiv.onmouseout=function(){if($d.obj.showTime){$d.tDiv.style.display='inline';}
  371. $d.clearInput.style.display=$d.todayInput.style.display='none';};}};
  372. My97DatePicker.prototype._returnDateStr=function(Y,M,D,h,m,s,fmt)
  373. {if(Y==null){Y=this.year;}
  374. if(M==null){M=this.month;}
  375. if(D==null){D=this.date;}
  376. if(h==null){h=this.hour;}
  377. if(m==null){m=this.minute;}
  378. if(s==null){s=this.sec;}
  379. if(fmt==null){fmt=this.dateFmt;}
  380. var sDate=fmt.replace(/%[Yy]/,this._doStr(Y,4)).replace(/%[M]/,this._doStr(M,2)).replace(/%[Dd]/,this._doStr(D,2));
  381. if(this.showTime){sDate=sDate.replace(/%[Hh]/,this._doStr(h,2)).replace(/%[m]/,this._doStr(m,2)).replace(/%[Ss]/,this._doStr(s,2));}
  382. return sDate;};
  383. My97DatePicker.prototype._doStr=function(s,len){s=s+'';
  384. for(var i=s.length;i<len;i++){s='0'+s;}
  385. return s;};
  386. My97DatePicker.prototype._setRealValue=function(Y,M,D,h,m,s){if(this.showTime){this.eCont.setAttribute("REALVALUE",this._returnDateStr(Y,M,D,h,m,s,dpcfg.realValueLongFmt));}
  387. else{this.eCont.setAttribute("REALVALUE",this._returnDateStr(Y,M,D,null,null,null,dpcfg.realValueShortFmt));}};
  388. My97DatePicker.prototype.pickDate=function(Y,M,D,h,m,s){if(Y==null){Y=this.dd.yInput.value;}
  389. if(M==null){M=this.dd.mInput.getAttribute("realValue");}
  390. if(D==null){D=this.date;}
  391. this.year=Y;this.month=M;this.date=D;
  392. if(this.showTime){if(h==null){h=this.dd.hhInput.value;}
  393. if(m==null){m=this.dd.mmInput.value;}
  394. if(s==null){s=this.dd.ssInput.value;}
  395. this.hour=h;this.minute=m;this.sec=s;
  396. this.eCont.value=this._returnDateStr(Y,M,D,h,m,s);}
  397. else{this.eCont.value=this._returnDateStr(Y,M,D);}
  398. this._setRealValue(Y,M,D,h,m,s);
  399. $d.obj._markValue(true);
  400. parent.document.dateDiv.style.display='none';
  401. this.onPicked();};
  402. My97DatePicker.prototype.modifyDate=function(Y,M,D,h,m,s){if(Y==null){Y=this.dd.yInput.value;}
  403. if(M==null){M=this.dd.mInput.getAttribute("realValue");}
  404. if(D==null){D=this.date;}
  405. this.year=Y;this.month=M;this.date=D;
  406. if(this.showTime){if(h==null){h=this.dd.hhInput.value;}
  407. if(m==null){m=this.dd.mmInput.value;}
  408. if(s==null){s=this.dd.ssInput.value;}
  409. this.hour=h;this.minute=m;this.sec=s;
  410. this.eCont.value=this._returnDateStr(Y,M,D,h,m,s);}
  411. else{this.eCont.value=this._returnDateStr(Y,M,D);}
  412. if((Y*10000+M*100+D*1)<(this.minDate.year*10000+this.minDate.month*100+this.minDate.date*1)){Y=this.minDate.year;
  413. M=this.minDate.month;
  414. D=this.minDate.date;}
  415. else if((Y*10000+M*100+D*1)>(this.maxDate.year*10000+this.maxDate.month*100+this.maxDate.date*1)){Y=this.maxDate.year;
  416. M=this.maxDate.month;
  417. D=this.maxDate.date;}else{while(!this._isDate(Y+'-'+M+'-'+D)&&D>0){D--;}}
  418. this.pickDate(Y,M,D);}
  419. My97DatePicker.prototype._markValue=function(bValue){if(bValue){this.eCont.className=this.eCont.className.replace(/ WdateFmtErr/,'');}
  420. else{var tempMode=dpcfg.errDealMode;
  421. while(true){switch(tempMode){case 0:
  422. if(!confirm(dpcfg.errAlertMsg)){tempMode=2;
  423. continue;}
  424. case 1:
  425. if(this.eCont.getAttribute("REALVALUE")){this._judgeCorrectDateTime(this.eCont.getAttribute("REALVALUE"));}else{this.eCont.value="";}
  426. this.eCont.className=this.eCont.className.replace(/ WdateFmtErr/,'');
  427. break;
  428. case 2:
  429. this.eCont.className=this.eCont.className.replace(/ WdateFmtErr/,'');
  430. this.eCont.className=this.eCont.className.replace(/Wdate/,'Wdate WdateFmtErr');
  431. break;}
  432. break;}}};
  433. My97DatePicker.prototype._judgeCorrectDateTime=function(sDateTime){var Y,M,D,h,m,s;
  434. var v=sDateTime.split(/W+/);
  435. var f=this.dateFmt.match(/%./g);
  436. for(var i=0;i<f.length;i++){if(f[i].toLowerCase()=='%y'){Y=Number(v[i]);
  437. if(isNaN(Y)){return false;}}
  438. else if(f[i]=='%M'){M=Number(v[i]);
  439. if(isNaN(M)){return false;}}
  440. else if(f[i].toLowerCase()=='%d'){D=Number(v[i]);
  441. if(isNaN(D)){return false;}}
  442. else if(f[i].toLowerCase()=='%h'){h=Number(v[i]);
  443. if(isNaN(h)){return false;}}
  444. else if(f[i]=='%m'){m=Number(v[i]);
  445. if(isNaN(m)){return false;}}
  446. else if(f[i].toLowerCase()=='%s'){s=Number(v[i]);
  447. if(isNaN(s)){return false;}}}
  448. Y=Y||this.minDate.year;
  449. M=M||this.minDate.month;
  450. D=D||this.minDate.date;
  451. if(this._isDate(Y+'-'+M+'-'+D)&&(h==undefined||(h>=0)&&(h<=23))&&(s==undefined||(m>=0)&&(h<=59))&&(s==undefined||(s>=0)&&(s<=59))){this.eCont.value=this._returnDateStr(Y,M,D,h,m,s);
  452. if(((Y*10000+M*100+D*1)>=(this.minDate.year*10000+this.minDate.month*100+this.minDate.date*1))&&((Y*10000+M*100+D*1)<=(this.maxDate.year*10000+this.maxDate.month*100+this.maxDate.date*1))){return true;}}
  453. return false;};
  454. My97DatePicker.prototype._doCustomDate=function(str,fmt,dvType){var defaultValue=(dvType=="min")?dpcfg.minDate:dpcfg.maxDate;
  455. if(!str||str==''){str=defaultValue;}
  456. var re=/{(.*?)}/
  457. var year,month,day;
  458. var arr;
  459. var tmpEval="";
  460. var hasLastDay=(str.indexOf('#lastDay#')>=0);
  461. str=str.replace(/#Year#/g,this.t_year).replace(/#Month#/g,this.t_month).replace(/#Day#/g,this.t_date).replace(/#lastDay#/,'0');
  462. if(str.substring(0,3)=="#F{"){if((arr=re.exec(str))!=null){str=parent.$dp.obj.win.eval(arr[1]);}
  463. else{alert("Function error!");
  464. return;}}
  465. else{var i=0;
  466. while((arr=re.exec(str))!=null){if(i++==97){break;}
  467. arr.lastIndex=arr.index+arr[1].length+1;
  468. tmpEval=parseInt(eval(arr[1]),10);
  469. if(tmpEval<0){tmpEval='19700'+(-tmpEval);}
  470. str=str.substring(0,arr.index)+tmpEval+str.substring(arr.lastIndex);}}
  471. if(str==''){str=defaultValue;}
  472. var v=str.split(/W+/);
  473. var f=fmt.match(/%./g);
  474. for(var i=0;i<f.length;i++){if(v[i]){if(f[i].toLowerCase()=='%y'){year=parseInt(v[i],10);}
  475. else if(f[i]=='%M'){month=parseInt(v[i],10);}
  476. else if(f[i].toLowerCase()=='%d'){day=parseInt(v[i],10);}}}
  477. year=(""+year).replace(/^19700/,"-");
  478. month=(""+month).replace(/^19700/,"-");
  479. day=(""+day).replace(/^19700/,"-");
  480. if(!hasLastDay){month-=1;}
  481. var tmp=new Date();
  482. tmp=new Date(year,month,day);
  483. year=tmp.getFullYear();
  484. month=tmp.getMonth()+1;
  485. day=tmp.getDate();
  486. if(isNaN(year)||isNaN(month)||isNaN(day)){alert('u65E5u671Fu8303u56F4u683Cu5F0Fu9519u8BEF(Invalid MINDATE or MAXDATE)!nnYear:'+year+'  Month:'+month+'  Day:'+day);}
  487. return{'year':year,'month':month,'date':day};}
  488. function hideYMSel(){$d.yDiv.style.display=$d.mDiv.style.display='none';}
  489. function autoSizeIframe(){if(window!=parent){var ifs=parent.document.getElementsByTagName("IFRAME");
  490. for(var i=0;i<ifs.length;i++){try
  491. {if(ifs[i].contentWindow==window){var tmp=document.getElementsByTagName('div')[0];
  492. ifs[i].style.width=tmp.offsetWidth+"px";
  493. ifs[i].style.height=tmp.offsetHeight+"px";}}
  494. catch(e){continue;}}}}