/**
 * doijs package
 * 
 * @author donna iwan setiawan
 * @version 1.1 release 6
 * copyright - (c) 2007 - 2010 donna iwan setiawan
 * license - GPL version 3 or any later version <http://www.gnu.org/licenses/gpl-3.0.txt>
 */
doi.widget.calendar=function(c){var e=[],d=[],b="doi-widget-calendar",a=arguments[1]||{};this.render=function(){if(!c){e=doi.dom.$("tag:div;title=doi-widget-calendar:true")}else{if(c.length){e=c}else{e=[c]}}if(!e||(e&&e.length==0)){return}for(var g=0;g<e.length;g++){var j=e[g].getAttribute("title");var f=doi.dom.merge({},a);f.className=(e[g].className)||b;f.attribute=doi.dom.parseAttribute(j);if(f.attribute.title){e[g].setAttribute("title",f.attribute.title)}else{e[g].setAttribute("title","")}var h=new doi.widget.calendarByElement(e[g],f);h.render();d.push(h)}};this.calendars=function(){return d}};doi.widget.register(doi.widget.calendar);doi.widget.calendarByElement=function(){var m=arguments[0],a=arguments[1]||{},b=(a.className)||"doi-widget-calendar",c,h=a.attribute||{},d=false,f=new Date(),g={d:f.getDate(),m:f.getMonth()+1,y:f.getFullYear(),h:0,i:0,s:0},e,i={from:f.getFullYear(),to:f.getFullYear()},p=this,o=false,r="m";if(doi.dom.isString(h)){h=doi.dom.parseAttribute(h)}this.data={day:["","Mon","Tue","Wed","Thu","Fri","Sat","Sun"],month:["","January","February","March","April","May","June","July","August","September","October","November","December"]};this.render=function(){if(d){return}if(!m||(m&&!doi.dom.isElement(m))){c=doi.widget.instance.save(this);var y=document.createElement("div");doi.dom.write(y);m=y}else{c=doi.widget.instance.save(this,m.id);if(!h){var u=m.getAttribute("title");m.setAttribute("title","");h=doi.dom.parseAttribute(u)}}if(a.parent&&doi.dom.isElement(a.parent)){a.parent.appendChild(m)}m.id=c;doi.dom.className(m,b);if(h.year){var t=h.year.match(/(\d{4,})(\s{1,}\d{4,})*/);if(t){var x=t[1];if(x<1900){x=f.getFullYear()}var w=doi.dom.parseInt(t[2]);if(w<1900){w=f.getFullYear()}i.from=x;i.to=w}else{i.from=1900;i.to=f.getFullYear()+10}}var v=q(h.value);if(v){g=n(v)}else{g=n(g)}e=new doi.dom.clone(g);m.innerHTML="";m.appendChild(s());d=true};this.element=function(){return doi.dom.$("#"+c)};function n(t){if(!t.y){t.y=g.y}if(!t.m){t.m=g.m}if(!t.d){t.d=g.d}var w=new Date(t.y,t.m-1,t.d);t.d=w.getDate();t.m=w.getMonth()+1;t.y=w.getFullYear();var v=i.from;var u=i.to;if(i.from>i.to){v=i.to;u=i.from}if(t.y<v||t.y>u){if(t.y<v){t.y=u}else{t.y=v}w=new Date(t.y,t.m-1,t.d);t.d=w.getDate();t.m=w.getMonth()+1;t.y=w.getFullYear()}if(t.h<0||t.h>23){t.h=0}if(t.i<0||t.i>59){t.i=0}if(t.s<0||t.s>59){t.s=0}return t}function q(x){if(!doi.dom.isString(x)){return false}var y=/^(\d{4,})\-(\d{1,2})\-(\d{1,2})(.*)/;var v=x.match(y);var u={};if(v){u.y=doi.dom.parseInt(v[1]);u.m=doi.dom.parseInt(v[2]);u.d=doi.dom.parseInt(v[3]);u.h=0;u.i=0;u.s=0;if(v[4]){var w=v[4].split(":");u.h=doi.dom.parseInt(w[0]);u.i=doi.dom.parseInt(w[1]);u.s=doi.dom.parseInt(w[2])}}else{v=x.split(":");u.h=doi.dom.parseInt(v[0]);u.i=doi.dom.parseInt(v[1]);u.s=doi.dom.parseInt(v[2])}return u}function j(w){var y=doi.dom.$("#"+c+"-nav-info");var x=document.createElement("div");if(r=="m"){var u=document.createElement("a");u.href="#";u.innerHTML=w.y;var v=document.createTextNode(p.data.month[w.m]+" ");doi.event.add(u,"click",function(){r="y";j(w)});x.appendChild(v);x.appendChild(u)}else{var u=document.createElement("a");u.href="#";u.innerHTML=p.data.month[w.m];var v=document.createTextNode(" "+w.y);doi.event.add(u,"click",function(){r="m";j(w)});x.appendChild(u);x.appendChild(v)}if(y){y.innerHTML="";y.appendChild(x)}else{return x}}function k(t,u,v){if(u=="next"){if(r=="m"){v.m++}else{v.y++}}else{if(r=="m"){v.m--}else{v.y--}}v=n(v);doi.event.fire(p,"navcellclick",{type:u,element:t,datetime:v});j(v);l(false,v)}function s(){var E=document.createElement("table");var x=document.createElement("tbody");E.setAttribute("cellPadding",0);E.setAttribute("cellSpacing",0);E.setAttribute("border",0);E.setAttribute("width","100%");var y=document.createElement("tr");var w=document.createElement("tr");var v=document.createElement("td");var u=document.createElement("td");E.appendChild(x);x.appendChild(y);x.appendChild(w);y.appendChild(v);w.appendChild(u);u.id=c+"-content";var C=document.createElement("table");var t=document.createElement("tbody");C.setAttribute("cellPadding",0);C.setAttribute("cellSpacing",0);C.setAttribute("border",0);C.setAttribute("width","100%");var D=document.createElement("tr");var B=document.createElement("td");B.setAttribute("width","10%");var A=document.createElement("td");var z=document.createElement("td");z.setAttribute("width","10%");v.appendChild(C);C.appendChild(t);t.appendChild(D);D.appendChild(B);D.appendChild(A);D.appendChild(z);C.id=c+"-nav";B.id=c+"-nav-back";A.id=c+"-nav-info";z.id=c+"-nav-next";doi.dom.className(C,b+"-nav");doi.dom.className(B,b+"-nav-back");doi.dom.className(A,b+"-nav-info");doi.dom.className(z,b+"-nav-next");doi.event.add(B,"mouseover",function(){doi.dom.addClass(this,b+"-nav-back-hover")});doi.event.add(z,"mouseover",function(){doi.dom.addClass(this,b+"-nav-next-hover")});doi.event.add(B,"mouseout",function(){doi.dom.removeClass(this,b+"-nav-back-hover")});doi.event.add(z,"mouseout",function(){doi.dom.removeClass(this,b+"-nav-next-hover")});doi.event.add(B,"click",function(){k(this,"back",g)});doi.event.add(z,"click",function(){k(this,"next",g)});B.innerHTML="&laquo;";z.innerHTML="&raquo;";A.appendChild(j(g));l(u,g);return E}function l(C){var Q=document.createElement("table");Q.setAttribute("cellPadding",1);Q.setAttribute("cellSpacing",1);Q.setAttribute("border",0);Q.setAttribute("width","100%");doi.dom.className(Q,b+"-content");var w=document.createElement("tbody");Q.appendChild(w);var P=new Date(g.y,g.m-1,1);var D=P.getDay();if(D==0){D=7}var P=new Date(g.y,g.m-1,31);var M=31;if(P.getMonth()+1!=g.m){M=31-P.getDate()}var x=(new Date(g.y,g.m-1,M).getDay());if(x==0){x=7}var I=Math.ceil((M+D-1)/7);var B=new Date(g.y,g.m-2,1);var A=B.getMonth()+1;var u=B.getFullYear();B=new Date(u,A-1,31);var z=31;var G=B.getMonth()+2;if(G>12){G-=12}if(G!=g.m){z-=B.getDate()}B=new Date(u,A-1,z);var y=B.getDay();if(y==0){y=7}var E=new Date(g.y,g.m,1);var O=1;var F=1;var H=B.getDate()-B.getDay()+1;var t=i.from;var J=i.to;if(t>J){t=i.to;J=i.from}for(var L=0;L<=I;L++){var N=document.createElement("tr");for(var K=1;K<=7;K++){var v=document.createElement("td");if(L==0){v.innerHTML=p.data.day[K];doi.dom.className(v,b+"-content-day");N.appendChild(v);continue}if(L==1){if(K>=D){v._datetime={d:O,m:g.m,y:g.y};doi.dom.className(v,b+"-content-cell");v.innerHTML=O++}else{v._datetime={d:H,m:B.getMonth()+1,y:B.getFullYear()};v.innerHTML=H++;if(v._datetime.y<t||v._datetime.y>J){v._datetime=false;v.innerHTML="&nbsp"}doi.dom.className(v,b+"-content-cell-other")}}else{if(L==I){if(K<=x){v._datetime={d:O,m:g.m,y:g.y};v.innerHTML=O++;doi.dom.className(v,b+"-content-cell")}else{v._datetime={d:F,m:E.getMonth()+1,y:E.getFullYear()};v.innerHTML=F++;if(v._datetime.y<t||v._datetime.y>J){v._datetime=false;v.innerHTML="&nbsp"}doi.dom.className(v,b+"-content-cell-other")}}else{v._datetime={d:O,m:g.m,y:g.y};v.innerHTML=O++;doi.dom.className(v,b+"-content-cell")}}if(e.d==v._datetime.d&&e.m==v._datetime.m&&e.y==v._datetime.y){doi.dom.addClassName(v,b+"-content-cell-click");if(o){doi.dom.removeClass(o,"-content-cell-click")}o=v}N.appendChild(v);doi.event.add(v,"click",function(){if(!this._datetime){return false}doi.dom.addClass(this,b+"-content-cell-click");if(o){doi.dom.removeClass(o,b+"-content-cell-click")}o=this;p.value(this._datetime,(e.m!=this._datetime.m));doi.event.fire(p,"cellclick",{element:o,datetime:this._datetime})});v._row=L;v._col=K;doi.event.add(v,"mouseover",function(){var X=b+"-content-cell-hover-focus";var R=b+"-content-cell-hover";doi.dom.addClass(this,X);var W=this.parentNode;for(var V=0;V<W.childNodes.length;V++){var U=W.childNodes[V];doi.dom.addClass(U,R)}var Y=W.parentNode.parentNode;var Z=this._row;var T=this._col;var S=Y.rows.length;for(var V=0;V<S;V++){if(V==0){doi.dom.addClass(Y.rows[V].childNodes[T-1],b+"-content-day-hover")}else{doi.dom.addClass(Y.rows[V].childNodes[T-1],R)}}});doi.event.add(v,"mouseout",function(){var X=b+"-content-cell-hover-focus";var R=b+"-content-cell-hover";doi.dom.removeClass(this,X);var W=this.parentNode;for(var V=0;V<W.childNodes.length;V++){var U=W.childNodes[V];doi.dom.removeClass(U,R)}var Y=W.parentNode.parentNode;var Z=this._row;var T=this._col;var S=Y.rows.length;for(var V=0;V<S;V++){if(V==0){doi.dom.removeClass(Y.rows[V].childNodes[T-1],b+"-content-day-hover")}else{doi.dom.removeClass(Y.rows[V].childNodes[T-1],R)}}})}w.appendChild(N)}if(!C){C=doi.dom.$("#"+c+"-content")}if(C){if(C.firstChild){C.replaceChild(Q,C.firstChild)}else{C.innerHTML="";C.appendChild(Q)}}doi.event.fire(p,"render")}this.value=function(){var t=arguments[0];var u=(arguments[1]!=false);if(t){if(doi.dom.isString(t)){t=q(t);if(!t){return new doi.dom.clone(e)}}t=n(t);e=new doi.dom.clone(t);g=new doi.dom.clone(t);if(u){j(g);l(false,g)}}return new doi.dom.clone(e)}};
