(function(){var A=YAHOO.lang,C=YAHOO.util.Dom,E=YAHOO.util.Event,B=ZC.Util,D=B.GetText;var F=ZC.Core.Widget.Create("DateTime");F.prototype._FindElements=function(){this._aDatePartEls={};this._elInput=[];var G=this._WidgetNameToID();var H=C.get(G);if(H){this._elInput.push(H)}for(var I in this.aDef.TimePartSet){if(A.hasOwnProperty(this.aDef.TimePartSet,I)&&this.aDef.TimePartSet[I]){H=C.get(G+"_"+I.toLowerCase());if(H){this._aDatePartEls[I]=H;this._elInput.push(this._aDatePartEls[I])}}}this._elButtonHolder=C.get(G+"-calbutton");if(this._elInput.length==0){this.aDef.SuppressCalendar=true;this._elInput=undefined}this._FindContainers()};F.prototype.SetupYUICalendar=function(){var G=this.GetCaption();if(!G&&this.oParent){G=this.oParent.GetCaption()}if(!G){G="Calendar"}var I=document.createElement("div");this.oYUICalendar=new YAHOO.widget.Calendar(I,{iframe:false,navigator:true});this.oCalDialog=ZC.JSManager.CreateDialog(G,I,document.body,{width:"16em",context:[this.elCalButton,"tl","bl"],buttons:[{text:D("Close"),handler:{fn:function(){this.HideCalendar()},scope:this,correctScope:true}}]});var H=function(){this.oCalDialog.fireEvent("changeContent")};this.oYUICalendar.renderEvent.subscribe(H,this,true);this.oYUICalendar.selectEvent.subscribe(this.SelectionChangeHandler,this,true);this._CheckMinWidgets();this._CheckMaxWidgets()};F.prototype.CustomSetupStart=function(){var G=this.aDef.TimePartSet,H,I;if(this.aDef.SuppressCalendar||this.IsReadOnly()||!G.Year||!G.Month||!G.Day){return true}this.elCalButton=document.createElement("input");this.elCalButton.type="button";this.elCalButton.className="opencalendar";this.elCalButton.value=D("Calendar");this.elCalButton.title=D("Open a calendar for selecting a date");if(this._elButtonHolder){this._elButtonHolder.parentNode.replaceChild(this.elCalButton,this._elButtonHolder)}else{I=C.getElementsByClassName("newhelp","img",this.elContainer);if(I.length){C.insertBefore(this.elCalButton,I[0])}else{if(this._aDatePartEls.Year){this._aDatePartEls.Year.parentNode.appendChild(this.elCalButton)}}}H=function(J){E.stopEvent(J);if(!A.isUndefined(this.oCalDialog)&&this.oCalDialog.cfg.getProperty("visible")){this.HideCalendar()}else{this.ShowCalendar()}};E.on(this.elCalButton,"click",H,this,true);E.on(this._elInput,"change",this._SelectsToCalendar,this,true);return true};F.prototype.Destruct=function(){F.superclass.Destruct.apply(this,arguments);this._aDatePartEls={};this._elButtonHolder=null;this.oYUICalendar=null;this.oCalDialog=null;this.elCalButton=null;this._aMinWidgets=[];this._aMaxWidgets=[]};F.prototype._SelectsToCalendar=function(){if(A.isUndefined(this.oYUICalendar)){return }this.oYUICalendar.select(this.GetValue());this.oYUICalendar.cfg.setProperty("pagedate",this.GetValue());this.oYUICalendar.render()};F.prototype.ShowCalendar=function(){if(A.isUndefined(this.oYUICalendar)){this.SetupYUICalendar()}this._SelectsToCalendar();this.oCalDialog.show();if(YAHOO.env.ua.opera&&document.documentElement){document.documentElement.className+=""}};F.prototype.HideCalendar=function(){this.oCalDialog.hide();this._FireEventHandlers("blur")};F.prototype.CustomSetupEnd=function(){var H=Infinity,G=-Infinity;if(!A.isUndefined(this._aDatePartEls.Year)){B.ForEach(this._aDatePartEls.Year.options,function(I){var K=I.value,J;if(K!="Null"){J=new Number(K);H=Math.min(H,J);G=Math.max(G,J)}});this.SetAttrib("StartYear",H);this.SetAttrib("StopYear",G)}this._aMinWidgets=[];this._aMaxWidgets=[];if(this.HasValidator("CompareTo")){ZC.JSManager.GetEvent("ManagerInit").subscribe(function(){if(this.AttribIsset("GreaterThanField")){var I=this.GetAttrib("GreaterThanField");if(A.isString(I)){I=[I]}I=B.Map(I,ZC.JSManager.GetWidget,ZC.JSManager);this.AddLowerBoundWidget(I,false);B.ForEach(I,function(J){if(!A.isUndefined(J)&&J.AddUpperBoundWidget){J.AddUpperBoundWidget(this,true)}},this)}if(this.AttribIsset("GreaterThanOrEqualField")){var I=this.GetAttrib("GreaterThanOrEqualField");if(A.isString(I)){I=[I]}I=B.Map(I,ZC.JSManager.GetWidget,ZC.JSManager);this.AddLowerBoundWidget(I,true);B.ForEach(I,function(J){if(!A.isUndefined(J)&&J.AddUpperBoundWidget){J.AddUpperBoundWidget(this,true)}},this)}if(this.AttribIsset("LessThanField")){var I=this.GetAttrib("LessThanField");if(A.isString(I)){I=[I]}I=B.Map(I,ZC.JSManager.GetWidget,ZC.JSManager);this.AddUpperBoundWidget(I,false);B.ForEach(I,function(J){if(!A.isUndefined(J)&&J.AddLowerBoundWidget){J.AddLowerBoundWidget(this,true)}},this)}if(this.AttribIsset("LessThanOrEqualField")){var I=this.GetAttrib("LessThanOrEqualField");if(A.isString(I)){I=[I]}I=B.Map(I,ZC.JSManager.GetWidget,ZC.JSManager);this.AddUpperBoundWidget(I,true);B.ForEach(I,function(J){if(!A.isUndefined(J)&&J.AddLowerBoundWidget){J.AddLowerBoundWidget(this,true)}},this)}},this,true)}return true};F.prototype._CheckMinWidgets=function(H,G){if(!this.oYUICalendar){return }var I;if(this.AttribIsset("StartYear")){I=new Date(this.GetAttrib("StartYear"),0,1)}B.ForEach(this._aMinWidgets,function(K){var J=K.oWidget.GetValue();if(!J){return }if(!K.bInclusive){J.setUTCDate(J.getUTCDate()+1)}if(A.isUndefined(I)||J>I){I=J}});if(I){this.oYUICalendar.cfg.setProperty("mindate",I);this.oYUICalendar.render()}};F.prototype._CheckMaxWidgets=function(H,G){if(!this.oYUICalendar){return }var I;if(this.AttribIsset("StopYear")){I=new Date(this.GetAttrib("StopYear"),11,31)}B.ForEach(this._aMaxWidgets,function(K){var J=K.oWidget.GetValue();if(!J){return }if(!K.bInclusive){J.setUTCDate(J.getUTCDate()-1)}if(A.isUndefined(I)||J<I){I=J}});if(I){this.oYUICalendar.cfg.setProperty("maxdate",I);this.oYUICalendar.render()}};F.prototype.AddLowerBoundWidget=function(G,H){if(!A.isArray(G)){G=[G]}B.ForEach(G,function(I){if(A.isUndefined(I)){return }this._aMinWidgets.push({oWidget:I,bInclusive:H});I.AddEvent(this._CheckMinWidgets,"change",this)},this);this._CheckMinWidgets.call(this)};F.prototype.AddUpperBoundWidget=function(G,H){if(!A.isArray(G)){G=[G]}B.ForEach(G,function(I){if(A.isUndefined(I)){return }this._aMaxWidgets.push({oWidget:I,bInclusive:H});I.AddEvent(this._CheckMaxWidgets,"change",this)},this);this._CheckMaxWidgets.call(this)};F.prototype.SelectionChangeHandler=function(H,I){if(this.bChangingSelection){return }var G=I[0][0];this._aDatePartEls.Year.value=G[0];this._aDatePartEls.Month.value=G[1];this._aDatePartEls.Day.value=G[2];this.bChangingSelection=true;this._FireEventHandlers("change");this.bChangingSelection=false};F.prototype.Enable=function(G,I,H){F.superclass.Enable.call(this,G,I,H);if(!this.aDef.SuppressCalendar){this.elCalButton.disabled=!G;C[G?"removeClass":"addClass"](this.elCalButton,"disabled")}};F.prototype.GetTextValue=function(H){H=H||this.aDef.TimePartSet;var G=(H.Year&&H.Month&&H.Day);var I=(H.Hour&&H.Minute);if(G&&!I){return this.GetValue().toLocaleDateString()}else{if(I&&!G){return this.GetValue().toLocaleDateString()}else{return this.GetValue().toLocaleString()}}};F.prototype.GetValue=function(){var G=new Date(0);for(var H in this.aDef.TimePartSet){if(A.hasOwnProperty(this.aDef.TimePartSet,H)&&this.aDef.TimePartSet[H]){if(B.InArray(H,["Year","Month","Day","Hour","Minute","Second"])&&A.isUndefined(this._aDatePartEls[H])){return undefined}switch(H){case"Year":if(this._aDatePartEls.Year.value=="Null"){return undefined}G.setFullYear(this._aDatePartEls.Year.value);break;case"Month":if(this._aDatePartEls.Month.value=="Null"){return undefined}G.setMonth(this._aDatePartEls.Month.value-1);break;case"Day":if(this._aDatePartEls.Day.value=="Null"){return undefined}G.setDate(this._aDatePartEls.Day.value);break;case"Hour":if(this._aDatePartEls.Hour.value=="Null"){return undefined}if(this.aDef.TimePartSet.AmPm){G.setHours(this._aDatePartEls.Hour.value+(12*this._aDatePartEls.AmPm.value))}else{G.setHours(this._aDatePartEls.Hour.value)}break;case"Minute":if(this._aDatePartEls.Minute.value=="Null"){return undefined}G.setMinutes(this._aDatePartEls.Minute.value);break;case"Second":if(this._aDatePartEls.Second.value=="Null"){return undefined}G.setSeconds(this._aDatePartEls.Second.value);break}}}return G};F.prototype.SetValue=function(G,J,I){J=J||this.aDef.TimePartSet;if(G==null){return this.Clear(J)}if(A.isString(G)){oDate=new Date(G)}else{if(A.isNumber(G)){oDate=new Date(G*1000)}else{oDate=G}}for(var H in J){if(A.hasOwnProperty(J,H)&&J[H]){switch(H){case"Year":this._aDatePartEls.Year.value=oDate.getFullYear();break;case"Month":this._aDatePartEls.Month.value=oDate.getMonth()+1;break;case"Day":this._aDatePartEls.Day.value=oDate.getDate();break;case"AmPm":this._aDatePartEls.AmPm.value=(oDate.getHours()>=12)?1:0;break;case"Hour":if(this.aDef.TimePartSet.AmPm){this._aDatePartEls.Hour.value=(oDate.getHours()%12)}else{this._aDatePartEls.Hour.value=oDate.getHours()}break;case"Minute":this._aDatePartEls.Minute.value=oDate.getMinutes();break;case"Second":this._aDatePartEls.Second.value=oDate.getSeconds();break}}}if(!I&&this.oYUICalendar){this.oYUICalendar.select(oDate)}this._FireEventHandlers("change")};F.prototype.Clear=function(H){H=H||this.aDef.TimePartSet;for(var G in H){if(A.hasOwnProperty(H,G)&&H[G]){this._aDatePartEls[G].value="Null"}}this._FireEventHandlers("change")};F.prototype._WireUpEvent=function(G){if(G=="blur"){E.on(this._elInput,"blur",function(){var I,H,J=["blur"];for(I=1,H=arguments.length;I<H;I++){J.push(arguments[I])}A.later(0,this,function(){if(!B.Some(this._elInput,function(K){return(K==document.activeElement)})){this._EventDispatcher.apply(this,J)}})},this,true)}else{F.superclass._WireUpEvent.apply(this,arguments)}};ZC.Core.Widget.Create("Date","Core",F);ZC.Core.Widget.Create("Time","Core",F)})();
