if(wf.Calendar==undefined){wf.Calendar={}
}Object.extend(Date.prototype,{baseYear:0,clone:function(){var a=new Date(this.getTime());
a.baseYear=this.baseYear;
return a
},getRegimenWeek:function(){return this.getMonth()*4+Math.ceil(this.getDate()/7)
},getRegimenYear:function(){return this.getFullYear()-(this.baseYear?this.baseYear:0)
},getRegimenDay:function(){var a=this.getFullYear()-this.baseYear-1;
return a*28*12+this.getMonth()*28+this.getDate()
},urlParams:function(){return{month:this.getMonth()+1,day:this.getDate(),year:this.getRegimenYear()}
},setBaseYear:function(a){this.baseYear=a;
return this
}});
Date.regimenBaseYear=0;
Date.regimenDayToDate=function(b){var d=Math.floor(b/(28*12))+Date.regimenBaseYear+1,a=Math.ceil(b/28),e=b%28==0?28:b%28,c=new Date(a+"/"+e+"/"+d);
c.setBaseYear(Date.regimenBaseYear);
return c
};
wf.Calendar.Base=Class.create({_processingTemplate:'<span class="processing">Loading</span>',_dayTemplate:'<div class="date">#{date}</div><div class="day" id="#{id}"></div>',initialize:function(b,d){this._container=$(b);
this.options=$H({start_date:null,days:d.is_regimen?28:42}).update(d);
this._panes=$H();
this._lastRequestId=0;
this._initializeDates();
this._initializeFormats();
this._initialAuth=wf.User.isAuth;
this._isBrowsing=true;
this._detailsContainer=this._container.down("div.details");
this.draw();
this.selectDate(this.dates.selected);
var a=this._container.id,c=this._container.down("div.navigation div.controls button.today"),e=this._detailsContainer.select(".actions.pane .showPane");
this.pendingScrollId=this.options.get("pending_scroll_id");
this._container.observe("calendarPane:close",this.onCalendarPaneClose.bind(this));
this._container.down("form.dateJump").observe("submit",this.onDateJumpSubmit.bind(this));
this._container.down("div.navigation div.controls button.previous").observe("click",this.onPreviousMonthClick.bind(this));
this._container.down("div.navigation div.controls button.next").observe("click",this.onNextMonthClick.bind(this));
if(c){c.observe("click",this.onTodayClick.bind(this))
}this._detailsContainer.setStyle({minHeight:this._container.down(".days").getHeight()+"px"});
e.invoke("observe","click",this.onShowPaneClick.bind(this));
e.invoke("observe","mouseover",this.onShowPaneMouseover.bind(this));
e.invoke("observe","mouseout",this.onShowPaneMouseout.bind(this));
this._detailsContainer.down("a.permalink.white").observe("click",function(){this.reload()
}.bind(this));
wf.Events.observe("units:update",a,this.reload.bind(this));
this.configure()
},_initializeDates:function(){Date.regimenBaseYear=this.options.get("base_year")?this.options.get("base_year"):0;
this.dates={};
$H(this.options.get("dates")).each(function(a){this.dates[a.key]=(new Date(a.value)).setBaseYear(this.options.get("base_year")).removeTime()
},this);
this.dates.month=this.dates.selected.clone()
},_initializeFormats:function(){if(this._dayItemFormats){for(var a in this._dayItemFormats){this._dayItemFormats[a]=new Template(this._dayItemFormats[a])
}}},onDateClick:function(c){var a=Event.findElement(c,"td").down("div.day").id.replace("calendar_date_",""),b=null;
if(parseInt(a,10)==a){b=Date.regimenDayToDate(a)
}else{b=Date.dbStringToDate(a)
}this.selectDate(b)
},onShowPaneClick:function(a){this.showPane(this.getPaneClassFromShowPaneEvent(a))
},onShowPaneMouseover:function(c){var b=this.getPaneClassFromShowPaneEvent(c),a=this._container.down(".description."+b);
this._container.select(".actions.pane .description").invoke("hide");
if(a){a.show()
}},onShowPaneMouseout:function(){this._container.select(".actions.pane .description").invoke("hide")
},onCalendarPaneClose:function(){this._isBrowsing=true;
this.refresh()
},onDateJumpSubmit:function(c){c.stop();
var d=Event.element(c).serialize(true),b=d["date[year]"]?parseInt(d["date[year]"],10)+Date.regimenBaseYear:this.dates.selected.getFullYear(),a=this.dates.selected.clone();
a.setFullYear(b,d["date[month]"]-1,1);
if(this.isValidDate(a)){this.selectDate(a)
}else{alert("Invalid date.")
}},onNextMonthClick:function(){this.changeMonth(1)
},onPreviousMonthClick:function(){this.changeMonth(-1)
},onTodayClick:function(){this.selectDate(this.dates.today)
},onLoadDaysComplete:function(g){if(g.request.options.requestId&&g.request.options.requestId!=this._lastRequestId){return
}var f=g.responseText.evalJSON(),c=this.getDayItem.bind(this),e=this._container.down("tr.dates td").getHeight()-this._container.down("tr.dates td div.date").getHeight()+parseInt(this.options.get("day_padding"),10),d=this.onMoreClick.bind(this),b=null;
for(b in f){var a=this.getCalendarDay(b);
if(!a){continue
}a.update("");
f[b].each(function(h){a.insert({bottom:c(h)})
})
}this._container.select("div.day").each(function(h){if(h.offsetHeight>e){var i=h.childElements(),l=i.length;
while(h.offsetHeight>e){i[--l].hide()
}var k=new Element("div",{className:"more "}),j=new Element("a",{href:"javascript:;",className:"more"}).update("+"+(i.length-l)+" more");
k.insert(j);
h.insert({bottom:k});
j.observe("click",d)
}});
this.refresh()
},onMoreClick:function(b){var a=Event.element(b);
b.stop();
a.up().siblings().invoke("show");
a.hide()
},configure:function(){},draw:function(){var c=this.dates.selected,d=this.options.get("is_regimen")?"Month "+(c.getMonth()+1)+(this.dates.max.getRegimenYear()>1?", Year "+c.getRegimenYear():""):c.format("month");
this._container.down(".calendarTitle").update(d);
var b=this.dates.month.clone(),a=this.dates.month.clone();
b.setMonth(b.getMonth()+1);
a.setMonth(a.getMonth()-1);
this._container.down("div.navigation div.controls button.next").setHasClassName("disabled",!this.isValidMonth(b));
this._container.down("div.navigation div.controls button.previous").setHasClassName("disabled",!this.isValidMonth(a));
this.drawCalendar();
this.loadDays()
},drawCalendar:function(){var d=this._container.down("table.calendarGrid tbody"),b=0,c=this.dates.month.clone(),a=this.onDateClick.bind(this),f=this.options.get("is_regimen"),e=null;
d.update("");
c.setDate(1);
if(!f){c.setDate(1-c.getDay()-(c.getDay()<3?7:0))
}else{c.setDate(1)
}this.dates.first=c.clone();
if(!f){d.insert('<tr class="days"><th>'+Date.locale.en.week_names.join("</th><th>")+"</th></tr>")
}for(b;
b<this.options.get("days");
b++){if(b%7==0){if(e){d.insert(e)
}if(f){d.insert('<tr class="week"><th colspan="7">Week '+c.getRegimenWeek()+"</th></tr>")
}e=new Element("tr").addClassName("dates")
}var g=new Element("td");
if(c.isSameDay(this.dates.today)){g.addClassName("today")
}if(this.isValidDate(c)){g.addClassName(c.getMonth()==this.dates.month.getMonth()?"inmonth":"outmonth").addClassName("valid");
g.observe("click",a)
}else{g.addClassName("invalid")
}g.insert(this._dayTemplate.interpolate({id:this.getCalendarDayId(c),date:c.getDate()}));
e.insert(g);
c.setDate(c.getDate()+1)
}this.dates.last=c.clone();
this.dates.last.setDate(c.getDate()-1);
d.insert(e)
},getDayItem:function(b){var c=b.format,a="get"+b.format.ucfirst()+"DayItem";
if(this[a]){return this[a](b)
}if(this._dayItemFormats[c]){return this._dayItemFormats[c].evaluate(b)
}return""
},getPaneClassFromShowPaneEvent:function(b){var a=Event.element(b),c=a.hasClassName("showPane")?a:a.up(".showPane");
return $H(this.options.get("button_list")).keys().find(function(d){return c.hasClassName(d)
})
},showPane:function(b){this._panes.values().invoke("hide");
if(this._panes.get(b)){this._panes.get(b).show()
}else{var a=this._container.down("div.details div.actions")||this._container.down("div.details h3.date"),c=new Element("div").update(this._processingTemplate);
a.insert({after:c});
new Ajax.Updater({success:a},this.options.get("button_list")[b].interpolate(this.dates.selected.urlParams()),{method:"get",evalScripts:true,insertion:"after",onComplete:function(){c.remove();
this._panes.set(b,this.createPane(b))
}.bind(this)})
}this._isBrowsing=false;
this.refresh()
},createPane:function(a){},changeMonth:function(d){var b=this.dates.month,a=this.dates.selected.clone(),c=b.clone();
c.setMonth(c.getMonth()+d);
if(!this.isValidMonth(c)){return
}if(a.getMonth()<b.getMonth()){a.setDate(1)
}if(a.getDate()>c.getDaysInMonth()){a.setDate(c.getDaysInMonth())
}if(a.getMonth()!=c.getMonth()){a.setMonth(c.getMonth())
}if(a.getFullYear()!=c.getFullYear()){a.setFullYear(c.getFullYear())
}this.dates.selected=a;
this.dates.month=c;
this.draw();
this.selectDate(a)
},loadDays:function(){this._detailsContainer.select("div.detailDay").invoke("remove");
if(this.isLoadingDays()&&this._lastLoadDaysRequest.transport.abort){this._lastLoadDaysRequest.transport.abort()
}var a=this.dates.first.urlParams();
a.days=this.options.get("days");
this._lastRequestId++;
this._lastLoadDaysRequest=new Ajax.Request(this.options.get("day_list_url").interpolate(a),{method:"get",onComplete:this.onLoadDaysComplete.bind(this),requestId:this._lastRequestId})
},loadDay:function(a){if(!this.isLoadingDays()){this.getCalendarDay(a).update("&nbsp;");
var b=a.urlParams();
b.days=1;
new Ajax.Request(this.options.get("day_list_url").interpolate(b),{method:"get",onComplete:this.onLoadDaysComplete.bind(this)})
}},isLoadingDays:function(){return this._lastLoadDaysRequest&&this._lastLoadDaysRequest.transport.readyState!=4
},isValidDate:function(a){return a>=this.dates.min&&a<=this.dates.max
},isValidMonth:function(a){return a.format("Y-m")>=this.dates.min.format("Y-m")&&a.format("Y-m")<=this.dates.max.format("Y-m")
},isOnCalendar:function(a){return a>=this.dates.first&&a<=this.dates.last
},getCalendarDay:function(a){return $(this.getCalendarDayId(a))
},getCalendarDayId:function(a){return this.options.get("is_regimen")?"calendar_date_"+(a instanceof Date?a.getRegimenDay():a):"calendar_date_"+(a instanceof Date?a.format("db"):a)
},getDetailDayId:function(a){return"calendar_detail_day_"+a.format("db")
},showDetailDay:function(b){if(this.isLoadingDays()){return
}var a=this.getCalendarDay(b);
if(!a.innerHTML.blank()){var c=this.getDetailDayId(b);
if(!$(c)){this._detailsContainer.insert({bottom:new Element("div",{id:c,className:"detailDay"}).update(this._processingTemplate)});
new Ajax.Request(this.getShowDetailDayUrl().interpolate(b.urlParams()),{method:"get",onComplete:function(d){if($(c)){$(c).update(d.responseText)
}if(this.pendingScrollId&&$(this.pendingScrollId)){$(this.pendingScrollId).scrollTo()
}this.pendingScrollId=null
}.bind(this)})
}$(c).show()
}},getShowDetailDayUrl:function(){return this.options.get("calendar_detail_day_url")
},removeDetailDay:function(b){var a=$(this.getDetailDayId(b));
if(a){a.remove()
}},reload:function(a){if(a==undefined){a=this.dates.selected
}window.location=this.options.get("calendar_show_url").interpolate(a.urlParams())
},setDate:function(a){if(!this.isOnCalendar(a)){if(this.isValidDate(a)){this.dates.selected=a.clone();
this.dates.month=a.clone();
this.draw()
}else{return
}}else{this.dates.selected=a.clone()
}},selectDate:function(b){this.setDate(b);
var a=this.getCalendarDay(this.dates.selected);
this._container.select(".dates td").invoke("removeClassName","selected");
a.up("td").addClassName("selected");
this.refreshDetailTitle();
this.refresh()
},reloadAndSelectDate:function(a,b){this.removeDetailDay(a);
this.loadDay(a);
this._isBrowsing=b;
this.selectDate(a)
},refreshDetailTitle:function(){this._detailsContainer.down("h3.date").update(this.getDetailTitle())
},getDetailTitle:function(){if(this.options.get("is_regimen")){var b=this.getCalendarDay(this.dates.selected).up("tr.dates").previous("tr.week").down("th").innerHTML.replace(/\D/g,""),a=this.dates.selected.getDate()%7;
return"Week "+b+", Day "+(a?a:7)
}return this.dates.selected.format("day_long")
},getHash:function(a){return this.options.get("is_regimen")?a.getRegimenDay():a.format("m/d/Y")
},refresh:function(){if(!this._initialAuth&&wf.User.isAuth){this.reload()
}if(this._isBrowsing){this._panes.values().invoke("hide")
}if(this._detailsContainer.down(".actions")){this._detailsContainer.down(".actions").setIsDisplayed(this._isBrowsing)
}this._container.select("div.detailDay").invoke("hide");
if(this._isBrowsing){this.showDetailDay(this.dates.selected)
}this._panes.values().invoke("setDate",this.dates.selected);
this.doRefresh()
},doRefresh:function(){}});
wf.Calendar.Pane=Class.create({_class:"pane",initialize:function(a,b){b.date=b.date.clone();
this._container=$(a);
this.options=$H(b);
this._date=b.date;
this._container.down("a.dismiss").observe("click",this.close.bind(this));
this.configure()
},configure:function(){},close:function(){this._container.hide();
this._container.fire("calendarPane:close",this._class)
},setDate:function(a){this._date=a;
this._container.select("form").invoke("fire","calendarPane:setDate",a)
},show:function(){this._container.show()
},hide:function(){this._container.hide()
}});
wf.Calendar.FilterPane=Class.create(wf.Calendar.Pane,{_class:"filterPane",configure:function(){this._showingFilter=true;
this._container.observe("form:cancel",this.showFilter.bind(this));
this._container.observe("filter:select",this.onFilterSelect.bind(this))
},onFilterSelect:function(a){if(this._showingFilter){this.hideFilter();
this.doFilterSelectAction(a.memo)
}},doFilterSelectAction:function(){},showFilter:function(){this._showingFilter=true;
this._container.down("form.filter").show();
this.hideProcessing()
},hideFilter:function(){this._showingFilter=false;
this._container.down("form.filter").hide()
},showProcessing:function(){if(!this._processing){this._processing=wf.Util.processing("Loading")
}this._container.insert({bottom:this._processing})
},hideProcessing:function(){if(this._processing){this._processing.hide()
}},close:function($super){$super();
this.showFilter()
}});
wf.Calendar.ExerciseFilterPane=Class.create(wf.Calendar.FilterPane,{_class:"exerciseFilterPane",configure:function($super){$super();
this._container.down("button.exerciseNew").observe("click",this.onExerciseNewClick.bind(this));
wf.Events.observe("exercise:create",this._container.id,this.onExerciseCreate.bind(this))
},onExerciseNewClick:function(){this._exerciseNewPopup=new wf.Popup.Ajax(this.options.get("exercises_custom_new_url"),{},{method:"get"})
},onExerciseCreate:function(){if(this._exerciseNewPopup){this._exerciseNewPopup.close()
}},showForm:function(a,b){this.cleanUpForms();
this.hideFilter();
this.showProcessing();
new Ajax.Updater(this._container,a,{parameters:b,method:"get",evalScripts:true,insertion:"bottom",onComplete:this.hideProcessing.bind(this)})
},hideFilter:function($super){$super();
this._container.down("div.exerciseNew").hide()
},showFilter:function($super){$super();
this._container.down("div.exerciseNew").show();
this.cleanUpForms()
},cleanUpForms:function(){}});
if(wf.Calendar==undefined){wf.Calendar={}
}wf.Calendar.Profile=Class.create(wf.Calendar.Base,{_dayItemFormats:{history:'<div class="item history"><span class="log black icon12"></span><div class="titleWrapper"><span class="title" title="#{title}">#{title}</span></div><div class="text">#{text}</div></div>',weightGoal:'<div class="item weightGoal"><span class="title" title="#{title}">#{title}</span><div class="text">#{text}</div></div>',weight:'<div class="weight"><span class="weight black icon12"></span>#{weight}</div>',icon:'<span class="#{icon} icon12" title="#{title}"></span>',multiRowTitle:'<span class="#{icon} icon12"></span><div class="titleWrapper"><span class="title" title="#{title}">#{title}</span></div>',multiRowText:'<div class="text" title="#{text}">#{text}</div>'},configure:function(){this._actionsDiv=this._container.down("div.actions");
var a=this._container.id,c=this.onObjectCreate.bind(this),b=this.onObjectDelete.bind(this);
this._container.observe("weight:edit",this.onWeightEdit.bind(this));
this._container.observe("history:rename",this.onHistoryRename.bind(this));
wf.Events.observe("plannedWorkout:create",a,c);
wf.Events.observe("plannedWorkout:delete",a,this.onPlannedWorkoutDelete.bind(this));
wf.Events.observe("history:create",a,c);
wf.Events.observe("history:delete",a,b);
wf.Events.observe("history:update",a,this.onHistoryUpdate.bind(this));
wf.Events.observe("weight:create",a,c);
wf.Events.observe("weight:delete",a,b);
wf.Events.observe("weightGoal:createOrUpdate",a,this.onWeightGoalCreateOrUpdate.bind(this));
wf.Events.observe("weightGoal:delete",a,this.onWeightGoalDelete.bind(this))
},onCalendarPaneClose:function($super,a){if(a.memo=="bodyPane"&&this._actionsDiv){this._actionsDiv.down("button.bodyPane").show()
}$super(a)
},onWeightEdit:function(a){this.showPane("bodyPane");
if(this._container.down("div.bodyPane")&&a.memo.weight){this._container.down('form.weight input[id$="_weight_quantity"]').setValue(a.memo.weight)
}},onHistoryRename:function(b){var a=Date.dbStringToDate(b.memo.ProfileDay.date);
this.loadDay(a)
},onPlannedWorkoutDelete:function(a){var b=a.program_day_date;
if(b){b=Date.dbStringToDate(b);
this.removeDetailDay(b);
this.loadDay(b)
}this.onObjectDelete(a)
},onObjectDelete:function(b){if(b.profile_id==this.options.get("profile_id")){var c=b.ProfileDay.date||b.date,a=Date.dbStringToDate(c);
this.loadDay(a);
this.selectDate(a)
}},onObjectCreate:function(b){var c=b.ProfileDay.date||b.date,a=Date.dbStringToDate(c);
if(!this._initialAuth){this.reload(a);
return
}if(!this.isOnCalendar(a)){this.setDate(a)
}else{if(b.program_day_workout_id||b.program_day_id){this.loadDays()
}}this.reloadAndSelectDate(a,true)
},onHistoryUpdate:function(b){if(b.profile_id==this.options.get("profile_id")){if(b.date_old&&b.date_old!=b.ProfileDay.date){var a=Date.dbStringToDate(b.date_old);
this.loadDay(a);
this.removeDetailDay(a)
}this.onObjectCreate(b)
}},onWeightGoalDelete:function(b){var a=Date.dbStringToDate(b.date);
if(this.isOnCalendar(a)){this.onObjectDelete(b)
}else{var c=new Element("p").update("Your weight goal has been deleted").addClassName("success");
this._detailsContainer.down("div.actions").insert({after:c});
Element.remove.delay(3,c)
}},onWeightGoalCreateOrUpdate:function(a){if(a.old_date&&a.old_date!=a.date){var b=Date.dbStringToDate(a.old_date);
if(this.isOnCalendar(b)){this.loadDay(b);
this.removeDetailDay(b)
}}if(a.date&&this.isOnCalendar(Date.dbStringToDate(a.date))){this.onObjectCreate(a)
}else{var c=new Element("p").update("Your weight goal has been updated").addClassName("success");
this._detailsContainer.down("div.actions").insert({after:c});
Element.remove.delay(3,c)
}},loadDays:function($super){if(this.options.get("profile_id")){$super()
}},getIconHeaderDayItem:function(b){var a=new Element("div",{className:"icons clearAfter"}),c=this._dayItemFormats.icon;
b.icons.each(function(d){a.insert({bottom:c.evaluate(d)})
});
return a
},getMultiRowDayItem:function(b){var c=this._dayItemFormats,a=new Element("div",{className:"item "+b.className});
a.insert({bottom:c.multiRowTitle.evaluate(b)});
b.texts.each(function(d){a.insert({bottom:c.multiRowText.evaluate({text:d})})
});
return a
},createPane:function(b){var c=this.options,a=this._container.down("div."+b);
if(a){switch(b){case"bodyPane":return new wf.Calendar.BodyPane(a,{date:this.dates.selected,authentication_url:c.get("authentication_url")});
case"logPlanPane":return new wf.Calendar.LogPlanPane(a,{date:this.dates.selected,today:this.dates.today,authentication_url:c.get("authentication_url"),workout_scale_and_log_url:c.get("workout_scale_and_log_url"),history_and_workout_new_url:c.get("history_and_workout_new_url"),history_new_url:c.get("history_new_url")});
case"historyAndWorkoutPane":return new wf.Calendar.HistoryAndWorkoutPane(a,{date:this.dates.selected,history_and_workout_new_url:c.get("history_and_workout_new_url"),exercises_custom_new_url:c.get("exercises_custom_new_url")})
}}return null
},doRefresh:function(){var e=this.dates.selected>this.dates.today,d=this._detailsContainer.down("button.planWorkout"),b=this._detailsContainer.down("button.logWorkout"),c=this._container.down(".description .plan"),a=this._container.down(".description .log");
if(d){d.setIsDisplayed(e);
c.setIsDisplayed(e)
}if(b){b.setIsDisplayed(!e);
a.setIsDisplayed(!e)
}},showDetailDay:function($super,b){var a=$(this.getDetailDayId(b));
if(a){a.select("div.weightsShow").invoke("fire","weights:show")
}$super(b)
}});
wf.Calendar.LogPlanPane=Class.create(wf.Calendar.FilterPane,{_class:"logPlanPane",configure:function($super){$super();
this._today=this.options.get("today");
this._container.down("button.historyAndWorkoutNew").observe("click",this.onHistoryAndWorkoutNewClick.bind(this));
this._container.observe("filter:refreshComplete",this.onFilterRefreshComplete.bind(this));
var a=this._container.identify();
wf.Events.observe("history:create",a,this.showFilter.bind(this));
wf.Events.observe("plannedWorkout:error",a,this.onPlannedWorkoutError.bind(this))
},onCalendarPaneDismissClick:function($super){this._container.select("div.historyForm").invoke("remove");
$super()
},onHistoryAndWorkoutNewClick:function(){window.location=this.options.get("history_and_workout_new_url").interpolate(this._date.urlParams())
},onFilterRefreshComplete:function(){this.refreshFilterButtons()
},onPlannedWorkoutError:function(a){alert(a.error)
},setDate:function($super,a){$super(a);
var b=this.isFuture();
if(this._showingFilter){this._container.down("div.historyAndWorkoutNew").setIsDisplayed(!b)
}this._container.down("h2.plan").setIsDisplayed(b);
this._container.down("h2.log").setIsDisplayed(!b);
this.refreshFilterButtons()
},doFilterSelectAction:function(c){var b;
this.showProcessing();
if(c.action=="plan"){var d=this._container.down("form.plannedWorkout");
d.down("input.workoutId").setValue(c.id);
d.down("input.date").setValue(this._date.format());
if(wf.User.isAuth){this.planWorkout(d)
}else{var a=new wf.Popup.Ajax(this.options.get("authentication_url"),{},{method:"get"});
this.showFilter();
wf.Events.observe("user:gainAuthentication",this._container.id,function(){a.close();
this.planWorkout(d)
}.bind(this))
}}else{if(c.action=="log"){b=$H(this._date.urlParams()).update({workout_id:c.id,scaled:c.scaled?1:0});
new Ajax.Updater(this._container,this.options.get("history_new_url").interpolate(b),{method:"get",evalScripts:true,insertion:"bottom",onComplete:this.hideProcessing.bind(this)})
}else{if(c.action=="scaleAndLog"){this.showFilter();
b=$H(this._date.urlParams()).update({workout_id:c.id,workout_slug:c.slug.urlize()});
window.location=this.options.get("workout_scale_and_log_url").interpolate(b)+"?scaled=1"
}}}},planWorkout:function(a){new Ajax.Request(a.action,{parameters:a.serialize(),onSuccess:function(b){b.responseText.evalScripts();
this.showFilter()
}.bind(this)})
},hideFilter:function($super){$super();
this._container.down("div.historyAndWorkoutNew").hide()
},showFilter:function($super){$super();
this._container.down("div.historyAndWorkoutNew").setIsDisplayed(!this.isFuture());
this._container.select("div.historyForm").invoke("remove")
},isFuture:function(){return this._date>this._today
},refreshFilterButtons:function(){var a=this.isFuture();
this._container.select('div.workout button[data-action="plan"]').invoke("setIsDisplayed",a);
this._container.select('div.workout button[data-action="log"]').invoke("setIsDisplayed",!a);
this._container.select("div.workout a.scale").invoke("setIsDisplayed",!a)
}});
wf.Calendar.BodyPane=Class.create(wf.Calendar.Pane,{_class:"bodyPane",configure:function(){this._container.down("form.weight").observe("submit",this.onWeightFormSubmit.bind(this));
this._container.down("form.weightGoal").observe("submit",this.onFormSubmit.bind(this));
var b=this.onFormError.bind(this),a=this._container.id;
wf.Events.observe("weight:error",a,b);
wf.Events.observe("weightGoal:error",a,b)
},onWeightFormSubmit:function(a){Event.element(a).down('input[id$="_profile_day_id"]').setValue(this._date.format());
this.onFormSubmit(a)
},onFormSubmit:function(c){c.stop();
var b=Event.element(c);
if(wf.User.isAuth){this.submitForm(b)
}else{var a=new wf.Popup.Ajax(this.options.get("authentication_url"),{},{method:"get"});
wf.Events.observe("user:gainAuthentication",this._container.id,function(){this.submitForm(b);
a.close()
}.bind(this))
}},onFormError:function(a){alert(a.error)
},submitForm:function(a){new Ajax.Request(a.action,{parameters:a.serialize(),onSuccess:function(b){b.responseText.evalScripts()
}.bind(this)})
}});
wf.Calendar.HistoryAndWorkoutPane=Class.create(wf.Calendar.ExerciseFilterPane,{_class:"historyAndWorkoutPane",configure:function($super){$super();
wf.Events.observe("history:create",this._container.identify(),this.showFilter.bind(this))
},onExerciseCreate:function($super,a){$super(a);
this.showHistoryAndWorkoutNewForm(a)
},doFilterSelectAction:function(a){if(a.action=="log"){this.showHistoryAndWorkoutNewForm(a)
}},showHistoryAndWorkoutNewForm:function(a){this.showForm(this.options.get("history_and_workout_new_url").interpolate(this._date.urlParams()),{exercise_id:a.id})
},cleanUpForms:function(){this._container.select("div.historyAndWorkoutEmbeddedForm").invoke("remove")
}});
if(wf.Form==undefined){wf.Form={}
}wf.Form.Units=Class.create({initialize:function(b,a){this._form=$(b);
this.options=$H({success_message:false}).update(a);
this._form.select("input").invoke("observe","change",this.onUnitsChange.bindAsEventListener(this))
},onUnitsChange:function(b){var a=this.getUnitUpdateMemo(Event.element(b));
if(this.options.get("local")==false){new Ajax.Request(this._form.readAttribute("action"),{parameters:this._form.serialize(),onSuccess:this.onSuccess.bind(this)})
}else{this._form.fire("units:edit",a)
}},onSuccess:function(){wf.Events.fire("units:update");
if(this.options.get("success_message")){if(this._form.down("p.success")){this._form.down("p.success").show()
}else{var a=new Element("p").addClassName("success").update(this.options.get("success_message"));
this._form.down("legend").insert({after:a})
}}},getUnitUpdateMemo:function(b){var a={},c=$A(["weight","distance_short","distance_medium","distance_long"]).find(function(d){return b.id.match(d)
});
if(c){a.type=c;
a.unit=$F(b);
return a
}return null
}});
wf.Behavior.TabbedHeader=Class.create({initialize:function(a){this._container=$(a);
this.getTabs().invoke("observe","click",this.onTabClick.bind(this))
},getTabs:function(){return this._container.down("div.tabs > ul").select("li")
},onTabClick:function(c){var a=Event.findElement(c,"li"),d=$w(a.className).first(),b=this._container.down("div.tabContents > div."+d);
if(a.hasClassName("selected")){return
}this.getTabs().invoke("removeClassName","selected");
a.addClassName("selected");
this._container.select(".tabContent").invoke("hide");
b.show()
}});
