function DDCal(b,d,c,a){this.state=0;this.name=b;this.curDate=new Date();this.mode=d;this.selectMultiple=(a==true);this.selectedDates=new Array();this.calendar;this.calHeading;this.calCells;this.rows;this.cols;this.cells=new Array();this.altElms=Array();this.altElmsSki=new Array("drx","dax","dex","abx","dux","rax","bbx");this.formname=document.getElementById("calID").value;switch(this.formname){case"ski":this.altElms=this.altElmsSki;break;case"ski2":break;case"ski3":break;default:this.altElms=this.altElmsSki}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()}DDCal.prototype.calConfig=function(){this.displayYearInitial=this.curDate.getFullYear();if(this.curDate.getMonth()>2&&this.curDate.getMonth()<11){this.displayMonthInitial=11}else{this.displayMonthInitial=this.curDate.getMonth()}this.rangeYearLower=this.curDate.getFullYear();this.rangeYearUpper=this.curDate.getFullYear()+2;this.minDate=new Date(2005,0,1);this.maxDate=new Date(2037,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()};DDCal.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"};DDCal.prototype.getTop=function(c){var b=c;var a=0;a+=b.offsetTop;while(b=b.offsetParent){a+=b.offsetTop}return a};DDCal.prototype.getLeft=function(c){var b=c;var a=0;a+=b.offsetLeft;while(b=b.offsetParent){a+=b.offsetLeft}return a};DDCal.prototype.show=function(){this.calendar.style.display="block";this.visible=true;for(var a=0;a<this.altElms.length;a++){document.getElementById(this.altElms[a]).style.visibility="hidden"}};DDCal.prototype.hide=function(){this.calendar.style.display="none";this.visible=false;for(var a=0;a<this.altElms.length;a++){document.getElementById(this.altElms[a]).style.visibility="visible"}};DDCal.prototype.toggle=function(){if(this.visible){this.hide()}else{this.show()}};DDCal.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)};DDCal.prototype.setClass=function(a,b){a.setAttribute("class",b);a.setAttribute("className",b)};DDCal.prototype.createCalendar=function(){var c,a,b;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};c=document.createElement("tbody");a=document.createElement("tr");b=document.createElement("td");b.appendChild(this.createMainHeading());a.appendChild(b);c.appendChild(a);a=document.createElement("tr");b=document.createElement("td");b.appendChild(this.createDayHeading());a.appendChild(b);c.appendChild(a);a=document.createElement("tr");b=document.createElement("td");b.setAttribute("id",this.name+"_cell_td");this.calCellContainer=b;b.appendChild(this.createCalCells());a.appendChild(b);c.appendChild(a);a=document.createElement("tr");b=document.createElement("td");b.appendChild(this.createFooter());a.appendChild(b);c.appendChild(a);this.calendar.appendChild(c);this.calendar.owner=this;this.calendar.onmouseover=function(){this.owner.mousein=true};this.calendar.onmouseout=function(){this.owner.mousein=false}};DDCal.prototype.createMainHeading=function(){var b=document.createElement("div");b.setAttribute("id",this.name+"_mainheading");this.setClass(b,"mainheading");this.monthSelect=document.createElement("select");this.yearSelect=document.createElement("select");var a=document.createElement("input"),e=document.createElement("input");var d,c;for(c=0;c<12;c++){d=document.createElement("option");d.setAttribute("value",c);if(this.state==0&&this.displayMonth==c){d.setAttribute("selected","selected")}d.appendChild(document.createTextNode(this.months_sh[c]));this.monthSelect.appendChild(d)}for(c=this.rangeYearLower;c<=this.rangeYearUpper;c++){d=document.createElement("option");d.setAttribute("value",c);if(this.state==0&&this.displayYear==c){d.setAttribute("selected","selected")}d.appendChild(document.createTextNode(c));this.yearSelect.appendChild(d)}e.setAttribute("type","button");e.setAttribute("value",">");e.setAttribute("title",this.monthup_title);a.setAttribute("type","button");a.setAttribute("value","<");a.setAttribute("title",this.monthdn_title);this.monthSelect.owner=this.yearSelect.owner=e.owner=a.owner=this;e.onmouseup=function(){this.owner.nextMonth()};a.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)};b.appendChild(a);b.appendChild(this.monthSelect);b.appendChild(this.yearSelect);b.appendChild(e);return b};DDCal.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};DDCal.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()}};DDCal.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};DDCal.prototype.createCalCells=function(){this.rows=new Array(false,false,false,false,false,false);this.cells=new Array();var f=-1,j=(this.showWeeks?48:42);var k=new Date(this.displayYear,this.displayMonth,1);var c=new Date(this.displayYear,this.displayMonth,this.monthDayCount[this.displayMonth]);var g=new Date(k);g.setDate(g.getDate()+(this.startDay-k.getDay())-(this.startDay-k.getDay()>0?7:0));this.calCells=document.createElement("table");this.calCells.setAttribute("id",this.name+"_calcells");this.setClass(this.calCells,"calcells");var b,d,h;b=document.createElement("tbody");for(var a=0;a<j;a++){if(this.showWeeks){if(a%8==0){f++;d=document.createElement("tr");h=document.createElement("td");if(this.selectMultiple){h.weekObj=new WeekHeading(this,h,g.getWeek(),f)}else{h.setAttribute("class","wkhead");h.setAttribute("className","wkhead")}h.appendChild(document.createTextNode(g.getWeek()));d.appendChild(h);a++}}else{if(a%7==0){f++;d=document.createElement("tr")}}h=document.createElement("td");h.appendChild(document.createTextNode(g.getDate()));var e=new CalCell(this,h,g,f);this.cells.push(e);h.cellObj=e;g.setDate(g.getDate()+1);d.appendChild(h);b.appendChild(d)}this.calCells.appendChild(b);this.reDraw();return this.calCells};DDCal.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};DDCal.prototype.deleteCells=function(){this.calCellContainer.removeChild(this.calCellContainer.firstChild);this.cells=new Array()};DDCal.prototype.goToMonth=function(a,b){this.monthSelect.value=this.displayMonth=b;this.yearSelect.value=this.displayYear=a;this.deleteCells();this.calCellContainer.appendChild(this.createCalCells())};DDCal.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())};DDCal.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())};DDCal.prototype.addZero=function(a){return((a<10)?"0":"")+a};DDCal.prototype.addDates=function(e,a){var b,d;for(var c=0;c<e.length;c++){d=false;for(b=0;b<this.selectedDates.length;b++){if(e[c].getUeDay()==this.selectedDates[b].getUeDay()){d=true;break}}if(!d){this.selectedDates.push(e[c])}}if(a!=false){this.reDraw()}};DDCal.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()}};DDCal.prototype.outputDate=function(i,e){var f=this.addZero(i.getDate());var c=this.addZero(i.getMonth()+1);var g=this.addZero(i.getFullYear());var b=this.addZero(i.getFullYear().toString().substring(3,4));var d=(e.indexOf("yyyy")>-1?g:b);var a=this.addZero(i.getHours());var j=this.addZero(i.getMinutes());var h=this.addZero(i.getSeconds());return e.replace(/dd/g,f).replace(/mm/g,c).replace(/y{1,4}/g,d).replace(/hh/g,a).replace(/nn/g,j).replace(/ss/g,h)};DDCal.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(c,b,a){this.owner=c;this.tableCell=b;this.dayOfWeek=a;this.tableCell.onclick=this.onclick}CalHeading.prototype.onclick=function(){var b=this.headObj.owner;var a=b.selectedDates;var d=b.cells;b.cols[this.headObj.dayOfWeek]=!b.cols[this.headObj.dayOfWeek];for(var e=0;e<d.length;e++){if(d[e].dayOfWeek==this.headObj.dayOfWeek&&(!b.selCurMonthOnly||d[e].date.getMonth()==b.displayMonth&&d[e].date.getFullYear()==b.displayYear)){if(b.cols[this.headObj.dayOfWeek]){if(b.selectedDates.arrayIndex(d[e].date)==-1){a.push(d[e].date)}}else{for(var c=0;c<a.length;c++){if(d[e].dayOfWeek==a[c].getDay()){a.splice(c,1);break}}}d[e].selected=b.cols[this.headObj.dayOfWeek]}}b.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 b=this.weekObj.owner;var d=b.cells;var a=b.selectedDates;var e,c;b.rows[this.weekObj.tableRow]=!b.rows[this.weekObj.tableRow];for(e=0;e<d.length;e++){if(d[e].tableRow==this.weekObj.tableRow){if(b.rows[this.weekObj.tableRow]&&(!b.selCurMonthOnly||d[e].date.getMonth()==b.displayMonth&&d[e].date.getFullYear()==b.displayYear)){if(b.selectedDates.arrayIndex(d[e].date)==-1){a.push(d[e].date)}}else{for(c=0;c<a.length;c++){if(a[c].getTime()==d[e].date.getTime()){a.splice(c,1);break}}}}}b.reDraw()};function CalCell(a,d,b,c){this.owner=a;this.tableCell=d;this.cellClass;this.selected=false;this.date=new Date(b);this.dayOfWeek=this.date.getDay();this.week=this.date.getWeek();this.tableRow=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();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(p){if(!p){p="d M Y"}LZ=function(c){return(c<0||c>9?"":"0")+c};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 o=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sun","Mon","Tue","Wed","Thu","Fri","Sat");p=p+"";var B="";var r=0;var t="";var u="";var G=this.getFullYear().toString();var x=this.getMonth()+1;var v=this.getDate();var D=this.getDay();var C=this.getHours();var F=this.getMinutes();var N=this.getSeconds();var e,j,l,b,f,n,g,a,I,L,w,C,q,A,i,O;var z=new Object();z.Y=G.toString();z.y=G.substring(2);z.n=x;z.m=LZ(x);z.F=J[x-1];z.M=J[x+11];z.j=v;z.d=LZ(v);z.D=o[D+7];z.l=o[D];z.G=C;z.H=LZ(C);if(C==0){z.g=12}else{if(C>12){z.g=C-12}else{z.g=C}}z.h=LZ(z.g);if(C>11){z.a="pm";z.A="PM"}else{z.a="am";z.A="AM"}z.i=LZ(F);z.s=LZ(N);while(r<p.length){t=p.charAt(r);u="";while((p.charAt(r)==t)&&(r<p.length)){u+=p.charAt(r++)}if(z[u]!=null){B=B+z[u]}else{B=B+u}}return B};Array.prototype.arrayIndex=function(c,b){b=(b!=null?b:0);for(var a=b;a<this.length;a++){if(c==this[a]){return a}}return -1};
