function Epoch(name,mode,targetelement,multiselect,trigger)
{this.trigger=trigger
this.state=0;this.name=name;if(this.name=='dep_popup')
{this.curDate=new Date(20+document.getElementById("ddy").value,document.getElementById("ddm").value-1,document.getElementById("ddd").value);}
else
{this.curDate=new Date(20+document.getElementById("rdy").value,document.getElementById("rdm").value-1,document.getElementById("rdd").value);}
this.mode=mode;this.selectMultiple=(multiselect==true);this.selectedDates=new Array();this.calendar;this.calHeading;this.calCells;this.rows;this.cols;this.cells=new Array();this.monthSelect;this.yearSelect;this.calConfig();this.setDays();this.displayYear=this.displayYearInitial;this.displayMonth=this.displayMonthInitial;this.createCalendar();if(this.mode=='popup'&&targetelement&&targetelement.type=='hidden')
{this.tgt=targetelement;this.calendar.style.position='absolute';this.topOffset=this.tgt.offsetHeight;this.leftOffset=10;this.calendar.style.top=this.getTop(trigger)+this.topOffset+'px';this.calendar.style.left=this.getLeft(trigger)+this.leftOffset+'px';document.body.appendChild(this.calendar);this.trigger.calendar=this;this.trigger.onclick=function(){this.calendar.show();};}
else
{this.container=targetelement;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=2008;this.rangeYearUpper=2012;this.minDate=new Date();this.startDay=1;this.showWeeks=false;this.selCurMonthOnly=false;this.clearSelectedOnChange=false;switch(this.mode)
{case'popup':this.visible=false;break;case'flat':this.visible=true;break;}};Epoch.prototype.getTop=function(element)
{var oNode=element;var iTop=0;while(oNode.tagName!='BODY'){iTop+=oNode.offsetTop;oNode=oNode.offsetParent;}
return iTop;};Epoch.prototype.getLeft=function(element)
{var oNode=element;var iLeft=0;while(oNode.tagName!='BODY'){iLeft+=oNode.offsetLeft;oNode=oNode.offsetParent;}
return iLeft;};Epoch.prototype.show=function()
{if(this.name=='dep_popup')
{this.curDate=new Date(20+document.getElementById("ddy").value,document.getElementById("ddm").value-1,document.getElementById("ddd").value);}
else
{this.curDate=new Date(20+document.getElementById("rdy").value,document.getElementById("rdm").value-1,document.getElementById("rdd").value);}
this.selectedDates[0]=this.curDate;this.goToMonth(parseInt(this.curDate.getFullYear()),parseInt(this.curDate.getMonth()));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()
{var daylist=new Array('Su','Mo','Tu','We','Th','Fr','Sa','Su','Mo','Tu','We','Th','Fr','Sa');this.daynames=new Array();var j=0;for(var i=this.startDay;i<this.startDay+7;i++){this.daynames[j++]=daylist[i];}
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(element,className)
{element.setAttribute('class',className);element.setAttribute('className',className);};Epoch.prototype.createCalendar=function()
{var tbody,tr,td;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;};tbody=document.createElement('tbody');tr=document.createElement('tr');td=document.createElement('td');td.appendChild(this.createMainHeading());tr.appendChild(td);tbody.appendChild(tr);tr=document.createElement('tr');td=document.createElement('td');td.appendChild(this.createDayHeading());tr.appendChild(td);tbody.appendChild(tr);tr=document.createElement('tr');td=document.createElement('td');td.setAttribute('id',this.name+'_cell_td');this.calCellContainer=td;td.appendChild(this.createCalCells());tr.appendChild(td);tbody.appendChild(tr);tr=document.createElement('tr');td=document.createElement('td');td.appendChild(this.createFooter());tr.appendChild(td);tbody.appendChild(tr);this.calendar.appendChild(tbody);};Epoch.prototype.createMainHeading=function()
{var months=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');var container=document.createElement('div');container.setAttribute('id',this.name+'_mainheading');this.setClass(container,'mainheading');this.monthSelect=document.createElement('select');this.yearSelect=document.createElement('select');var monthDn=document.createElement('input'),monthUp=document.createElement('input');var opt,i;for(i=0;i<12;i++)
{opt=document.createElement('option');opt.setAttribute('value',i);if(this.state==0&&this.displayMonth==i){opt.setAttribute('selected','selected');}
opt.appendChild(document.createTextNode(months[i]));this.monthSelect.appendChild(opt);}
for(i=this.rangeYearLower;i<=this.rangeYearUpper;i++)
{opt=document.createElement('option');opt.setAttribute('value',i);if(this.state==0&&this.displayYear==i){opt.setAttribute('selected','selected');}
opt.appendChild(document.createTextNode(i));this.yearSelect.appendChild(opt);}
monthUp.setAttribute('type','button');monthUp.setAttribute('value','>');monthUp.setAttribute('title','Go to the next month');monthDn.setAttribute('type','button');monthDn.setAttribute('value','<');monthDn.setAttribute('title','Go to the previous month');this.monthSelect.owner=this.yearSelect.owner=monthUp.owner=monthDn.owner=this;monthUp.onmouseup=function(){this.owner.nextMonth();};monthDn.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);};container.appendChild(monthDn);container.appendChild(this.monthSelect);container.appendChild(this.yearSelect);container.appendChild(monthUp);return container;};Epoch.prototype.createFooter=function()
{var container=document.createElement('div');var clearSelected=document.createElement('input');clearSelected.setAttribute('type','button');clearSelected.setAttribute('value','Close');clearSelected.setAttribute('title','Clears any dates selected on the calendar');clearSelected.owner=this;clearSelected.onclick=function(){this.owner.resetSelections(false);};container.appendChild(clearSelected);return container;};Epoch.prototype.resetSelections=function(returnToDefaultMonth)
{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=null;if(this.mode=='popup'){this.hide();}}
if(returnToDefaultMonth==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 tbody,tr,td;tbody=document.createElement('tbody');tr=document.createElement('tr');this.cols=new Array(false,false,false,false,false,false,false);if(this.showWeeks)
{td=document.createElement('td');td.setAttribute('class','wkhead');td.setAttribute('className','wkhead');tr.appendChild(td);}
for(var dow=0;dow<7;dow++)
{td=document.createElement('td');td.appendChild(document.createTextNode(this.daynames[dow]));if(this.selectMultiple){td.headObj=new CalHeading(this,td,(dow+this.startDay<7?dow+this.startDay:dow+this.startDay-7));}
tr.appendChild(td);}
tbody.appendChild(tr);this.calHeading.appendChild(tbody);return this.calHeading;};Epoch.prototype.createCalCells=function()
{this.rows=new Array(false,false,false,false,false,false);this.cells=new Array();var row=-1,totalCells=(this.showWeeks?48:42);var beginDate=new Date(this.displayYear,this.displayMonth,1);var endDate=new Date(this.displayYear,this.displayMonth,this.monthDayCount[this.displayMonth]);var sdt=new Date(beginDate);sdt.setDate(sdt.getDate()+(this.startDay-beginDate.getDay())-(this.startDay-beginDate.getDay()>0?7:0));this.calCells=document.createElement('table');this.calCells.setAttribute('id',this.name+'_calcells');this.setClass(this.calCells,'calcells');var tbody,tr,td;tbody=document.createElement('tbody');for(var i=0;i<totalCells;i++)
{if(this.showWeeks)
{if(i%8==0)
{row++;tr=document.createElement('tr');td=document.createElement('td');if(this.selectMultiple){td.weekObj=new WeekHeading(this,td,sdt.getWeek(),row)}
else
{td.setAttribute('class','wkhead');td.setAttribute('className','wkhead');}
td.appendChild(document.createTextNode(sdt.getWeek()));tr.appendChild(td);i++;}}
else if(i%7==0)
{row++;tr=document.createElement('tr');}
td=document.createElement('td');td.appendChild(document.createTextNode(sdt.getDate()));var cell=new CalCell(this,td,sdt,row);this.cells.push(cell);td.cellObj=cell;sdt.setDate(sdt.getDate()+1);tr.appendChild(td);tbody.appendChild(tr);}
this.calCells.appendChild(tbody);this.reDraw();return this.calCells;};Epoch.prototype.reDraw=function()
{this.state=1;var i,j;for(i=0;i<this.cells.length;i++){this.cells[i].selected=false;}
for(i=0;i<this.cells.length;i++)
{for(j=0;j<this.selectedDates.length;j++){if(this.cells[i].date.getTime()==this.selectedDates[j].getTime()){this.cells[i].selected=true;}}
this.cells[i].setClass();}
this.state=2;};Epoch.prototype.deleteCells=function()
{this.calCellContainer.removeChild(this.calCellContainer.firstChild);this.cells=new Array();};Epoch.prototype.goToMonth=function(year,month)
{this.monthSelect.value=this.displayMonth=month;this.yearSelect.value=this.displayYear=year;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 is the maximum range');}}
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 is the maximum range');}}
this.displayMonth=this.monthSelect.value;this.displayYear=this.yearSelect.value;this.deleteCells();this.calCellContainer.appendChild(this.createCalCells());};Epoch.prototype.addZero=function(vNumber)
{return((parseInt(vNumber,10)<10)?'0':'')+vNumber;};Epoch.prototype.outputDate=function(vDate,vFormat)
{var vDay=this.addZero(vDate.getDate());var vMonth=this.addZero(vDate.getMonth()+1);var vYearLong=this.addZero(vDate.getFullYear());var vYearShort=this.addZero(vDate.getFullYear().toString().substring(3,4));var vYear=(vFormat.indexOf('yyyy')>-1?vYearLong:vYearShort);var vHour=this.addZero(vDate.getHours());var vMinute=this.addZero(vDate.getMinutes());var vSecond=this.addZero(vDate.getSeconds());var safeYear=this.addZero(parseInt(vYear,10)-2000);if(this.name=='dep_popup')
{document.getElementById("ddd").value=vDay;document.getElementById("ddm").value=vMonth;document.getElementById("ddy").value=safeYear;}
else
{document.getElementById("rdd").value=vDay;document.getElementById("rdm").value=vMonth;document.getElementById("rdy").value=safeYear;}
return vFormat.replace(/dd/g,vDay).replace(/mm/g,vMonth).replace(/y{1,4}/g,vYear).replace(/hh/g,vHour).replace(/nn/g,vMinute).replace(/ss/g,vSecond);};function CalHeading(owner,tableCell,dow)
{this.owner=owner;this.tableCell=tableCell;this.dayOfWeek=dow;this.tableCell.onclick=this.onclick;}
CalHeading.prototype.onclick=function()
{var owner=this.headObj.owner;var sdates=owner.selectedDates;var cells=owner.cells;owner.cols[this.headObj.dayOfWeek]=!owner.cols[this.headObj.dayOfWeek];for(var i=0;i<cells.length;i++)
{if(cells[i].dayOfWeek==this.headObj.dayOfWeek&&(!owner.selCurMonthOnly||cells[i].date.getMonth()==owner.displayMonth&&cells[i].date.getFullYear()==owner.displayYear))
{if(owner.cols[this.headObj.dayOfWeek])
{if(owner.selectedDates.arrayIndex(cells[i].date)==-1){sdates.push(cells[i].date);}}
else
{for(var j=0;j<sdates.length;j++)
{if(cells[i].dayOfWeek==sdates[j].getDay())
{sdates.splice(j,1);break;}}}
cells[i].selected=owner.cols[this.headObj.dayOfWeek];}}
owner.reDraw();};function WeekHeading(owner,tableCell,week,row)
{this.owner=owner;this.tableCell=tableCell;this.week=week;this.tableRow=row;this.tableCell.setAttribute('class','wkhead');this.tableCell.setAttribute('className','wkhead');this.tableCell.onclick=this.onclick;}
WeekHeading.prototype.onclick=function()
{var owner=this.weekObj.owner;var cells=owner.cells;var sdates=owner.selectedDates;var i,j;owner.rows[this.weekObj.tableRow]=!owner.rows[this.weekObj.tableRow];for(i=0;i<cells.length;i++)
{if(cells[i].tableRow==this.weekObj.tableRow)
{if(owner.rows[this.weekObj.tableRow]&&(!owner.selCurMonthOnly||cells[i].date.getMonth()==owner.displayMonth&&cells[i].date.getFullYear()==owner.displayYear))
{if(owner.selectedDates.arrayIndex(cells[i].date)==-1){sdates.push(cells[i].date);}}
else
{for(j=0;j<sdates.length;j++)
{if(sdates[j].getTime()==cells[i].date.getTime())
{sdates.splice(j,1);break;}}}}}
owner.reDraw();};function CalCell(owner,tableCell,dateObj,row)
{this.owner=owner;this.tableCell=tableCell;this.cellClass;this.selected=false;this.date=new Date(dateObj);this.dayOfWeek=this.date.getDay();this.week=this.date.getWeek();this.tableRow=row;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 cell=this.cellObj;var owner=cell.owner;if(!owner.selCurMonthOnly||cell.date.getMonth()==owner.displayMonth&&cell.date.getFullYear()==owner.displayYear)
{if(owner.selectMultiple==true)
{if(!cell.selected)
{if(owner.selectedDates.arrayIndex(cell.date)==-1){owner.selectedDates.push(cell.date);}}
else
{var tmp=owner.selectedDates;for(var i=0;i<tmp.length;i++)
{if(tmp[i].getTime()==cell.date.getTime()){tmp.splice(i,1);}}}}
else
{owner.selectedDates=new Array(cell.date);if(owner.tgt)
{owner.tgt.value=owner.outputDate(owner.selectedDates[0],'mm/dd/yyyy');if(owner.mode=='popup'){owner.hide();}}}
owner.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);};Array.prototype.arrayIndex=function(searchVal,startIndex)
{startIndex=(startIndex!=null?startIndex:0);for(var i=startIndex;i<this.length;i++)
{if(searchVal==this[i]){return i;}}
return-1;};