Date.js
//JavaScript Documentvargmonths=NewArray ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");varweekday=NewArray ("Day", "one", "two", "three", "four", "five", "six");varStrtoday= "Today";varStryear= "Year";varStrmonth= "Month";varStrday= "Day";varSplitchar= "-";varstartyear=2000;varendyear=2050;varDaytdheight=12;varDaytdtextsize=12;varGcnotcurmonth= "#E0E0E0";varGcrestday= "#FF0000";varGcworkday= "#444444";varGcmouseover= "#79D0FF";vargcmouseout= "#F4F4F4";varGctoday= "#444444";varGctodaymouseover= "#6699FF";vargctodaymouseout= "#79D0FF";varGdctrl=NewObject ();vargoselecttag=NewArray ();varGdcurdate=NewDate ();varGiyear=gdcurdate.getfullyear ();varGimonth=gdcurdate.getmonth (+1);vargiday=gdcurdate.getdate ();function$(){varelements=NewArray (); for(vari=0;i<arguments.length;i++) {varElement=arguments[i];if(typeof(Arguments[i]) = = ' String ') {Element=document.getelementbyid (arguments[i]);}if(arguments.length==1) {returnelement;} Elements. Push (element);}returnelements;} Array.prototype.Push=function(){varStartlength= This. length; for(vari=0;i<arguments.length;i++) { This[Startlength+i]=arguments[i];}return This. Length;} String.prototype.HexToDec=function(){returnparseint ( This, 16);} String.prototype.cleanBlank=function(){return This. IsEmpty ()? "": This. replace (/\s/g, "");}functionCheckcolor () {varcolor_tmp= (arguments[0]+ ""). Replace (/\s/g, ""). toUpperCase ();varModel_tmp1=arguments[1].touppercase ();varModel_tmp2= "RGB (" +arguments[1].substring (1,3). Hextodec () + "," +arguments[1].substring (1,3). Hextodec () + "," +arguments[1].substring (5). Hextodec () + ")"; Model_tmp2=model_tmp2.touppercase ();if(COLOR_TMP==MODEL_TMP1 | | COLOR_TMP==MODEL_TMP2) {return true;}return false;}function$V () {return$ (arguments[0]). Value;}functionFpopcalendar (Evt,popctrl,datectrl) {evt.cancelbubble=true; Gdctrl=datectrl;fsetyearmon (Giyear,gimonth);varPoint=fgetxy (Popctrl); with($ ("Calendardiv"). Style) {left=point.x+ "px"; top= (point.y+popctrl.offsetheight+1) + "px"; visibility= ' visible '; zindex= ';p osition= ' Absolute ';} $ ("Calendardiv"). focus ();}functionFsetdate (Iyear,imonth,iday) {varimonthnew=NewString (Imonth);varidaynew=NewString (Iday);if(IMONTHNEW.LENGTH<2) {imonthnew= "0" +imonthnew;}if(IDAYNEW.LENGTH<2) {idaynew= "0" +idaynew;} gdctrl.value=iyear+splitchar+imonthnew+splitchar+Idaynew;fhidecalendar ();}functionFhidecalendar () {$ ("Calendardiv"). style.visibility= "hidden"; for(vari=0;i<goselecttag.length;i++) {goselecttag[i].style.visibility= "visible";} Goselecttag.length=0;}functionFsetselected () {varioffset=0;varIyear=parseint ($ ("Tbselyear"). Value);varImonth=parseint ($ ("Tbselmonth"). Value);varacell=$ ("Celltext" +arguments[0]); acell.bgcolor=gcmouseout; with(Acell) {varIday=parseint (InnerHTML);if(Checkcolor (Style.color,gcnotcurmonth)) {ioffset= (innerhtml>10)? -1:1;} Imonth+=ioffset;if(imonth<1) {iyear--;imonth=12;}Else if(IMONTH>12) {iyear++;imonth=1;}} Fsetdate (Iyear,imonth,iday);}functionPoint (Ix,iy) { This. X=ix; This. y=IY;}functionFbuildcal (iyear,imonth) {varAmonth=NewArray (); for(vari=1;i<7;i++) {amonth[i]=NewArray (i);}varDcaldate=NewDate (iyear,imonth-1,1);varIdayoffirst=dcaldate.getday ();varIdaysinmonth=NewDate (iyear,imonth,0). GetDate ();varioffsetlast=NewDate (iyear,imonth-1,0). GetDate ()-idayoffirst+1;varidate=1;varInext=1; for(vard=0;d<7;d++) {amonth[1][d]= (D<idayoffirst)? ( IOFFSETLAST+D) * ( -1): idate++;} for(varw=2;w<7;w++) { for(vard=0;d<7;d++) {amonth[w][d]= (idate<=idaysinmonth) idate++:(inext++) * (-1);}}returnAMonth;}functionFdrawcal (iyear,imonth,icellheight,idatetextsize) {varcolortd= "bgcolor=" "+gcmouseout+" ' bordercolor= ' "+gcmouseout+" ' ";varstyletd= "valign= ' Middle ' align= ' center ' style= ' height:" +icellheight+ "px;font-weight:bolder;font-size:" + idatetextsize+ "PX;";varDatecal= "";d atecal+= "<tr>"; for(vari=0;i<7;i++) {datecal+= "<td" +colortd+styletd+ "color: #990099 ' >" +weekday[i]+ "</td>";} datecal+= "</tr>"; for(varw=1;w<7;w++) {datecal+= "<tr>"; for(vard=0;d<7;d++) {vartmpid=w+ "" +d;datecal+= "<td" +styletd+ "cursor:pointer; ' onclick= ' fsetselected (" +tmpid+ ") ' >;d atecal+= ' < Span id= ' Celltext "+tmpid+" ></span> ";d atecal+=" </td> ";} datecal+= "</tr>";}returndatecal;}functionFupdatecal (iyear,imonth) {varMymonth=fbuildcal (Iyear,imonth);vari=0; for(varw=1;w<7;w++) { for(vard=0;d<7;d++) { with($ ("Celltext" +w+ "" +d)) {parentnode.bgcolor=gcmouseout;parentnode.bordercolor=gcmouseout;parentnode.onmouseover=function(){ This. Bgcolor=gcmouseover;}; parentnode.onmouseout=function(){ This. Bgcolor=gcmouseout;};if(mymonth[w][d]<0) {style.color=gcnotcurmonth;innerhtml=math.abs (mymonth[w][d]);}Else{style.color= ((d==0) | | | (d==6))? GCRESTDAY:GCWORKDAY;INNERHTML=MYMONTH[W][D];if(Iyear==giyear && imonth==gimonth && mymonth[w][d]==giday) {style.color=gctoday;parentnode.bgcolor=gctodaymouseout;parentnode.onmouseover=function(){ This. Bgcolor=gctodaymouseover;}; parentnode.onmouseout=function(){ This. bgcolor=gctodaymouseout; }}}}}functionFsetyearmon (Iyear,imon) {$ ("Tbselmonth"). options[imon-1].selected=true; for(vari=0;i<$ ("Tbselyear"). length;i++) {if($ ("Tbselyear"). Options[i].value==iyear) {$ ("tbselyear"). options[i].selected=true;}} Fupdatecal (Iyear,imon);}functionFprevmonth () {varimon=$ ("Tbselmonth"). Value;variyear=$ ("Tbselyear"). Value;if(--imon<1) {imon=12;iyear--;} Fsetyearmon (Iyear,imon);}functionFnextmonth () {varimon=$ ("Tbselmonth"). Value;variyear=$ ("Tbselyear"). Value;if(++IMON>12) {imon=1;iyear++;} Fsetyearmon (Iyear,imon);}functionFgetxy (ATAG) {varOtmp=atag;varpt=NewPoint (0,0); Do{pt.x+=otmp.offsetleft;pt.y+=otmp.offsettop;otmp=otmp.offsetparent;} while(OTmp.tagName.toUpperCase ()! = "BODY");returnpt;}functionGetdatediv () {varNoselectforie= "";varNoselectforfirefox= "";if(document.all) {noselectforie= "onselectstart= ' return false; '";}Else{noselectforfirefox= "-moz-user-select:none;";}vardatediv= "";d atediv+= "<div id= ' calendardiv ' onclick= ' event.cancelbubble=true '" +noselectforie+ "style= '" + noselectforfirefox+ "position:absolute;z-index:99;visibility:hidden;border:1px solid #999999; > ";d atediv+=" <table border= ' 0 ' bgcolor= ' #E0E0E0 ' cellpadding= ' 1 ' cellspacing= ' 1 ' > ";d atediv+=" <tr> "; datediv+= "<td><input type= ' button ' id= ' prevmonth ' value= ' < ' style= ' height:20px;width:20px;font-weight: Bolder, ' onclick= ' fprevmonth () ' > ';d atediv+= ' </td><td><select id= ' tbselyear ' style= ' border:1px solid; ' onchange= ' fupdatecal ($V (\ "Tbselyear\"), $V (\ "tbselmonth\")) ' > '; for(vari=startyear;i<endyear;i++) {datediv+= "<option value= '" +i+ "' >" +i+stryear+ "</option>";} datediv+= "</select></td><td>";d atediv+= "<select id= ' tbselmonth ' style= ' border:1px solid; ' Onchange= ' fupdatecal ($V (\ "Tbselyear\"), $V (\ "tbselmonth\")) ' > '; for(var i=0;i<12;i++) {datediv+= "<option value=" "+ (i+1) +" ' > "+gmonths[i]+" </option> ";} datediv+= "</select></td><td>";d atediv+= "<input type= ' button ' id= ' nextmonth ' value= ' > ' Style= ' Height:20px;width:20px;font-weight:bolder; ' onclick= ' fnextmonth () ' > ";d atediv+=" </td> ";d atediv+= "</tr><tr>";d atediv+= "<td align= ' center ' colspan= ' 4 ' >";d atediv+= "<div style= ' Background-color: #cccccc ' ><table width= ' 100% ' border= ' 0 ' cellpadding= ' 3 ' cellspacing= ' 1 ' > ';d atediv+= Fdrawcal (giyear,gimonth,daytdheight,daytdtextsize);d atediv+= "</table></div>";d atediv+= "</td> ";d atediv+=" </tr><tr><td align= ' center ' colspan= ' 4 ' nowrap> ";d atediv+=" <span style= ' cursor: Pointer;font-weight:bolder, ' onclick= ' fsetdate (giyear,gimonth,giday) ' onmouseover= ' this.style.color=\ ' + gcmouseover+ "\" ' onmouseout= ' this.style.color=\ "#000000 \" > "+strtoday+": "+giyear+stryear+gimonth+strmonth+ giday+strday+ "</span>";d atediv+= "</tR></tr> ";d atediv+=" </table></div> "; returnDatediv;} with(document) {Onclick=fhidecalendar;write (Getdatediv ());}
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title><Scriptlanguage= "JavaScript"src= "Date.js"></Script></Head><Body><inputReadOnly= "ReadOnly"onclick= "Fpopcalendar (event,this,this)"onfocus= "This.select ()"/></Body></HTML>