(function(i){function h(a){var b=i.data(a,"datebox");var c=b.options;i(a).addClass("datebox-f");i(a).combo(i.extend({},c,{onShowPanel:function(){b.calendar.calendar("resize");c.onShowPanel.call(a)}}));i(a).combo("textbox").parent().addClass("datebox");if(!b.calendar){d()}function d(){var e=i(a).combo("panel");b.calendar=i("<div></div>").appendTo(e).wrap('<div class="datebox-calendar-inner"></div>');b.calendar.calendar({fit:true,border:false,onSelect:function(k){var n=c.formatter(k);f(a,n);i(a).combo("hidePanel");c.onSelect.call(a,k)}});f(a,c.value);var l=i('<div class="datebox-button"></div>').appendTo(e);i('<a href="javascript:void(0)" class="datebox-current"></a>').html(c.currentText).appendTo(l);i('<a href="javascript:void(0)" class="datebox-close"></a>').html(c.closeText).appendTo(l);l.find(".datebox-current,.datebox-close").hover(function(){i(this).addClass("datebox-button-hover")},function(){i(this).removeClass("datebox-button-hover")});l.find(".datebox-current").click(function(){b.calendar.calendar({year:new Date().getFullYear(),month:new Date().getMonth()+1,current:new Date()})});l.find(".datebox-close").click(function(){i(a).combo("hidePanel")})}}function j(b,a){f(b,a)}function g(d){var a=i.data(d,"datebox").options;var b=i.data(d,"datebox").calendar;var c=a.formatter(b.calendar("options").current);f(d,c);i(d).combo("hidePanel")}function f(a,b){var c=i.data(a,"datebox");var d=c.options;i(a).combo("setValue",b).combo("setText",b);c.calendar.calendar("moveTo",d.parser(b))}i.fn.datebox=function(a,b){if(typeof a=="string"){var c=i.fn.datebox.methods[a];if(c){return c(this,b)}else{return this.combo(a,b)}}a=a||{};return this.each(function(){var d=i.data(this,"datebox");if(d){i.extend(d.options,a)}else{i.data(this,"datebox",{options:i.extend({},i.fn.datebox.defaults,i.fn.datebox.parseOptions(this),a)})}h(this)})};i.fn.datebox.methods={options:function(a){return i.data(a[0],"datebox").options},calendar:function(a){return i.data(a[0],"datebox").calendar},setValue:function(a,b){return a.each(function(){f(this,b)})}};i.fn.datebox.parseOptions=function(a){var b=i(a);return i.extend({},i.fn.combo.parseOptions(a),{})};i.fn.datebox.defaults=i.extend({},i.fn.combo.defaults,{panelWidth:180,panelHeight:"auto",keyHandler:{up:function(){},down:function(){},enter:function(){g(this)},query:function(a){j(this,a)}},currentText:"Today",closeText:"Close",okText:"Ok",formatter:function(c){var a=c.getFullYear();var d=c.getMonth()+1;var b=c.getDate();return d+"/"+b+"/"+a},parser:function(a){var b=Date.parse(a);if(!isNaN(b)){return new Date(b)}else{return new Date()}},onSelect:function(a){}})})(jQuery);