/*  Copyright Mihai Bazon, 2002-2005  |  www.bazon.net/mishoo
 * -----------------------------------------------------------
 *
 * The DHTML Calendar, version 1.0 "It is happening again"
 *
 * Details and latest version at:
 * www.dynarch.com/projects/calendar
 *
 * This script is developed by Dynarch.com.  Visit us at www.dynarch.com.
 *
 * This script is distributed under the GNU Lesser General Public License.
 * Read the entire license text here: http://www.gnu.org/licenses/lgpl.html
 */

// $Id: calendar.js 2786 2008-11-10 04:10:55Z sulin $
//////////////////////////////////////////////////////////
/**
 * DHTML Calendar 增强版(修改为在IE下在Select上方)
 * @author   xwk
 * @since    2008-10-20
 * @qq       56433593
 * @version  1.0.2
 * 使用方法有两种
 * 1.原始Setup方法,参照官网
 * 2.showCalendar('id',[format(%Y-%m-%d)])
 * */
Calendar=function(E,C,D,B){this.activeDiv=null;this.currentDateEl=null;this.getDateStatus=null;this.getDateToolTip=null;this.getDateText=null;this.timeout=null;this.onSelected=D||null;this.onClose=B||null;this.dragging=false;this.hidden=false;this.minYear=1970;this.maxYear=2050;this.dateFormat=Calendar._TT["DEF_DATE_FORMAT"];this.ttDateFormat=Calendar._TT["TT_DATE_FORMAT"];this.isPopup=true;this.weekNumbers=true;this.firstDayOfWeek=typeof E=="number"?E:Calendar._FD;this.showsOtherMonths=false;this.dateStr=C;this.ar_days=null;this.showsTime=false;this.time24=true;this.yearStep=2;this.hiliteToday=true;this.multiple=null;this.table=null;this.element=null;this.tbody=null;this.firstdayname=null;this.monthsCombo=null;this.yearsCombo=null;this.hilitedMonth=null;this.activeMonth=null;this.hilitedYear=null;this.activeYear=null;this.dateClicked=false;if(typeof Calendar._SDN=="undefined"){if(typeof Calendar._SDN_len=="undefined")Calendar._SDN_len=3;var A=new Array();for(var F=8;F>0;)A[--F]=Calendar._DN[F].substr(0,Calendar._SDN_len);Calendar._SDN=A;if(typeof Calendar._SMN_len=="undefined")Calendar._SMN_len=3;A=new Array();for(F=12;F>0;)A[--F]=Calendar._MN[F].substr(0,Calendar._SMN_len);Calendar._SMN=A}};Calendar._C=null;Calendar.is_ie=(/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent));Calendar.is_ie5=(Calendar.is_ie&&/msie 5\.0/i.test(navigator.userAgent));Calendar.is_opera=/opera/i.test(navigator.userAgent);Calendar.is_khtml=/Konqueror|Safari|KHTML/i.test(navigator.userAgent);Calendar.getAbsolutePos=function(B){var D=0,A=0,F=/^div$/i.test(B.tagName);if(F&&B.scrollLeft)D=B.scrollLeft;if(F&&B.scrollTop)A=B.scrollTop;var C={x:B.offsetLeft-D,y:B.offsetTop-A};if(B.offsetParent){var E=this.getAbsolutePos(B.offsetParent);C.x+=E.x;C.y+=E.y}return C};Calendar.isRelated=function(A,B){var D=B.relatedTarget;if(!D){var C=B.type;if(C=="mouseover")D=B.fromElement;else if(C=="mouseout")D=B.toElement}while(D){if(D==A)return true;D=D.parentNode}return false};Calendar.removeClass=function(B,D){if(!(B&&B.className))return;var A=B.className.split(" "),C=new Array();for(var E=A.length;E>0;)if(A[--E]!=D)C[C.length]=A[E];B.className=C.join(" ")};Calendar.addClass=function(A,B){Calendar.removeClass(A,B);A.className+=" "+B};Calendar.getElement=function(B){var A=Calendar.is_ie?window.event.srcElement:B.currentTarget;while(A.nodeType!=1||/^div$/i.test(A.tagName))A=A.parentNode;return A};Calendar.getTargetElement=function(B){var A=Calendar.is_ie?window.event.srcElement:B.target;while(A.nodeType!=1)A=A.parentNode;return A};Calendar.stopEvent=function(A){A||(A=window.event);if(Calendar.is_ie){A.cancelBubble=true;A.returnValue=false}else{A.preventDefault();A.stopPropagation()}return false};Calendar.addEvent=function(A,B,C){if(A.attachEvent)A.attachEvent("on"+B,C);else if(A.addEventListener)A.addEventListener(B,C,true);else A["on"+B]=C};Calendar.removeEvent=function(A,B,C){if(A.detachEvent)A.detachEvent("on"+B,C);else if(A.removeEventListener)A.removeEventListener(B,C,true);else A["on"+B]=null};Calendar.createElement=function(C,B){var A=null;if(document.createElementNS)A=document.createElementNS("http://www.w3.org/1999/xhtml",C);else A=document.createElement(C);if(typeof B!="undefined")B.appendChild(A);return A};Calendar._add_evs=function(el){with(Calendar){addEvent(el,"mouseover",dayMouseOver);addEvent(el,"mousedown",dayMouseDown);addEvent(el,"mouseout",dayMouseOut);if(is_ie){addEvent(el,"dblclick",dayMouseDblClick);el.setAttribute("unselectable",true)}}};Calendar.findMonth=function(A){if(typeof A.month!="undefined")return A;else if(typeof A.parentNode.month!="undefined")return A.parentNode;return null};Calendar.findYear=function(A){if(typeof A.year!="undefined")return A;else if(typeof A.parentNode.year!="undefined")return A.parentNode;return null};Calendar.showMonthsCombo=function(){var E=Calendar._C;if(!E)return false;var E=E,F=E.activeDiv,B=E.monthsCombo;if(E.hilitedMonth)Calendar.removeClass(E.hilitedMonth,"hilite");if(E.activeMonth)Calendar.removeClass(E.activeMonth,"active");var C=E.monthsCombo.getElementsByTagName("div")[E.date.getMonth()];Calendar.addClass(C,"active");E.activeMonth=C;var A=B.style;A.display="block";if(F.navtype<0)A.left=F.offsetLeft+"px";else{var D=B.offsetWidth;if(typeof D=="undefined")D=50;A.left=(F.offsetLeft+F.offsetWidth-D)+"px"}A.top=(F.offsetTop+F.offsetHeight)+"px";E.updateIFRAME(B)};Calendar.showYearsCombo=function(E){var F=Calendar._C;if(!F)return false;var F=F,J=F.activeDiv,B=F.yearsCombo;if(F.hilitedYear)Calendar.removeClass(F.hilitedYear,"hilite");if(F.activeYear)Calendar.removeClass(F.activeYear,"active");F.activeYear=null;var G=F.date.getFullYear()+(E?1:-1),C=B.firstChild,D=false;for(var I=12;I>0;--I){if(G>=F.minYear&&G<=F.maxYear){C.innerHTML=G;C.year=G;C.style.display="block";D=true}else C.style.display="none";C=C.nextSibling;G+=E?F.yearStep:-F.yearStep}if(D){var A=B.style;A.display="block";if(J.navtype<0)A.left=J.offsetLeft+"px";else{var H=B.offsetWidth;if(typeof H=="undefined")H=50;A.left=(J.offsetLeft+J.offsetWidth-H)+"px"}A.top=(J.offsetTop+J.offsetHeight)+"px"}F.updateIFRAME(B)};Calendar.tableMouseUp=function(ev){var cal=Calendar._C;if(!cal)return false;if(cal.timeout)clearTimeout(cal.timeout);var A=cal.activeDiv;if(!A)return false;var B=Calendar.getTargetElement(ev);ev||(ev=window.event);Calendar.removeClass(A,"active");if(B==A||B.parentNode==A)Calendar.cellClick(A,ev);var C=Calendar.findMonth(B),E=null;if(C){E=new Date(cal.date);if(C.month!=E.getMonth()){E.setMonth(C.month);cal.setDate(E);cal.dateClicked=false;cal.callHandler()}}else{var D=Calendar.findYear(B);if(D){E=new Date(cal.date);if(D.year!=E.getFullYear()){E.setFullYear(D.year);cal.setDate(E);cal.dateClicked=false;cal.callHandler()}}}with(Calendar){removeEvent(document,"mouseup",tableMouseUp);removeEvent(document,"mouseover",tableMouseOver);removeEvent(document,"mousemove",tableMouseOver);cal._hideCombos();_C=null;return stopEvent(ev)}};Calendar.tableMouseOver=function(A){var N=Calendar._C;if(!N)return;var J=N.activeDiv,K=Calendar.getTargetElement(A);if(K==J||K.parentNode==J){Calendar.addClass(J,"hilite active");Calendar.addClass(J.parentNode,"rowhilite")}else{if(typeof J.navtype=="undefined"||(J.navtype!=50&&(J.navtype==0||Math.abs(J.navtype)>2)))Calendar.removeClass(J,"active");Calendar.removeClass(J,"hilite");Calendar.removeClass(J.parentNode,"rowhilite")}A||(A=window.event);if(J.navtype==50&&K!=J){var G=Calendar.getAbsolutePos(J),H=J.offsetWidth,P=A.clientX,B,O=true;if(P>G.x+H){B=P-G.x-H;O=false}else B=G.x-P;if(B<0)B=0;var C=J._range,L=J._current,D=Math.floor(B/10)%C.length;for(var F=C.length;--F>=0;)if(C[F]==L)break;while(D-->0)if(O){if(--F<0)F=C.length-1}else if(++F>=C.length)F=0;var I=C[F];J.innerHTML=I;N.onUpdateTime()}var E=Calendar.findMonth(K);if(E){if(E.month!=N.date.getMonth()){if(N.hilitedMonth)Calendar.removeClass(N.hilitedMonth,"hilite");Calendar.addClass(E,"hilite");N.hilitedMonth=E}else if(N.hilitedMonth)Calendar.removeClass(N.hilitedMonth,"hilite")}else{if(N.hilitedMonth)Calendar.removeClass(N.hilitedMonth,"hilite");var M=Calendar.findYear(K);if(M){if(M.year!=N.date.getFullYear()){if(N.hilitedYear)Calendar.removeClass(N.hilitedYear,"hilite");Calendar.addClass(M,"hilite");N.hilitedYear=M}else if(N.hilitedYear)Calendar.removeClass(N.hilitedYear,"hilite")}else if(N.hilitedYear)Calendar.removeClass(N.hilitedYear,"hilite")}return Calendar.stopEvent(A)};Calendar.tableMouseDown=function(A){if(Calendar.getTargetElement(A)==Calendar.getElement(A))return Calendar.stopEvent(A)};Calendar.calDragIt=function(A){var E=Calendar._C;if(!(E&&E.dragging))return false;var C,B;if(Calendar.is_ie){B=window.event.clientY+document.body.scrollTop;C=window.event.clientX+document.body.scrollLeft}else{C=A.pageX;B=A.pageY}E.hideShowCovered();var D=E.element.style;D.left=(C-E.xOffs)+"px";D.top=(B-E.yOffs)+"px";Calendar.setupIFRAME(E.IFRAME,(C-E.xOffs),(B-E.yOffs));return Calendar.stopEvent(A)};Calendar.calDragEnd=function(ev){var A=Calendar._C;if(!A)return false;A.dragging=false;with(Calendar){removeEvent(document,"mousemove",calDragIt);removeEvent(document,"mouseup",calDragEnd);tableMouseUp(ev)}A.hideShowCovered()};Calendar.dayMouseDown=function(A){var el=Calendar.getElement(A);if(el.disabled)return false;var B=el.calendar;B.activeDiv=el;Calendar._C=B;if(el.navtype!=300)with(Calendar){if(el.navtype==50){el._current=el.innerHTML;addEvent(document,"mousemove",tableMouseOver)}else addEvent(document,Calendar.is_ie5?"mousemove":"mouseover",tableMouseOver);addClass(el,"hilite active");addEvent(document,"mouseup",tableMouseUp)}else if(B.isPopup)B._dragStart(A);if(el.navtype==-1||el.navtype==1){if(B.timeout)clearTimeout(B.timeout);B.timeout=setTimeout("Calendar.showMonthsCombo()",250)}else if(el.navtype==-2||el.navtype==2){if(B.timeout)clearTimeout(B.timeout);B.timeout=setTimeout((el.navtype>0)?"Calendar.showYearsCombo(true)":"Calendar.showYearsCombo(false)",250)}else B.timeout=null;return Calendar.stopEvent(A)};Calendar.dayMouseDblClick=function(A){Calendar.cellClick(Calendar.getElement(A),A||window.event);if(Calendar.is_ie)document.selection.empty()};Calendar.dayMouseOver=function(A){var B=Calendar.getElement(A);if(Calendar.isRelated(B,A)||Calendar._C||B.disabled)return false;if(B.ttip){if(B.ttip.substr(0,1)=="_")B.ttip=B.caldate.print(B.calendar.ttDateFormat)+B.ttip.substr(1);B.calendar.tooltips.innerHTML=B.ttip}if(B.navtype!=300){Calendar.addClass(B,"hilite");if(B.caldate)Calendar.addClass(B.parentNode,"rowhilite")}return Calendar.stopEvent(A)};Calendar.dayMouseOut=function(ev){with(Calendar){var el=getElement(ev);if(isRelated(el,ev)||_C||el.disabled)return false;removeClass(el,"hilite");if(el.caldate)removeClass(el.parentNode,"rowhilite");if(el.calendar)el.calendar.tooltips.innerHTML=_TT["SEL_DATE"];return stopEvent(ev)}};Calendar.cellClick=function(I,A){var L=I.calendar,N=false,C=false,E=null;if(typeof I.navtype=="undefined"){if(L.currentDateEl){Calendar.removeClass(L.currentDateEl,"selected");Calendar.addClass(I,"selected");N=(L.currentDateEl==I);if(!N)L.currentDateEl=I}L.date.setDateOnly(I.caldate);E=L.date;var M=!(L.dateClicked=!I.otherMonth);if(!M&&!L.currentDateEl)L._toggleMultipleDate(new Date(E));else C=!I.disabled;if(M)L._init(L.firstDayOfWeek,E)}else{if(I.navtype==200){Calendar.removeClass(I,"hilite");L.callCloseHandler();return}E=new Date(L.date);if(I.navtype==0)E.setDateOnly(new Date());L.dateClicked=false;var K=E.getFullYear(),D=E.getMonth();function F(C){var B=E.getDate(),A=E.getMonthDays(C);if(B>A)E.setDate(A);E.setMonth(C)}switch(I.navtype){case 400:Calendar.removeClass(I,"hilite");L.params.inputField.value="";return;case-2:if(K>L.minYear)E.setFullYear(K-1);break;case-1:if(D>0)F(D-1);else if(K-->L.minYear){E.setFullYear(K);F(11)}break;case 1:if(D<11)F(D+1);else if(K<L.maxYear){E.setFullYear(K+1);F(0)}break;case 2:if(K<L.maxYear)E.setFullYear(K+1);break;case 100:L.setFirstDayOfWeek(I.fdow);return;case 50:var B=I._range,J=I.innerHTML;for(var G=B.length;--G>=0;)if(B[G]==J)break;if(A&&A.shiftKey){if(--G<0)G=B.length-1}else if(++G>=B.length)G=0;var H=B[G];I.innerHTML=H;L.onUpdateTime();return;case 0:if((typeof L.getDateStatus=="function")&&L.getDateStatus(E,E.getFullYear(),E.getMonth(),E.getDate()))return false;break}if(!E.equalsTo(L.date)){L.setDate(E);C=true}else if(I.navtype==0)C=N=true}if(C)A&&L.callHandler();if(N){Calendar.removeClass(I,"hilite");A&&L.callCloseHandler()}};Calendar.prototype.create=function(C){var F=null;if(!C){F=document.getElementsByTagName("body")[0];this.isPopup=true;this.IFRAME=Calendar.createIFRAME()}else{F=C;this.isPopup=false}this.date=this.dateStr?new Date(this.dateStr):new Date();var H=Calendar.createElement("table");this.table=H;H.cellSpacing=0;H.cellPadding=0;H.calendar=this;Calendar.addEvent(H,"mousedown",Calendar.tableMouseDown);var E=Calendar.createElement("div");this.element=E;E.className="calendar";if(this.isPopup){E.style.position="absolute";E.style.display="none"}E.appendChild(H);var B=Calendar.createElement("thead",H),D=null,K=null,P=this,G=function(A,C,B){D=Calendar.createElement("td",K);D.colSpan=C;D.className="button";if(B!=0&&Math.abs(B)<=2)D.className+=" navnav";Calendar._add_evs(D);D.calendar=P;D.navtype=B;D.innerHTML="<div unselectable='on'>"+A+"</div>";return D};K=Calendar.createElement("tr",B);var O=6;(this.isPopup)&&--O;(this.weekNumbers)&&++O;G("-",1,400).ttip=Calendar._TT["INFO"];this.title=G("",O,300);this.title.className="title";if(this.isPopup){this.title.ttip=Calendar._TT["DRAG_TO_MOVE"];this.title.style.cursor="move";G("&#x00d7;",1,200).ttip=Calendar._TT["CLOSE"]}K=Calendar.createElement("tr",B);K.className="headrow";this._nav_py=G("&#x00ab;",1,-2);this._nav_py.ttip=Calendar._TT["PREV_YEAR"];this._nav_pm=G("&#x2039;",1,-1);this._nav_pm.ttip=Calendar._TT["PREV_MONTH"];this._nav_now=G(Calendar._TT["TODAY"],this.weekNumbers?4:3,0);this._nav_now.ttip=Calendar._TT["GO_TODAY"];this._nav_nm=G("&#x203a;",1,1);this._nav_nm.ttip=Calendar._TT["NEXT_MONTH"];this._nav_ny=G("&#x00bb;",1,2);this._nav_ny.ttip=Calendar._TT["NEXT_YEAR"];K=Calendar.createElement("tr",B);K.className="daynames";if(this.weekNumbers){D=Calendar.createElement("td",K);D.className="name wn";D.innerHTML=Calendar._TT["WK"]}for(var L=7;L>0;--L){D=Calendar.createElement("td",K);if(!L){D.navtype=100;D.calendar=this;Calendar._add_evs(D)}}this.firstdayname=(this.weekNumbers)?K.firstChild.nextSibling:K.firstChild;this._displayWeekdays();var M=Calendar.createElement("tbody",H);this.tbody=M;for(L=6;L>0;--L){K=Calendar.createElement("tr",M);if(this.weekNumbers)D=Calendar.createElement("td",K);for(var I=7;I>0;--I){D=Calendar.createElement("td",K);D.calendar=this;Calendar._add_evs(D)}}if(this.showsTime){K=Calendar.createElement("tr",M);K.className="time";D=Calendar.createElement("td",K);D.className="time";D.colSpan=2;D.innerHTML=Calendar._TT["TIME"]||"&nbsp;";D=Calendar.createElement("td",K);D.className="time";D.colSpan=this.weekNumbers?4:3;(function(){function F(C,B,F,A){var E=Calendar.createElement("span",D);E.className=C;E.innerHTML=B;E.calendar=P;E.ttip=Calendar._TT["TIME_PART"];E.navtype=50;E._range=[];if(typeof F!="number")E._range=F;else for(var H=F;H<=A;++H){var G;if(H<10&&A>=10)G="0"+H;else G=""+H;E._range[E._range.length]=G}Calendar._add_evs(E);return E}var A=P.date.getHours(),G=P.date.getMinutes(),B=!P.time24,E=(A>12);if(B&&E)A-=12;var H=F("hour",A,B?1:0,B?12:23),J=Calendar.createElement("span",D);J.innerHTML=":";J.className="colon";var C=F("minute",G,0,59),I=null;D=Calendar.createElement("td",K);D.className="time";D.colSpan=2;if(B)I=F("ampm",E?"pm":"am",["am","pm"]);else D.innerHTML="&nbsp;";P.onSetTime=function(){var D,A=this.date.getHours(),E=this.date.getMinutes();if(B){D=(A>=12);if(D)A-=12;if(A==0)A=12;I.innerHTML=D?"pm":"am"}H.innerHTML=(A<10)?("0"+A):A;C.innerHTML=(E<10)?("0"+E):E};P.onUpdateTime=function(){var E=this.date,G=parseInt(H.innerHTML,10);if(B)if(/pm/i.test(I.innerHTML)&&G<12)G+=12;else if(/am/i.test(I.innerHTML)&&G==12)G=0;var A=E.getDate(),D=E.getMonth(),F=E.getFullYear();E.setHours(G);E.setMinutes(parseInt(C.innerHTML,10));E.setFullYear(F);E.setMonth(D);E.setDate(A);this.dateClicked=false;this.callHandler()}})()}else this.onSetTime=this.onUpdateTime=function(){};var J=Calendar.createElement("tfoot",H);K=Calendar.createElement("tr",J);K.className="footrow";D=G(Calendar._TT["SEL_DATE"],this.weekNumbers?8:7,300);D.className="ttip";if(this.isPopup){D.ttip=Calendar._TT["DRAG_TO_MOVE"];D.style.cursor="move"}this.tooltips=D;E=Calendar.createElement("div",this.element);this.monthsCombo=E;E.className="combo";for(L=0;L<Calendar._MN.length;++L){var A=Calendar.createElement("div");A.className=Calendar.is_ie?"label-IEfix":"label";A.month=L;A.innerHTML=Calendar._SMN[L];E.appendChild(A)}E=Calendar.createElement("div",this.element);this.yearsCombo=E;E.className="combo";for(L=12;L>0;--L){var N=Calendar.createElement("div");N.className=Calendar.is_ie?"label-IEfix":"label";E.appendChild(N)}this._init(this.firstDayOfWeek,this.date);F.appendChild(this.element)};Calendar._keyEvent=function(A){var H=window._dynarch_popupCalendar;if(!H||H.multiple)return false;(Calendar.is_ie)&&(A=window.event);var I=(Calendar.is_ie||A.type=="keypress"),D=A.keyCode;if(A.ctrlKey)switch(D){case 37:I&&Calendar.cellClick(H._nav_pm);break;case 38:I&&Calendar.cellClick(H._nav_py);break;case 39:I&&Calendar.cellClick(H._nav_nm);break;case 40:I&&Calendar.cellClick(H._nav_ny);break;default:return false}else switch(D){case 32:Calendar.cellClick(H._nav_now);break;case 27:I&&H.callCloseHandler();break;case 37:case 38:case 39:case 40:if(I){var E,M,K,G,F,L;E=D==37||D==38;L=(D==37||D==39)?1:7;function J(){F=H.currentDateEl;var A=F.pos;M=A&15;K=A>>4;G=H.ar_days[K][M]}J();function C(){var A=new Date(H.date);A.setDate(A.getDate()-L);H.setDate(A)}function B(){var A=new Date(H.date);A.setDate(A.getDate()+L);H.setDate(A)}while(1){switch(D){case 37:if(--M>=0)G=H.ar_days[K][M];else{M=6;D=38;continue}break;case 38:if(--K>=0)G=H.ar_days[K][M];else{C();J()}break;case 39:if(++M<7)G=H.ar_days[K][M];else{M=0;D=40;continue}break;case 40:if(++K<H.ar_days.length)G=H.ar_days[K][M];else{B();J()}break}break}if(G)if(!G.disabled)Calendar.cellClick(G);else if(E)C();else B()}break;case 13:if(I)Calendar.cellClick(H.currentDateEl,A);break;default:return false}return Calendar.stopEvent(A)};Calendar.prototype._init=function(L,F){var C=new Date(),Z=C.getFullYear(),D=C.getMonth(),A=C.getDate();this.table.style.visibility="hidden";var J=F.getFullYear();if(J<this.minYear){J=this.minYear;F.setFullYear(J)}else if(J>this.maxYear){J=this.maxYear;F.setFullYear(J)}this.firstDayOfWeek=L;this.date=new Date(F);var Y=F.getMonth(),R=F.getDate(),E=F.getMonthDays();F.setDate(1);var X=(F.getDay()-this.firstDayOfWeek)%7;if(X<0)X+=7;F.setDate(-X);F.setDate(F.getDate()+1);var V=this.tbody.firstChild,S=Calendar._SMN[Y],N=this.ar_days=new Array(),I=Calendar._TT["WEEKEND"],H=this.multiple?(this.datesCells={}):null;for(var W=0;W<6;++W,V=V.nextSibling){var Q=V.firstChild;if(this.weekNumbers){Q.className="day wn";Q.innerHTML=F.getWeekNumber();Q=Q.nextSibling}V.className="daysrow";var T=false,M,G=N[W]=[];for(var U=0;U<7;++U,Q=Q.nextSibling,F.setDate(M+1)){M=F.getDate();var B=F.getDay();Q.className="day";Q.pos=W<<4|U;G[U]=Q;var K=(F.getMonth()==Y);if(!K){if(this.showsOtherMonths){Q.className+=" othermonth";Q.otherMonth=true}else{Q.className="emptycell";Q.innerHTML="&nbsp;";Q.disabled=true;continue}}else{Q.otherMonth=false;T=true}Q.disabled=false;Q.innerHTML=this.getDateText?this.getDateText(F,M):M;if(H)H[F.print("%Y%m%d")]=Q;if(this.getDateStatus){var O=this.getDateStatus(F,J,Y,M);if(this.getDateToolTip){var P=this.getDateToolTip(F,J,Y,M);if(P)Q.title=P}if(O===true){Q.className+=" disabled";Q.disabled=true}else{if(/disabled/i.test(O))Q.disabled=true;Q.className+=" "+O}}if(!Q.disabled){Q.caldate=new Date(F);Q.ttip="_";if(!this.multiple&&K&&M==R&&this.hiliteToday){Q.className+=" selected";this.currentDateEl=Q}if(F.getFullYear()==Z&&F.getMonth()==D&&M==A){Q.className+=" today";Q.ttip+=Calendar._TT["PART_TODAY"]}if(I.indexOf(B.toString())!=-1)Q.className+=Q.otherMonth?" oweekend":" weekend"}}if(!(T||this.showsOtherMonths))V.className="emptyrow"}this.title.innerHTML=Calendar._MN[Y]+", "+J;this.onSetTime();this.table.style.visibility="visible";this._initMultipleDates();this.updateIFRAME()};Calendar.prototype._initMultipleDates=function(){if(this.multiple)for(var C in this.multiple){var B=this.datesCells[C],A=this.multiple[C];if(!A)continue;if(B)B.className+=" selected"}};Calendar.prototype._toggleMultipleDate=function(C){if(this.multiple){var D=C.print("%Y%m%d"),B=this.datesCells[D];if(B){var A=this.multiple[D];if(!A){Calendar.addClass(B,"selected");this.multiple[D]=C}else{Calendar.removeClass(B,"selected");delete this.multiple[D]}}}};Calendar.prototype.setDateToolTipHandler=function(A){this.getDateToolTip=A};Calendar.prototype.setDate=function(A){if(!A.equalsTo(this.date))this._init(this.firstDayOfWeek,A)};Calendar.prototype.refresh=function(){this._init(this.firstDayOfWeek,this.date)};Calendar.prototype.setFirstDayOfWeek=function(A){this._init(A,this.date);this._displayWeekdays()};Calendar.prototype.setDateStatusHandler=Calendar.prototype.setDisabledHandler=function(A){this.getDateStatus=A};Calendar.prototype.setRange=function(A,B){this.minYear=A;this.maxYear=B};Calendar.prototype.callHandler=function(){if(this.onSelected)this.onSelected(this,this.date.print(this.dateFormat))};Calendar.prototype.callCloseHandler=function(){if(this.onClose)this.onClose(this);this.hideShowCovered()};Calendar.prototype.destroy=function(){var A=this.element.parentNode;A.removeChild(this.element);Calendar._C=null;window._dynarch_popupCalendar=null};Calendar.prototype.reparent=function(B){var A=this.element;A.parentNode.removeChild(A);B.appendChild(A)};Calendar._checkCalendar=function(A){var C=window._dynarch_popupCalendar;if(!C)return false;var B=Calendar.is_ie?Calendar.getElement(A):Calendar.getTargetElement(A);for(;B!=null&&B!=C.element;B=B.parentNode);if(B==null){window._dynarch_popupCalendar.callCloseHandler();return Calendar.stopEvent(A)}};Calendar.prototype.show=function(){var F=this.table.getElementsByTagName("tr");for(var E=F.length;E>0;){var D=F[--E];Calendar.removeClass(D,"rowhilite");var A=D.getElementsByTagName("td");for(var C=A.length;C>0;){var B=A[--C];Calendar.removeClass(B,"hilite");Calendar.removeClass(B,"active")}}this.element.style.display="block";this.hidden=false;if(this.isPopup){this.updateIFRAME();window._dynarch_popupCalendar=this;Calendar.addEvent(document,"keydown",Calendar._keyEvent);Calendar.addEvent(document,"keypress",Calendar._keyEvent);Calendar.addEvent(document,"mousedown",Calendar._checkCalendar)}this.hideShowCovered()};Calendar.prototype.hide=function(){if(this.isPopup){Calendar.removeEvent(document,"keydown",Calendar._keyEvent);Calendar.removeEvent(document,"keypress",Calendar._keyEvent);Calendar.removeEvent(document,"mousedown",Calendar._checkCalendar)}this.element.style.display="none";Calendar.hideIFRAME(this.IFRAME);this.hidden=true;this.hideShowCovered()};Calendar.prototype.showAt=function(C,B){var A=this.element.style;A.left=C+"px";A.top=B+"px";this.show()};Calendar.prototype.showAtElement=function(B,A){var E=this,C=Calendar.getAbsolutePos(B);if(!A||typeof A!="string"){this.showAt(C.x,C.y+B.offsetHeight);return true}function D(D){if(D.x<0)D.x=0;if(D.y<0)D.y=0;var A=document.createElement("div"),B=A.style;B.position="absolute";B.right=B.bottom=B.width=B.height="0px";document.body.appendChild(A);var E=Calendar.getAbsolutePos(A);document.body.removeChild(A);if(Calendar.is_ie){E.y+=document.body.scrollTop;E.x+=document.body.scrollLeft}else{E.y+=window.scrollY;E.x+=window.scrollX}var C=D.x+D.width-E.x;if(C>0)D.x-=C;C=D.y+D.height-E.y;if(C>0)D.y-=C}this.element.style.display="block";Calendar.continuation_for_the_fucking_khtml_browser=function(){var D=E.element.offsetWidth,H=E.element.offsetHeight;E.element.style.display="none";var G=A.substr(0,1),F="l";if(A.length>1)F=A.substr(1,1);switch(G){case"T":C.y-=H;break;case"B":C.y+=B.offsetHeight;break;case"C":C.y+=(B.offsetHeight-H)/2;break;case"t":C.y+=B.offsetHeight-H;break;case"b":break}switch(F){case"L":C.x-=D;break;case"R":C.x+=B.offsetWidth;break;case"C":C.x+=(B.offsetWidth-D)/2;break;case"l":C.x+=B.offsetWidth-D;break;case"r":break}C.width=D;C.height=H+40;E.monthsCombo.style.display="none";E.showAt(C.x,C.y)};if(Calendar.is_khtml)setTimeout("Calendar.continuation_for_the_fucking_khtml_browser()",10);else Calendar.continuation_for_the_fucking_khtml_browser()};Calendar.prototype.setDateFormat=function(A){this.dateFormat=A};Calendar.prototype.setTtDateFormat=function(A){this.ttDateFormat=A};Calendar.prototype.parseDate=function(A,B){if(!B)B=this.dateFormat;this.setDate(Date.parseDate(A,B))};Calendar.prototype.hideShowCovered=function(){if(!Calendar.is_ie5)return;function F(B){var A=B.style.visibility;if(!A)if(document.defaultView&&typeof(document.defaultView.getComputedStyle)=="function"){if(!Calendar.is_khtml)A=document.defaultView.getComputedStyle(B,"").getPropertyValue("visibility");else A=""}else if(B.currentStyle)A=B.currentStyle.visibility;else A="";return A}var A=new Array("applet","iframe","select"),N=this.element,O=Calendar.getAbsolutePos(N),I=O.x,G=N.offsetWidth+I,H=O.y,K=N.offsetHeight+H;for(var L=A.length;L>0;){var J=document.getElementsByTagName(A[--L]),P=null;for(var M=J.length;M>0;){P=J[--M];O=Calendar.getAbsolutePos(P);var C=O.x,D=P.offsetWidth+C,B=O.y,E=P.offsetHeight+B;if(this.hidden||(C>G)||(D<I)||(B>K)||(E<H)){if(!P.__msh_save_visibility)P.__msh_save_visibility=F(P);P.style.visibility=P.__msh_save_visibility}else{if(!P.__msh_save_visibility)P.__msh_save_visibility=F(P);P.style.visibility="hidden"}}}};Calendar.prototype._displayWeekdays=function(){var A=this.firstDayOfWeek,B=this.firstdayname,D=Calendar._TT["WEEKEND"];for(var E=0;E<7;++E){B.className="day name";var C=(E+A)%7;if(E){B.ttip=Calendar._TT["DAY_FIRST"].replace("%s",Calendar._DN[C]);B.navtype=100;B.calendar=this;B.fdow=C;Calendar._add_evs(B)}if(D.indexOf(C.toString())!=-1)Calendar.addClass(B,"weekend");B.innerHTML=Calendar._SDN[(E+A)%7];B=B.nextSibling}};Calendar.prototype._hideCombos=function(){this.monthsCombo.style.display="none";this.yearsCombo.style.display="none";this.updateIFRAME()};Calendar.prototype._dragStart=function(A){if(this.dragging)return;this.dragging=true;var C,B;if(Calendar.is_ie){B=window.event.clientY+document.body.scrollTop;C=window.event.clientX+document.body.scrollLeft}else{B=A.clientY+window.scrollY;C=A.clientX+window.scrollX}var D=this.element.style;this.xOffs=C-parseInt(D.left);this.yOffs=B-parseInt(D.top);with(Calendar){addEvent(document,"mousemove",calDragIt);addEvent(document,"mouseup",calDragEnd)}};Date._MD=new Array(31,28,31,30,31,30,31,31,30,31,30,31);Date.SECOND=1000;Date.MINUTE=60*Date.SECOND;Date.HOUR=60*Date.MINUTE;Date.DAY=24*Date.HOUR;Date.WEEK=7*Date.DAY;Date.parseDate=function(L,E){var G=new Date(),M=0,H=-1,C=0,F=L.split(/\W+/),D=E.match(/%./g),J=0,I=0,A=0,B=0;for(J=0;J<F.length;++J){if(!F[J])continue;switch(D[J]){case"%d":case"%e":C=parseInt(F[J],10);break;case"%m":H=parseInt(F[J],10)-1;break;case"%Y":case"%y":M=parseInt(F[J],10);(M<100)&&(M+=(M>29)?1900:2000);break;case"%b":case"%B":for(I=0;I<12;++I)if(Calendar._MN[I].substr(0,F[J].length).toLowerCase()==F[J].toLowerCase()){H=I;break}break;case"%H":case"%I":case"%k":case"%l":A=parseInt(F[J],10);break;case"%P":case"%p":if(/pm/i.test(F[J])&&A<12)A+=12;else if(/am/i.test(F[J])&&A>=12)A-=12;break;case"%M":B=parseInt(F[J],10);break}}if(isNaN(M))M=G.getFullYear();if(isNaN(H))H=G.getMonth();if(isNaN(C))C=G.getDate();if(isNaN(A))A=G.getHours();if(isNaN(B))B=G.getMinutes();if(M!=0&&H!=-1&&C!=0)return new Date(M,H,C,A,B,0);M=0;H=-1;C=0;for(J=0;J<F.length;++J)if(F[J].search(/[a-zA-Z]+/)!=-1){var K=-1;for(I=0;I<12;++I)if(Calendar._MN[I].substr(0,F[J].length).toLowerCase()==F[J].toLowerCase()){K=I;break}if(K!=-1){if(H!=-1)C=H+1;H=K}}else if(parseInt(F[J],10)<=12&&H==-1)H=F[J]-1;else if(parseInt(F[J],10)>31&&M==0){M=parseInt(F[J],10);(M<100)&&(M+=(M>29)?1900:2000)}else if(C==0)C=F[J];if(M==0)M=G.getFullYear();if(H!=-1&&C!=0)return new Date(M,H,C,A,B,0);return G};Date.prototype.getMonthDays=function(A){var B=this.getFullYear();if(typeof A=="undefined")A=this.getMonth();if(((0==(B%4))&&((0!=(B%100))||(0==(B%400))))&&A==1)return 29;else return Date._MD[A]};Date.prototype.getDayOfYear=function(){var B=new Date(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0),C=new Date(this.getFullYear(),0,0,0,0,0),A=B-C;return Math.floor(A/Date.DAY)};Date.prototype.getWeekNumber=function(){var A=new Date(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0),C=A.getDay();A.setDate(A.getDate()-(C+6)%7+3);var B=A.valueOf();A.setMonth(0);A.setDate(4);return Math.round((B-A.valueOf())/(7*86400000))+1};Date.prototype.equalsTo=function(A){return((this.getFullYear()==A.getFullYear())&&(this.getMonth()==A.getMonth())&&(this.getDate()==A.getDate())&&(this.getHours()==A.getHours())&&(this.getMinutes()==A.getMinutes()))};Date.prototype.setDateOnly=function(B){var A=new Date(B);this.setDate(1);this.setFullYear(A.getFullYear());this.setMonth(A.getMonth());this.setDate(A.getDate())};Date.prototype.print=function(L){var H=this.getMonth(),D=this.getDate(),Q=this.getFullYear(),G=this.getWeekNumber(),K=this.getDay(),M={},A=this.getHours(),P=(A>=12),C=(P)?(A-12):A,E=this.getDayOfYear();if(C==0)C=12;var B=this.getMinutes(),N=this.getSeconds();M["%a"]=Calendar._SDN[K];M["%A"]=Calendar._DN[K];M["%b"]=Calendar._SMN[H];M["%B"]=Calendar._MN[H];M["%C"]=1+Math.floor(Q/100);M["%d"]=(D<10)?("0"+D):D;M["%e"]=D;M["%H"]=(A<10)?("0"+A):A;M["%I"]=(C<10)?("0"+C):C;M["%j"]=(E<100)?((E<10)?("00"+E):("0"+E)):E;M["%k"]=A;M["%l"]=C;M["%m"]=(H<9)?("0"+(1+H)):(1+H);M["%M"]=(B<10)?("0"+B):B;M["%n"]="\n";M["%p"]=P?"PM":"AM";M["%P"]=P?"pm":"am";M["%s"]=Math.floor(this.getTime()/1000);M["%S"]=(N<10)?("0"+N):N;M["%t"]="\t";M["%U"]=M["%W"]=M["%V"]=(G<10)?("0"+G):G;M["%u"]=K+1;M["%w"]=K;M["%y"]=(""+Q).substr(2,2);M["%Y"]=Q;M["%%"]="%";var I=/%./g;if(!Calendar.is_ie5&&!Calendar.is_khtml)return L.replace(I,function(A){return M[A]||A});var F=L.match(I);for(var J=0;J<F.length;J++){var O=M[F[J]];if(O){I=new RegExp(F[J],"g");L=L.replace(I,O)}}return L};Date.prototype.__msh_oldSetFullYear=Date.prototype.setFullYear;Date.prototype.setFullYear=function(B){var A=new Date(this);A.__msh_oldSetFullYear(B);if(A.getMonth()!=this.getMonth())this.setDate(28);this.__msh_oldSetFullYear(B)};window._dynarch_popupCalendar=null;Calendar.windowLoaded=typeof(document.readyState)!="undefined"?(document.readyState=="loaded"||document.readyState=="complete"):document.getElementsByTagName!=null&&typeof(document.getElementsByTagName("body")[0])!="undefined";Calendar.addEvent(window,"load",function(){Calendar.windowLoaded=true});Calendar.IFRAME_id=0;Calendar.createIFRAME=function(A){if(!Calendar.is_ie)return null;var C="IFRAME"+(++Calendar.IFRAME_id),B=["<iframe id=\"",C,"\" scrolling=\"no\" frameborder=\"0\" style=\"z-index:0;position:absolute;visibility:hidden;filter:progid:DXImageTransform.Microsoft.alpha(style=0,opacity=0,finishOpacity=0);border:0;top:0;left:0;width:0;height:0\" src=\"javascript:false\"></iframe>"].join("");if(!A)A=document.body;if(Calendar.windowLoaded)A.insertAdjacentHTML("beforeEnd",B);else Calendar.addEvent(window,"load",function(){A.insertAdjacentHTML("beforeEnd",B);A=null});return document.getElementById(C)};Calendar.setupIFRAME_el=function(A,K,F){if(A){var J=Calendar.getAbsolutePos(K),B=J.x,C=J.y,D=B+K.offsetWidth,E=C+K.offsetHeight;if(F){var H=Calendar.getAbsolutePos(F),L=H.x,I=H.y,M=L+F.offsetWidth,G=I+F.offsetHeight;if(B>L)B=L;if(C>I)C=I;if(D<M)D=M;if(E<G)E=G}Calendar.setupIFRAME(A,B,C,D-B,E-C)}};Calendar.setupIFRAME=function(B,F,E,A,D){if(B){var C=B.style;(typeof F!="undefined")&&(C.left=F+"px");(typeof E!="undefined")&&(C.top=E+"px");(typeof A!="undefined")&&(C.width=A+"px");(typeof D!="undefined")&&(C.height=D+"px");C.visibility="inherit"}};Calendar.hideIFRAME=function(A){if(A)A.style.visibility="hidden"};Calendar.prototype.updateIFRAME=function(A){Calendar.setupIFRAME_el(this.IFRAME,this.element,A)};Calendar.getPageScrollX=function(){if(window.pageXOffset)return window.pageXOffset;else if(document.body&&document.body.scrollLeft)return document.body.scrollLeft;else if(document.documentElement&&document.documentElement.scrollLeft)return document.documentElement.scrollLeft;return 0};Calendar.getPageScrollY=function(){if(window.pageYOffset)return window.pageYOffset;else if(document.body&&document.body.scrollTop)return document.body.scrollTop;else if(document.documentElement&&document.documentElement.scrollTop)return document.documentElement.scrollTop;return 0};Calendar.getWindowSize=function(){var B=0,A=0;if(Calendar.is_opera){B=document.body.clientWidth||0;A=document.body.clientHeight||0}else if(Calendar.is_khtml){B=window.innerWidth||0;A=window.innerHeight||0}else if(document.compatMode&&document.compatMode=="CSS1Compat"){B=document.documentElement.clientWidth||0;A=document.documentElement.clientHeight||0}else{B=document.body.clientWidth||0;A=document.body.clientHeight||0}return{width:B,height:A}};Calendar.fixPosition2=function(C,B){var E=Calendar.getPageScrollX(),D=Calendar.getPageScrollY(),A=Calendar.getWindowSize();B=parseInt(B,10)||0;if(C.x<E)C.x=E+B;if(C.y<D)C.y=D+B;if(C.x+C.width>E+A.width)C.x=E+A.width-C.width-B;if(C.y+C.height>D+A.height)C.y=D+A.height-C.height-B};Calendar.setup=function(E){function B(B,A){if(typeof E[B]=="undefined")E[B]=A}B("inputField",null);B("displayArea",null);B("button",null);B("eventName","click");B("ifFormat","%Y/%m/%d");B("daFormat","%Y/%m/%d");B("singleClick",true);B("disableFunc",null);B("dateStatusFunc",E["disableFunc"]);B("dateText",null);B("firstDay",null);B("align","Br");B("range",[1900,2999]);B("weekNumbers",true);B("flat",null);B("flatCallback",null);B("onSelect",null);B("onClose",null);B("onUpdate",null);B("date",null);B("showsTime",false);B("timeFormat","24");B("electric",true);B("step",2);B("position",null);B("cache",false);B("showOthers",false);B("multiple",null);var C=["inputField","displayArea","button"];for(var G in C)if(typeof E[C[G]]=="string")E[C[G]]=document.getElementById(E[C[G]]);if(!(E.flat||E.multiple||E.inputField||E.displayArea||E.button)){alert("Calendar.setup:\n  Nothing to setup (no fields found).  Please check your code");return false}function A(C){var B=C.params,A=(C.dateClicked||B.electric);if(A&&B.inputField){B.inputField.value=C.date.print(B.ifFormat);if(typeof B.inputField.onchange=="function")B.inputField.onchange()}if(A&&B.displayArea)B.displayArea.innerHTML=C.date.print(B.daFormat);if(A&&typeof B.onUpdate=="function")B.onUpdate(C);if(A&&B.flat)if(typeof B.flatCallback=="function")B.flatCallback(C);if(A&&B.singleClick&&C.dateClicked)C.callCloseHandler()}if(E.flat!=null){if(typeof E.flat=="string")E.flat=document.getElementById(E.flat);if(!E.flat){alert("Calendar.setup:\n  Flat specified but can't find parent.");return false}var D=new Calendar(E.firstDay,E.date,E.onSelect||A);D.showsOtherMonths=E.showOthers;D.showsTime=E.showsTime;D.time24=(E.timeFormat=="24");D.params=E;D.weekNumbers=E.weekNumbers;D.setRange(E.range[0],E.range[1]);D.setDateStatusHandler(E.dateStatusFunc);D.getDateText=E.dateText;if(E.ifFormat)D.setDateFormat(E.ifFormat);if(E.inputField&&typeof E.inputField.value=="string")D.parseDate(E.inputField.value);D.create(E.flat);D.show();return false}var F=E.button||E.displayArea||E.inputField;F["on"+E.eventName]=function(){var G=E.inputField||E.displayArea,F=E.inputField?E.ifFormat:E.daFormat,C=false,D=window.calendar;if(G)E.date=Date.parseDate(G.value||G.innerHTML,F);if(!(D&&E.cache)){window.calendar=D=new Calendar(E.firstDay,E.date,E.onSelect||A,E.onClose||function(A){A.hide()});D.showsTime=E.showsTime;D.time24=(E.timeFormat=="24");D.weekNumbers=E.weekNumbers;C=true}else{if(E.date)D.setDate(E.date);D.hide()}if(E.multiple){D.multiple={};for(var I=E.multiple.length;--I>=0;){var B=E.multiple[I],H=B.print("%Y%m%d");D.multiple[H]=B}}D.showsOtherMonths=E.showOthers;D.yearStep=E.step;D.setRange(E.range[0],E.range[1]);D.params=E;D.setDateStatusHandler(E.dateStatusFunc);D.getDateText=E.dateText;D.setDateFormat(F);if(C)D.create();D.refresh();if(!E.position)D.showAtElement(E.button||E.displayArea||E.inputField,E.align);else D.showAt(E.position[0],E.position[1]);return false};return D};window.calendar=null;function selected(A,B){A.params.inputField.value=B;if(A.singleClick&&A.dateClicked)A.callCloseHandler()}function closeHandler(A){A.hide()}function showCalendar(A,D){var B=document.getElementById(A);if(calendar!=null)calendar.hide();else{var C=new Calendar(false,null,selected,closeHandler);calendar=C;C.setRange(1900,2070);C.singleClick=true;C.create()}calendar.setDateFormat(D?D:"%Y-%m-%d");calendar.parseDate(B.value);calendar.params={inputField:B};calendar.showAtElement(B);return false}
