function Epoch(B,E,C,A,D){this.format=D;this.state=0;this.name=B;this.curDate=new Date();this.mode=E;this.selectMultiple=(A==true);this.selectedDates=new Array();this.calendar;this.calHeading;this.calCells;this.rows;this.cols;this.cells=new Array();this.monthSelect;this.yearSelect;this.mousein=false;this.calConfig();this.setDays();this.displayYear=this.displayYearInitial;this.displayMonth=this.displayMonthInitial;this.createCalendar();if(this.mode=="popup"&&C&&C.type=="text"){this.tgt=C;this.calendar.style.position="absolute";this.topOffset=this.tgt.offsetHeight;this.leftOffset=0;this.calendar.style.top=this.getTop(C)+this.topOffset+"px";this.calendar.style.left=this.getLeft(C)+this.leftOffset+"px";document.body.appendChild(this.calendar);this.tgt.calendar=this;this.tgt.onfocus=function(){this.calendar.show()};this.tgt.onblur=function(){if(!this.calendar.mousein){this.calendar.hide()}}}else{this.container=C;this.container.appendChild(this.calendar)}this.state=2;this.visible?this.show():this.hide()}Epoch.prototype.calConfig=function(){this.displayYearInitial=this.curDate.getFullYear();this.displayMonthInitial=this.curDate.getMonth();this.rangeYearLower=1910;this.rangeYearUpper=2008+50;this.minDate=new Date(1910,0,1);this.maxDate=new Date(2008,0,1);this.startDay=0;this.showWeeks=true;this.selCurMonthOnly=false;this.clearSelectedOnChange=true;switch(this.mode){case"popup":this.visible=false;break;case"flat":this.visible=true;break}this.setLang()};Epoch.prototype.setLang=function(){this.daylist=new Array("Su","Mo","Tu","We","Th","Fr","Sa","Su","Mo","Tu","We","Th","Fr","Sa");this.months_sh=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");this.monthup_title="Go to the next month";this.monthdn_title="Go to the previous month";this.clearbtn_caption="Clear";this.clearbtn_title="Clears any dates selected on the calendar";this.maxrange_caption="This is the maximum range"};Epoch.prototype.getTop=function(A){var C=A;var B=0;while(C.tagName!="BODY"){B+=C.offsetTop;C=C.offsetParent}return B};Epoch.prototype.getLeft=function(A){var C=A;var B=0;while(C.tagName!="BODY"){B+=C.offsetLeft;C=C.offsetParent}return B};Epoch.prototype.show=function(){this.calendar.style.display="block";this.visible=true};Epoch.prototype.hide=function(){this.calendar.style.display="none";this.visible=false};Epoch.prototype.toggle=function(){if(this.visible){this.hide()}else{this.show()}};Epoch.prototype.setDays=function(){this.daynames=new Array();var A=0;for(var B=this.startDay;B<this.startDay+7;B++){this.daynames[A++]=this.daylist[B]}this.monthDayCount=new Array(31,((this.curDate.getFullYear()-2000)%4?28:29),31,30,31,30,31,31,30,31,30,31)};Epoch.prototype.setClass=function(A,B){A.setAttribute("class",B);A.setAttribute("className",B)};Epoch.prototype.createCalendar=function(){var A,B,C;this.calendar=document.createElement("table");this.calendar.setAttribute("id",this.name+"_calendar");this.setClass(this.calendar,"calendar");this.calendar.onselectstart=function(){return false};this.calendar.ondrag=function(){return false};A=document.createElement("tbody");B=document.createElement("tr");C=document.createElement("td");C.appendChild(this.createMainHeading());B.appendChild(C);A.appendChild(B);B=document.createElement("tr");C=document.createElement("td");C.appendChild(this.createDayHeading());B.appendChild(C);A.appendChild(B);B=document.createElement("tr");C=document.createElement("td");C.setAttribute("id",this.name+"_cell_td");this.calCellContainer=C;C.appendChild(this.createCalCells());B.appendChild(C);A.appendChild(B);B=document.createElement("tr");C=document.createElement("td");C.appendChild(this.createFooter());B.appendChild(C);A.appendChild(B);this.calendar.appendChild(A);this.calendar.owner=this;this.calendar.onmouseover=function(){this.owner.mousein=true};this.calendar.onmouseout=function(){this.owner.mousein=false}};Epoch.prototype.createMainHeading=function(){var A=document.createElement("div");A.setAttribute("id",this.name+"_mainheading");this.setClass(A,"mainheading");this.monthSelect=document.createElement("select");this.yearSelect=document.createElement("select");var E=document.createElement("input"),D=document.createElement("input");var C,B;for(B=0;B<12;B++){C=document.createElement("option");C.setAttribute("value",B);if(this.state==0&&this.displayMonth==B){C.setAttribute("selected","selected")}C.appendChild(document.createTextNode(this.months_sh[B]));this.monthSelect.appendChild(C)}for(B=this.rangeYearLower;B<=this.rangeYearUpper;B++){C=document.createElement("option");C.setAttribute("value",B);if(this.state==0&&this.displayYear==B){C.setAttribute("selected","selected")}C.appendChild(document.createTextNode(B));this.yearSelect.appendChild(C)}D.setAttribute("type","button");D.setAttribute("value",">");D.setAttribute("title",this.monthup_title);E.setAttribute("type","button");E.setAttribute("value","<");E.setAttribute("title",this.monthdn_title);this.monthSelect.owner=this.yearSelect.owner=D.owner=E.owner=this;D.onmouseup=function(){this.owner.nextMonth()};E.onmouseup=function(){this.owner.prevMonth()};this.monthSelect.onchange=function(){this.owner.displayMonth=this.value;this.owner.displayYear=this.owner.yearSelect.value;this.owner.goToMonth(this.owner.displayYear,this.owner.displayMonth)};this.yearSelect.onchange=function(){this.owner.displayMonth=this.owner.monthSelect.value;this.owner.displayYear=this.value;this.owner.goToMonth(this.owner.displayYear,this.owner.displayMonth)};A.appendChild(E);A.appendChild(this.monthSelect);A.appendChild(this.yearSelect);A.appendChild(D);return A};Epoch.prototype.createFooter=function(){var A=document.createElement("div");var B=document.createElement("input");B.setAttribute("type","button");B.setAttribute("value",this.clearbtn_caption);B.setAttribute("title",this.clearbtn_title);B.owner=this;B.onclick=function(){this.owner.resetSelections(false)};A.appendChild(B);return A};Epoch.prototype.resetSelections=function(A){this.selectedDates=new Array();this.rows=new Array(false,false,false,false,false,false,false);this.cols=new Array(false,false,false,false,false,false,false);if(this.tgt){this.tgt.value="";if(this.mode=="popup"){this.hide()}}if(A==true){this.goToMonth(this.displayYearInitial,this.displayMonthInitial)}else{this.reDraw()}};Epoch.prototype.createDayHeading=function(){this.calHeading=document.createElement("table");this.calHeading.setAttribute("id",this.name+"_caldayheading");this.setClass(this.calHeading,"caldayheading");var A,B,D;A=document.createElement("tbody");B=document.createElement("tr");this.cols=new Array(false,false,false,false,false,false,false);if(this.showWeeks){D=document.createElement("td");D.setAttribute("class","wkhead");D.setAttribute("className","wkhead");B.appendChild(D)}for(var C=0;C<7;C++){D=document.createElement("td");D.appendChild(document.createTextNode(this.daynames[C]));if(this.selectMultiple){D.headObj=new CalHeading(this,D,(C+this.startDay<7?C+this.startDay:C+this.startDay-7))}B.appendChild(D)}A.appendChild(B);this.calHeading.appendChild(A);return this.calHeading};Epoch.prototype.createCalCells=function(){this.rows=new Array(false,false,false,false,false,false);this.cells=new Array();var J=-1,C=(this.showWeeks?48:42);var D=new Date(this.displayYear,this.displayMonth,1);var G=new Date(this.displayYear,this.displayMonth,this.monthDayCount[this.displayMonth]);var A=new Date(D);A.setDate(A.getDate()+(this.startDay-D.getDay())-(this.startDay-D.getDay()>0?7:0));this.calCells=document.createElement("table");this.calCells.setAttribute("id",this.name+"_calcells");this.setClass(this.calCells,"calcells");var F,H,B;F=document.createElement("tbody");for(var E=0;E<C;E++){if(this.showWeeks){if(E%8==0){J++;H=document.createElement("tr");B=document.createElement("td");if(this.selectMultiple){B.weekObj=new WeekHeading(this,B,A.getWeek(),J)}else{B.setAttribute("class","wkhead");B.setAttribute("className","wkhead")}B.appendChild(document.createTextNode(A.getWeek()));H.appendChild(B);E++}}else{if(E%7==0){J++;H=document.createElement("tr")}}B=document.createElement("td");B.appendChild(document.createTextNode(A.getDate()));var I=new CalCell(this,B,A,J,this.format);this.cells.push(I);B.cellObj=I;A.setDate(A.getDate()+1);H.appendChild(B);F.appendChild(H)}this.calCells.appendChild(F);this.reDraw();return this.calCells};Epoch.prototype.reDraw=function(){this.state=1;var B,A;for(B=0;B<this.cells.length;B++){this.cells[B].selected=false}for(B=0;B<this.cells.length;B++){for(A=0;A<this.selectedDates.length;A++){if(this.cells[B].date.getUeDay()==this.selectedDates[A].getUeDay()){this.cells[B].selected=true}}this.cells[B].setClass()}this.state=2};Epoch.prototype.deleteCells=function(){this.calCellContainer.removeChild(this.calCellContainer.firstChild);this.cells=new Array()};Epoch.prototype.goToMonth=function(A,B){this.monthSelect.value=this.displayMonth=B;this.yearSelect.value=this.displayYear=A;this.deleteCells();this.calCellContainer.appendChild(this.createCalCells())};Epoch.prototype.nextMonth=function(){if(this.monthSelect.value<11){this.monthSelect.value++}else{if(this.yearSelect.value<this.rangeYearUpper){this.monthSelect.value=0;this.yearSelect.value++}else{alert(this.maxrange_caption)}}this.displayMonth=this.monthSelect.value;this.displayYear=this.yearSelect.value;this.deleteCells();this.calCellContainer.appendChild(this.createCalCells())};Epoch.prototype.prevMonth=function(){if(this.monthSelect.value>0){this.monthSelect.value--}else{if(this.yearSelect.value>this.rangeYearLower){this.monthSelect.value=11;this.yearSelect.value--}else{alert(this.maxrange_caption)}}this.displayMonth=this.monthSelect.value;this.displayYear=this.yearSelect.value;this.deleteCells();this.calCellContainer.appendChild(this.createCalCells())};Epoch.prototype.addZero=function(A){return((A<10)?"0":"")+A};Epoch.prototype.addDates=function(D,E){var A,C;for(var B=0;B<D.length;B++){C=false;for(A=0;A<this.selectedDates.length;A++){if(D[B].getUeDay()==this.selectedDates[A].getUeDay()){C=true;break}}if(!C){this.selectedDates.push(D[B])}}if(E!=false){this.reDraw()}};Epoch.prototype.removeDates=function(C,D){var A;for(var B=0;B<C.length;B++){for(A=0;A<this.selectedDates.length;A++){if(C[B].getUeDay()==this.selectedDates[A].getUeDay()){this.selectedDates.splice(A,1)}}}if(D!=false){this.reDraw()}};Epoch.prototype.outputDate=function(C,I){var J=this.addZero(C.getDate());var G=this.addZero(C.getMonth()+1);var A=this.addZero(C.getFullYear());var F=this.addZero(C.getFullYear().toString().substring(3,4));var H=(I.indexOf("yyyy")>-1?A:F);var E=this.addZero(C.getHours());var D=this.addZero(C.getMinutes());var B=this.addZero(C.getSeconds());return I.replace(/dd/g,J).replace(/mm/g,G).replace(/y{1,4}/g,H).replace(/hh/g,E).replace(/nn/g,D).replace(/ss/g,B)};Epoch.prototype.updatePos=function(A){this.calendar.style.top=this.getTop(A)+this.topOffset+"px";this.calendar.style.left=this.getLeft(A)+this.leftOffset+"px"};function CalHeading(A,C,B){this.owner=A;this.tableCell=C;this.dayOfWeek=B;this.tableCell.onclick=this.onclick}CalHeading.prototype.onclick=function(){var A=this.headObj.owner;var E=A.selectedDates;var C=A.cells;A.cols[this.headObj.dayOfWeek]=!A.cols[this.headObj.dayOfWeek];for(var D=0;D<C.length;D++){if(C[D].dayOfWeek==this.headObj.dayOfWeek&&(!A.selCurMonthOnly||C[D].date.getMonth()==A.displayMonth&&C[D].date.getFullYear()==A.displayYear)){if(A.cols[this.headObj.dayOfWeek]){if(A.selectedDates.arrayIndex(C[D].date)==-1){E.push(C[D].date)}}else{for(var B=0;B<E.length;B++){if(C[D].dayOfWeek==E[B].getDay()){E.splice(B,1);break}}}C[D].selected=A.cols[this.headObj.dayOfWeek]}}A.reDraw()};function WeekHeading(A,D,B,C){this.owner=A;this.tableCell=D;this.week=B;this.tableRow=C;this.tableCell.setAttribute("class","wkhead");this.tableCell.setAttribute("className","wkhead");this.tableCell.onclick=this.onclick}WeekHeading.prototype.onclick=function(){var A=this.weekObj.owner;var C=A.cells;var E=A.selectedDates;var D,B;A.rows[this.weekObj.tableRow]=!A.rows[this.weekObj.tableRow];for(D=0;D<C.length;D++){if(C[D].tableRow==this.weekObj.tableRow){if(A.rows[this.weekObj.tableRow]&&(!A.selCurMonthOnly||C[D].date.getMonth()==A.displayMonth&&C[D].date.getFullYear()==A.displayYear)){if(A.selectedDates.arrayIndex(C[D].date)==-1){E.push(C[D].date)}}else{for(B=0;B<E.length;B++){if(E[B].getTime()==C[D].date.getTime()){E.splice(B,1);break}}}}}A.reDraw()};function CalCell(A,E,B,D,C){this.owner=A;this.tableCell=E;this.cellClass;this.selected=false;this.date=new Date(B);this.dayOfWeek=this.date.getDay();this.week=this.date.getWeek();this.tableRow=D;this.format=C;this.tableCell.onclick=this.onclick;this.tableCell.onmouseover=this.onmouseover;this.tableCell.onmouseout=this.onmouseout;this.setClass()}CalCell.prototype.onmouseover=function(){this.setAttribute("class",this.cellClass+" hover");this.setAttribute("className",this.cellClass+" hover")};CalCell.prototype.onmouseout=function(){this.cellObj.setClass()};CalCell.prototype.onclick=function(){var B=this.cellObj;var A=B.owner;if(!A.selCurMonthOnly||B.date.getMonth()==A.displayMonth&&B.date.getFullYear()==A.displayYear){if(A.selectMultiple==true){if(!B.selected){if(A.selectedDates.arrayIndex(B.date)==-1){A.selectedDates.push(B.date)}}else{var D=A.selectedDates;for(var C=0;C<D.length;C++){if(D[C].getUeDay()==B.date.getUeDay()){D.splice(C,1)}}}}else{A.selectedDates=new Array(B.date);if(A.tgt){A.tgt.value=A.selectedDates[0].dateFormat(this.cellObj.format);if(A.mode=="popup"){A.hide()}}}A.reDraw()}};CalCell.prototype.setClass=function(){if(this.selected){this.cellClass="cell_selected"}else{if(this.owner.displayMonth!=this.date.getMonth()){this.cellClass="notmnth"}else{if(this.date.getDay()>0&&this.date.getDay()<6){this.cellClass="wkday"}else{this.cellClass="wkend"}}}if(this.date.getFullYear()==this.owner.curDate.getFullYear()&&this.date.getMonth()==this.owner.curDate.getMonth()&&this.date.getDate()==this.owner.curDate.getDate()){this.cellClass=this.cellClass+" curdate"}this.tableCell.setAttribute("class",this.cellClass);this.tableCell.setAttribute("className",this.cellClass)};Date.prototype.getDayOfYear=function(){return parseInt((this.getTime()-new Date(this.getFullYear(),0,1).getTime())/86400000+1)};Date.prototype.getWeek=function(){return parseInt((this.getTime()-new Date(this.getFullYear(),0,1).getTime())/604800000+1)};Date.prototype.getUeDay=function(){return parseInt(Math.floor((this.getTime()-this.getTimezoneOffset()*60000)/86400000))};Date.prototype.dateFormat=function(e){if(!e){e="m/d/Y"}LZ=function(E){return(E<0||E>9?"":"0")+E};var J=new Array("January","February","March","April","May","June","July","August","September","October","November","December","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");var V=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sun","Mon","Tue","Wed","Thu","Fri","Sat");e=e+"";var L="";var U=0;var g="";var D="";var I=this.getFullYear().toString();var F=this.getMonth()+1;var f=this.getDate();var O=this.getDay();var N=this.getHours();var X=this.getMinutes();var Q=this.getSeconds();var S,T,B,R,i,C,b,a,Y,P,l,N,j,G,A,Z;var W=new Object();W["Y"]=I.toString();W["y"]=I.substring(2);W["n"]=F;W["m"]=LZ(F);W["F"]=J[F-1];W["M"]=J[F+11];W["j"]=f;W["d"]=LZ(f);W["D"]=V[O+7];W["l"]=V[O];W["G"]=N;W["H"]=LZ(N);if(N==0){W["g"]=12}else{if(N>12){W["g"]=N-12}else{W["g"]=N}}W["h"]=LZ(W["g"]);if(N>11){W["a"]="pm";W["A"]="PM"}else{W["a"]="am";W["A"]="AM"}W["i"]=LZ(X);W["s"]=LZ(Q);while(U<e.length){g=e.charAt(U);D="";while((e.charAt(U)==g)&&(U<e.length)){D+=e.charAt(U++)}if(W[D]!=null){L=L+W[D]}else{L=L+D}}return L};Array.prototype.arrayIndex=function(A,C){C=(C!=null?C:0);for(var B=C;B<this.length;B++){if(A==this[B]){return B}}return -1}