(function(){var A=YAHOO.lang,C=YAHOO.util.Dom,D=YAHOO.util.Event,B=ZC.Util;var E=ZC.Core.Widget.Create("DateTime_Text","Travel");E.prototype._FindElements=function(){var F=this._WidgetNameToID();var G=C.get(F);if(G){this._elInput=G}this._elButtonHolder=C.get(F+"-calbutton");if(!this._elInput){this.aDef.SuppressCalendar=true;this._elInput=undefined}this._FindContainers()};E.prototype.SetupYUICalendar=function(){var F=this.GetCaption();if(!F&&this.oParent){F=this.oParent.GetCaption()}if(!F){F="Calendar"}var H=document.createElement("div");this.oYUICalendar=new YAHOO.widget.Calendar(H,{iframe:false,navigator:true,mindate:new Date()});this.oCalDialog=ZC.JSManager.CreateDialog(F,H,document.body,{width:"16em",context:[this.elCalButton,"tl","bl"],buttons:[{text:B.DGetText("Travel","Close"),handler:{fn:function(){this.HideCalendar()},scope:this,correctScope:true}}]});var G=function(){this.oCalDialog.fireEvent("changeContent")};this.oYUICalendar.renderEvent.subscribe(G,this,true);this.oYUICalendar.selectEvent.subscribe(this.SelectionChangeHandler,this,true)};E.prototype.CustomSetupStart=function(){this.elCalButton=document.createElement("input");this.elCalButton.type="button";this.elCalButton.className="opencalendar";this.elCalButton.value=B.DGetText("Travel","Calendar");this.elCalButton.title=B.DGetText("Travel","Open a calendar for selecting a date");if(this._elButtonHolder){this._elButtonHolder.parentNode.replaceChild(this.elCalButton,this._elButtonHolder)}else{aHelp=C.getElementsByClassName("newhelp","img",this.elContainer);if(aHelp.length){C.insertBefore(this.elCalButton,aHelp[0])}else{B.WrapContents(this._elInput);this._elInput.parentNode.appendChild(this.elCalButton)}}fnCalButtonClickHandler=function(F){D.stopEvent(F);if(!A.isUndefined(this.oCalDialog)&&this.oCalDialog.cfg.getProperty("visible")){this.HideCalendar()}else{this.ShowCalendar()}};D.on(this.elCalButton,"click",fnCalButtonClickHandler,this,true);D.on(this._elInput,"change",this._SelectsToCalendar,this,true);return true};E.prototype._InputToCalendar=function(){if(A.isUndefined(this.oYUICalendar)){return }this.oYUICalendar.select(this.GetValue());this.oYUICalendar.cfg.setProperty("pagedate",this.GetValue());console.log(this.GetValue());this.oYUICalendar.render()};E.prototype.SelectionChangeHandler=function(I,J){if(this.bChangingSelection){return }var H=J[0][0];var G=H[0];var K=H[1]-1;var F=H[2];oDate=new Date(G,K,F);console.log("Selection change handler");this.SetValue(oDate,[],true);this.bChangingSelection=true;this._FireEventHandlers("change");this.bChangingSelection=false};E.prototype.SetValue=function(F,I,H){var G;if(F==null){return this.Clear()}if(A.isString(F)){G=new Date(F)}else{if(A.isNumber(F)){G=new Date(F*1000)}else{G=F}}this._elInput.value=B.sprintf("%02d/%02d/%d",G.getDate(),G.getMonth()+1,G.getFullYear());console.log("Date changing to "+this._elInput.value);if(!H&&this.oYUICalendar){this.oYUICalendar.select(G);this._FireEventHandlers("change")}};E.prototype.GetValue=function(){var F=new Date(),G;G=this._elInput.value.split("/");F.setDate(G[0]||F.getDate());F.setMonth(G[1]-1||F.getMonth());F.setFullYear(G[2]||F.getFullYear());return F};E.prototype.Clear=function(){};E.prototype.ShowCalendar=function(){if(A.isUndefined(this.oYUICalendar)){this.SetupYUICalendar()}this._InputToCalendar();this.oCalDialog.show();if(YAHOO.env.ua.opera&&document.documentElement){document.documentElement.className+=""}};E.prototype.HideCalendar=function(){this.oCalDialog.hide();this._FireEventHandlers("blur")};E.prototype.Enable=function(F,H,G){E.superclass.Enable.call(this,F,H,G);if(!this.aDef.SuppressCalendar){this.elCalButton.disabled=!F;C[F?"removeClass":"addClass"](this.elCalButton,"disabled")}}})();
