(function($,undefined){$.extend($.ui,{timepicker:{version:"0.0.1"}});var PROP_NAME="timepicker";var tpuuid=new Date().getTime();function Timepicker(){this.debug=true;this._curInst=null;this._disabledInputs=[];this._timepickerShowing=false;this._inDialog=false;this._dialogClass="ui-timepicker-dialog";this._mainDivId="ui-timepicker-div";this._currentClass="ui-timepicker-current";this._dayOverClass="ui-timepicker-days-cell-over";this.regional=[];this.regional[""]={hourText:"Hour",minuteText:"Minute",amPmText:["AM","PM"]};this._defaults={showOn:"focus",showAnim:"fadeIn",showOptions:{},appendText:"",onSelect:null,onClose:null,timeSeparator:":",showPeriod:false,showLeadingZero:true,showMinutesLeadingZero:true};$.extend(this._defaults,this.regional[""]);this.tpDiv=$('<div id="'+this._mainDivId+'" class="ui-timepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all " style="display: none"></div>')}$.extend(Timepicker.prototype,{markerClassName:"hasTimepicker",log:function(){if(this.debug){console.log.apply("",arguments)}},_widgetTimepicker:function(){return this.tpDiv},setDefaults:function(settings){extendRemove(this._defaults,settings||{});return this},_attachTimepicker:function(target,settings){var inlineSettings=null;for(var attrName in this._defaults){var attrValue=target.getAttribute("time:"+attrName);if(attrValue){inlineSettings=inlineSettings||{};try{inlineSettings[attrName]=eval(attrValue)}catch(err){inlineSettings[attrName]=attrValue}}}var nodeName=target.nodeName.toLowerCase();var inline=(nodeName=="div"||nodeName=="span");if(!target.id){this.uuid+=1;target.id="tp"+this.uuid}var inst=this._newInst($(target),inline);inst.settings=$.extend({},settings||{},inlineSettings||{});if(nodeName=="input"){this._connectTimepicker(target,inst)}else{if(inline){this._inlineTimepicker(target,inst)}}},_newInst:function(target,inline){var id=target[0].id.replace(/([^A-Za-z0-9_-])/g,"\\\\$1");return{id:id,input:target,selectedDay:0,selectedMonth:0,selectedYear:0,drawMonth:0,drawYear:0,inline:inline,tpDiv:(!inline?this.tpDiv:$('<div class="'+this._inlineClass+' ui-timepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>'))}},_connectTimepicker:function(target,inst){var input=$(target);inst.append=$([]);inst.trigger=$([]);if(input.hasClass(this.markerClassName)){return}this._attachments(input,inst);input.addClass(this.markerClassName).keydown(this._doKeyDown).bind("setData.timepicker",function(event,key,value){inst.settings[key]=value}).bind("getData.timepicker",function(event,key){return this._get(inst,key)});$.data(target,PROP_NAME,inst)},_doKeyDown:function(event){var inst=$.timepicker._getInst(event.target);var handled=true;inst._keyEvent=true;if($.timepicker._timepickerShowing){switch(event.keyCode){case 9:$.timepicker._hideTimepicker();handled=false;break;case 27:$.timepicker._hideTimepicker();break;default:handled=false}}else{if(event.keyCode==36&&event.ctrlKey){$.timepicker._showTimepicker(this)}else{handled=false}}if(handled){event.preventDefault();event.stopPropagation()}},_attachments:function(input,inst){var appendText=this._get(inst,"appendText");var isRTL=this._get(inst,"isRTL");if(inst.append){inst.append.remove()}if(appendText){inst.append=$('<span class="'+this._appendClass+'">'+appendText+"</span>");input[isRTL?"before":"after"](inst.append)}input.unbind("focus",this._showTimepicker);if(inst.trigger){inst.trigger.remove()}var showOn=this._get(inst,"showOn");if(showOn=="focus"||showOn=="both"){input.focus(this._showTimepicker)}if(showOn=="button"||showOn=="both"){var buttonText=this._get(inst,"buttonText");var buttonImage=this._get(inst,"buttonImage");inst.trigger=$(this._get(inst,"buttonImageOnly")?$("<img/>").addClass(this._triggerClass).attr({src:buttonImage,alt:buttonText,title:buttonText}):$('<button type="button"></button>').addClass(this._triggerClass).html(buttonImage==""?buttonText:$("<img/>").attr({src:buttonImage,alt:buttonText,title:buttonText})));input[isRTL?"before":"after"](inst.trigger);inst.trigger.click(function(){if($.timepicker._timepickerShowing&&$.timepicker._lastInput==input[0]){$.timepicker._hideTimepicker()}else{$.timepicker._showTimepicker(input[0])}return false})}},_showTimepicker:function(input){input=input.target||input;if(input.nodeName.toLowerCase()!="input"){input=$("input",input.parentNode)[0]}if($.timepicker._isDisabledTimepicker(input)||$.timepicker._lastInput==input){return}var inst=$.timepicker._getInst(input);if($.timepicker._curInst&&$.timepicker._curInst!=inst){$.timepicker._curInst.tpDiv.stop(true,true)}var beforeShow=$.timepicker._get(inst,"beforeShow");extendRemove(inst.settings,(beforeShow?beforeShow.apply(input,[input,inst]):{}));inst.lastVal=null;$.timepicker._lastInput=input;$.timepicker._setTimeFromField(inst);if($.timepicker._inDialog){input.value=""}if(!$.timepicker._pos){$.timepicker._pos=$.timepicker._findPos(input);$.timepicker._pos[1]+=input.offsetHeight}var isFixed=false;$(input).parents().each(function(){isFixed|=$(this).css("position")=="fixed";return !isFixed});if(isFixed&&$.browser.opera){$.timepicker._pos[0]-=document.documentElement.scrollLeft;$.timepicker._pos[1]-=document.documentElement.scrollTop}var offset={left:$.timepicker._pos[0],top:$.timepicker._pos[1]};$.timepicker._pos=null;inst.tpDiv.css({position:"absolute",display:"block",top:"-1000px"});$.timepicker._updateTimepicker(inst);inst._hoursClicked=false;inst._minutesClicked=false;offset=$.timepicker._checkOffset(inst,offset,isFixed);inst.tpDiv.css({position:($.timepicker._inDialog&&$.blockUI?"static":(isFixed?"fixed":"absolute")),display:"none",left:offset.left+"px",top:offset.top+"px"});if(!inst.inline){var showAnim=$.timepicker._get(inst,"showAnim");var duration=$.timepicker._get(inst,"duration");var postProcess=function(){$.timepicker._timepickerShowing=true;var borders=$.timepicker._getBorders(inst.tpDiv);inst.tpDiv.find("iframe.ui-timepicker-cover").css({left:-borders[0],top:-borders[1],width:inst.tpDiv.outerWidth(),height:inst.tpDiv.outerHeight()})};inst.tpDiv.css("z-index",$(input).css("z-index")+1);if($.effects&&$.effects[showAnim]){inst.tpDiv.show(showAnim,$.timepicker._get(inst,"showOptions"),duration,postProcess)}else{inst.tpDiv[showAnim||"show"]((showAnim?duration:null),postProcess)}if(!showAnim||!duration){postProcess()}if(inst.input.is(":visible")&&!inst.input.is(":disabled")){inst.input.focus()}$.timepicker._curInst=inst}},_updateTimepicker:function(inst){var self=this;var borders=$.timepicker._getBorders(inst.tpDiv);inst.tpDiv.empty().append(this._generateHTML(inst)).find("iframe.ui-timepicker-cover").css({left:-borders[0],top:-borders[1],width:inst.tpDiv.outerWidth(),height:inst.tpDiv.outerHeight()}).end().find(".ui-timepicker td a").bind("mouseout",function(){$(this).removeClass("ui-state-hover");if(this.className.indexOf("ui-timepicker-prev")!=-1){$(this).removeClass("ui-timepicker-prev-hover")}if(this.className.indexOf("ui-timepicker-next")!=-1){$(this).removeClass("ui-timepicker-next-hover")}}).bind("mouseover",function(){if(!self._isDisabledTimepicker(inst.inline?inst.tpDiv.parent()[0]:inst.input[0])){$(this).parents(".ui-timepicker-calendar").find("a").removeClass("ui-state-hover");$(this).addClass("ui-state-hover");if(this.className.indexOf("ui-timepicker-prev")!=-1){$(this).addClass("ui-timepicker-prev-hover")}if(this.className.indexOf("ui-timepicker-next")!=-1){$(this).addClass("ui-timepicker-next-hover")}}}).end().find("."+this._dayOverClass+" a").trigger("mouseover").end()},_generateHTML:function(inst){var h,m,html="";var showPeriod=(this._get(inst,"showPeriod")==true);var showLeadingZero=(this._get(inst,"showLeadingZero")==true);var showMinutesLeadingZero=(this._get(inst,"showMinutesLeadingZero")==true);var amPmText=this._get(inst,"amPmText");html='<div id="ui-timepicker-hours" >';html+='<div class="ui-timepicker-title ui-widget-header ui-helper-clearfix ui-corner-all">'+this._get(inst,"hourText")+"</div>";html+='<table class="ui-timepicker">';html+='<tr><th rowspan="2">'+amPmText[0]+"</th>";for(h=0;h<=5;h++){html+=this._generateHTMLHourCell(inst,h,(h==0)&&showPeriod?"12":(showLeadingZero?"0"+h.toString():h.toString()))}html+="</tr><tr>";for(h=6;h<=11;h++){html+=this._generateHTMLHourCell(inst,h,(h<10)&&showLeadingZero?"0"+h.toString():h.toString())}html+='<tr><th rowspan="2">'+amPmText[1]+"</th>";for(h=12;h<=17;h++){html+=this._generateHTMLHourCell(inst,h,(h>12)&&showPeriod?(h-12).toString():h.toString())}html+="</tr><tr>";for(h=18;h<=23;h++){html+=this._generateHTMLHourCell(inst,h,showPeriod?(h-12).toString():h.toString())}html+="</tr></table></div>";html+='<div id="ui-timepicker-minutes">';html+='<div class="ui-timepicker-title ui-widget-header ui-helper-clearfix ui-corner-all">'+this._get(inst,"minuteText")+"</div>";html+='<table class="ui-timepicker">';html+="<tr>";for(m=0;m<15;m+=5){html+=this._generateHTMLMinuteCell(inst,m,(m<10)&&showMinutesLeadingZero?"0"+m.toString():m.toString())}html+="</tr><tr>";for(m=15;m<30;m+=5){html+=this._generateHTMLMinuteCell(inst,m,m.toString())}html+="</tr><tr>";for(m=30;m<45;m+=5){html+=this._generateHTMLMinuteCell(inst,m,m.toString())}html+="</tr><tr>";for(m=45;m<60;m+=5){html+=this._generateHTMLMinuteCell(inst,m,m.toString())}html+="</tr></table></div>";html+='<div style="clear: both"></div>';return html},_generateHTMLHourCell:function(inst,hour,displayText){var html='<td onclick="TP_jQuery_'+tpuuid+".timepicker.selectHours('#"+inst.id+"', "+hour.toString()+', this ); return false;" ondblclick="TP_jQuery_'+tpuuid+".timepicker.selectHours('#"+inst.id+"', "+hour.toString()+', this, true ); return false;" ><a href="#" class="ui-state-default '+(hour==inst.hours?"ui-state-active":"")+'">'+displayText+"</a></td>";return html},_generateHTMLMinuteCell:function(inst,minute,displayText){var html='<td onclick="TP_jQuery_'+tpuuid+".timepicker.selectMinutes('#"+inst.id+"', "+minute.toString()+', this ); return false;" ondblclick="TP_jQuery_'+tpuuid+".timepicker.selectMinutes('#"+inst.id+"', "+minute.toString()+', this, true ); return false;" ><a href="#" class="ui-state-default '+(minute==inst.minutes?"ui-state-active":"")+'" >'+displayText+"</a></td>";return html},_isDisabledTimepicker:function(target){if(!target){return false}for(var i=0;i<this._disabledInputs.length;i++){if(this._disabledInputs[i]==target){return true}}return false},_checkOffset:function(inst,offset,isFixed){var tpWidth=inst.tpDiv.outerWidth();var tpHeight=inst.tpDiv.outerHeight();var inputWidth=inst.input?inst.input.outerWidth():0;var inputHeight=inst.input?inst.input.outerHeight():0;var viewWidth=document.documentElement.clientWidth+$(document).scrollLeft();var viewHeight=document.documentElement.clientHeight+$(document).scrollTop();offset.left-=(this._get(inst,"isRTL")?(tpWidth-inputWidth):0);offset.left-=(isFixed&&offset.left==inst.input.offset().left)?$(document).scrollLeft():0;offset.top-=(isFixed&&offset.top==(inst.input.offset().top+inputHeight))?$(document).scrollTop():0;offset.left-=Math.min(offset.left,(offset.left+tpWidth>viewWidth&&viewWidth>tpWidth)?Math.abs(offset.left+tpWidth-viewWidth):0);offset.top-=Math.min(offset.top,(offset.top+tpHeight>viewHeight&&viewHeight>tpHeight)?Math.abs(tpHeight+inputHeight):0);return offset},_findPos:function(obj){var inst=this._getInst(obj);var isRTL=this._get(inst,"isRTL");while(obj&&(obj.type=="hidden"||obj.nodeType!=1)){obj=obj[isRTL?"previousSibling":"nextSibling"]}var position=$(obj).offset();return[position.left,position.top]},_getBorders:function(elem){var convert=function(value){return{thin:1,medium:2,thick:3}[value]||value};return[parseFloat(convert(elem.css("border-left-width"))),parseFloat(convert(elem.css("border-top-width")))]},_checkExternalClick:function(event){if(!$.timepicker._curInst){return}var $target=$(event.target);if($target[0].id!=$.timepicker._mainDivId&&$target.parents("#"+$.timepicker._mainDivId).length==0&&!$target.hasClass($.timepicker.markerClassName)&&!$target.hasClass($.timepicker._triggerClass)&&$.timepicker._timepickerShowing&&!($.timepicker._inDialog&&$.blockUI)){$.timepicker._hideTimepicker()}},_hideTimepicker:function(input){var inst=this._curInst;if(!inst||(input&&inst!=$.data(input,PROP_NAME))){return}if(this._timepickerShowing){var showAnim=this._get(inst,"showAnim");var duration=this._get(inst,"duration");var postProcess=function(){$.timepicker._tidyDialog(inst);this._curInst=null};if($.effects&&$.effects[showAnim]){inst.tpDiv.hide(showAnim,$.timepicker._get(inst,"showOptions"),duration,postProcess)}else{inst.tpDiv[(showAnim=="slideDown"?"slideUp":(showAnim=="fadeIn"?"fadeOut":"hide"))]((showAnim?duration:null),postProcess)}if(!showAnim){postProcess()}var onClose=this._get(inst,"onClose");if(onClose){onClose.apply((inst.input?inst.input[0]:null),[(inst.input?inst.input.val():""),inst])}this._timepickerShowing=false;this._lastInput=null;if(this._inDialog){this._dialogInput.css({position:"absolute",left:"0",top:"-100px"});if($.blockUI){$.unblockUI();$("body").append(this.tpDiv)}}this._inDialog=false}},_tidyDialog:function(inst){inst.tpDiv.removeClass(this._dialogClass).unbind(".ui-timepicker")},_getInst:function(target){try{return $.data(target,PROP_NAME)}catch(err){throw"Missing instance data for this timepicker"}},_get:function(inst,name){return inst.settings[name]!==undefined?inst.settings[name]:this._defaults[name]},_setTimeFromField:function(inst){if(inst.input.val()==inst.lastVal){return}var timeVal=inst.lastVal=inst.input?inst.input.val():null;var time=this.parseTime(inst,timeVal);inst.hours=time.hours;inst.minutes=time.minutes},parseTime:function(inst,timeVal){var retVal=new Object();retVal.hours=-1;retVal.minutes=-1;var timeSeparator=this._get(inst,"timeSeparator");var amPmText=this._get(inst,"amPmText");var p=timeVal.indexOf(timeSeparator);if(p==-1){return retVal}retVal.hours=parseInt(timeVal.substr(0,p),10);retVal.minutes=parseInt(timeVal.substr(p+1),10);var showPeriod=(this._get(inst,"showPeriod")==true);if(retVal.hours<12&&showPeriod){var timeValUpper=timeVal.toUpperCase();if(timeValUpper.indexOf(amPmText[1].toUpperCase())!=-1){retVal.hours+=12}}return retVal},_optionTimepicker:function(target,name,value){var inst=this._getInst(target);if(arguments.length==2&&typeof name=="string"){return(name=="defaults"?$.extend({},$.timepicker._defaults):(inst?(name=="all"?$.extend({},inst.settings):this._get(inst,name)):null))}var settings=name||{};if(typeof name=="string"){settings={};settings[name]=value}if(inst){if(this._curInst==inst){this._hideTimepicker()}var date=this._getDateTimepicker(target,true);extendRemove(inst.settings,settings);this._attachments($(target),inst);this._autoSize(inst)}},selectHours:function(id,newHours,td,fromDoubleClick){var target=$(id);var inst=this._getInst(target[0]);$("#ui-timepicker-hours a").removeClass("ui-state-active");$(td).children("a").addClass("ui-state-active");inst.hours=newHours;this._updateSelectedValue(inst);inst._hoursClicked=true;if((inst._minutesClicked)||(fromDoubleClick)){$.timepicker._hideTimepicker()}},selectMinutes:function(id,newMinutes,td,fromDoubleClick){var target=$(id);var inst=this._getInst(target[0]);$("#ui-timepicker-minutes a").removeClass("ui-state-active");$(td).children("a").addClass("ui-state-active");inst.minutes=newMinutes;this._updateSelectedValue(inst);inst._minutesClicked=true;if((inst._hoursClicked)||(fromDoubleClick)){$.timepicker._hideTimepicker()}},_updateSelectedValue:function(inst){if((inst.hours<0)||(inst.hours>23)){inst.hours=12}if((inst.minutes<0)||(inst.minutes>59)){inst.minutes=0}var period="";var showPeriod=(this._get(inst,"showPeriod")==true);var showLeadingZero=(this._get(inst,"showLeadingZero")==true);var amPmText=this._get(inst,"amPmText");var displayHours=inst.hours;if(showPeriod){if(inst.hours<12){period=amPmText[0]}else{period=amPmText[1];if(displayHours>12){displayHours-=12}}}var h=displayHours.toString();if(showLeadingZero&&(displayHours<10)){h="0"+h}var m=inst.minutes.toString();if(inst.minutes<10){m="0"+m}var newTime=h+this._get(inst,"timeSeparator")+m;if(period.length>0){newTime+=" "+period}if(inst.input){inst.input.val(newTime)}var onSelect=this._get(inst,"onSelect");if(onSelect){onSelect.apply((inst.input?inst.input[0]:null),[newTime,inst])}return newTime}});$.fn.timepicker=function(options){if(!$.timepicker.initialized){$(document).mousedown($.timepicker._checkExternalClick).find("body").append($.timepicker.tpDiv);$.timepicker.initialized=true}var otherArgs=Array.prototype.slice.call(arguments,1);if(typeof options=="string"&&(options=="isDisabled"||options=="getDate"||options=="widget")){return $.timepicker["_"+options+"Datepicker"].apply($.timepicker,[this[0]].concat(otherArgs))}if(options=="option"&&arguments.length==2&&typeof arguments[1]=="string"){return $.timepicker["_"+options+"Datepicker"].apply($.timepicker,[this[0]].concat(otherArgs))}return this.each(function(){typeof options=="string"?$.timepicker["_"+options+"Datepicker"].apply($.timepicker,[this].concat(otherArgs)):$.timepicker._attachTimepicker(this,options)})};function extendRemove(target,props){$.extend(target,props);for(var name in props){if(props[name]==null||props[name]==undefined){target[name]=props[name]}}return target}$.timepicker=new Timepicker();$.timepicker.initialized=false;$.timepicker.uuid=new Date().getTime();$.timepicker.version="1.8.6";window["TP_jQuery_"+tpuuid]=$})(jQuery);
