Advertisement
petromaxa

Untitled

Feb 16th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. var Timer;
  2. var TotalSeconds;
  3.  
  4.  
  5. function CreateTimer(TimerID, Time) {
  6. Timer = document.getElementById(TimerID);
  7. TotalSeconds = Time;
  8.  
  9. UpdateTimer();
  10. window.setTimeout("Tick()", 1000);
  11. }
  12.  
  13. function Tick() {
  14. if (TotalSeconds <= 0)
  15. {
  16. CalculateResults();
  17. return;
  18. }
  19.  
  20. TotalSeconds -= 1;
  21. UpdateTimer();
  22. window.setTimeout("Tick()", 1000);
  23. }
  24.  
  25. function UpdateTimer() {
  26. var Seconds = TotalSeconds;
  27.  
  28. var Days = Math.floor(Seconds / 86400);
  29. Seconds -= Days * 86400;
  30.  
  31. var Hours = Math.floor(Seconds / 3600);
  32. Seconds -= Hours * (3600);
  33.  
  34. var Minutes = Math.floor(Seconds / 60);
  35. Seconds -= Minutes * (60);
  36.  
  37.  
  38. var TimeStr = ((Days > 0) ? Days + " days " : "") + LeadingZero(Hours) + ":" + LeadingZero(Minutes) + ":" + LeadingZero(Seconds);
  39.  
  40. Timer.innerHTML = TimeStr;
  41. }
  42.  
  43. function LeadingZero(Time) {
  44.  
  45. return (Time < 10) ? "0" + Time : + Time;
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement