varj_departure=0,j_duration=0,j_arrival=0,j_dest="",j_stops=[];functionupd_journey_data(){$(".countdown").each(function(){vart=$(this).data("journey"),t=(t&&(t=t.split(";"),j_departure=parseInt(t[0]),j_arrival=parseInt(t[1]),j_duration=j_arrival-j_departure),$(this).data("dest")),e=(t&&(j_dest=t),$(this).data("route"));if(e)for(varaine=e.split("|"),j_stops=[],e){for(varn=e[a].split(";"),r=1;r<5;r++)n[r]=parseInt(n[r]);j_stops.push(n)}})}functionupd_countdown(){vart=Date.now()/1e3;t<j_departure?$(".countdown").text("Abfahrt in "+Math.round((j_departure-t)/60)+" Minuten"):0<j_arrival&&(t<j_arrival?$(".countdown").text("Ankunft in "+Math.round((j_arrival-t)/60)+" Minuten"):$(".countdown").text("Ziel erreicht"))}functionhhmm(t){vart=newDate(1e3*t),e=t.getHours(),t=t.getMinutes();return(e<10?"0"+e:e)+":"+(t<10?"0"+t:t)}functionodelay(t,e){returnt<e?" (+"+(e-t)/60+")":t==e?"":" ("+(e-t)/60+")"}functiontvly_run(e,t,a){varn='<i class="material-icons">error</i>',r=e.data("tr")?$('<tr><td colspan="'+e.data("tr")+'"><div class="progress"><div class="indeterminate"></div></div></td></tr>'):$('<div class="progress"><div class="indeterminate"></div></div>');e.hide(),e.after(r),$.post("/action",t,function(t){t.success?$(location).attr("href",t.redirect_to):(M.toast({html:n+" "+t.error}),r.remove(),a&&a(),e.append(" "+n),e.show())})}functiontvly_update(){$.get("/ajax/status_card.html",function(t){$(".statuscol").html(t),tvly_reg_handlers(),upd_journey_data(),setTimeout(tvly_update,4e4)}).fail(function(){$(".sync-failed-marker").css("display","block"),upd_countdown(),setTimeout(tvly_update,5e3)})}functiontvly_update_public(){vart;$(".publicstatuscol").each(function(){t=$(this).data("user")}),$.get("/ajax/status/"+t+".html",function(t){$(".publicstatuscol").html(t),upd_journey_data(),setTimeout(tvly_update_public,4e4)}).fail(function(){$(".sync-failed-marker").css("display","block"),upd_countdown(),setTimeout(tvly_update_public,5e3)})}functiontvly_journey_progress(){vart=Date.now()/1e3,e=0;if(0<j_duration){for(stopin1<(e=(e=1-(j_arrival-t)/j_duration)<0?0:e)&&(e=1),$(".progress .determinate").css("width",100*e+"%"),j_stops){vara=j_stops[stop][0],n=j_stops[stop][1],r=j_stops[stop][2],o=j_stops[stop][3],i=j_stops[stop][4];if(a==j_dest){$(".next-stop").html("");break}if(0!=r&&0<r-t){$(".next-stop").html(a+"<br/>"+hhmm(r)+odelay(n,r));break}if(0!=i&&0<i-t){$(".next-stop").html(a+"<br/>"+hhmm(r)+" → "+hhmm(i)+odelay(o,i));break}}setTimeout(tvly_journey_progress,5e3)}}functiontvly_reg_handlers(){$(".action-checkin").click(function(){vart=$(this),e={action:"checkin",station:t.data("station"),train:t.data("train"),dest:t.data("dest")};tvly_run(t,e)}),$(".action-checkout").click(function(){vart=$(this),e={action:"checkout",station:t.data("station"),force:t.data("force")};tvly_run(t,e,function(){t.append(" – Ohne Echtzeitdaten auschecken?"),t.data("force",!0)})}),$(".action-undo").click(function(){vart=$(this),e=Date.now()/1e3,a=parseInt(t.data("checkints")),n={action:"undo",undo_id:t.data("id")},r=!0;(r=900<e-a?confirm("Checkin wirklich rückgängig machen? Er kann ggf. nicht wiederholt werden."):r)&&tvly_run(t,n)}),$(".action-cancelled-from").click(function(){vart=$(this),e={action:"cancelled_from",station:t.data("station"),train:t.data("train")};tvly_run(t,e)}),$(".action-cancelled-to").click(function(){vart=$(this),e={action:"cancelled_to",station:t.data("station"),force:!0};tvly_run(t,e)}),$(".action-delete").click(function(){vart=$(this),e={action:"delete",id:t.data("id"),checkin:t.data("checkin"),checkout:t.data("checkout")};confirm("Diese Zugfahrt wirklich löschen? Der Eintrag wird sofort aus der Datenbank entfernt und kann nicht wiederhergestellt werden.")&&tvly_run(t,e)}),$(".action-share").click(function(){vart=$(this).data("text"),e=$(this).data("url");navigator.share?(shareObj={text:t},e&&(shareObj.url=e),navigator.share(shareObj)):(e&&(t+=" "+e),(e=document.createElement("textarea")).value=t,e.setAttribute("readonly",""),e.style.position="absolute",e.style.left="-9999px",document.body.appendChild(