Advertisement
konyakov

Untitled

May 9th, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /**
  3.  
  4. Author: Robert Hashemian
  5.  
  6. http://www.hashemian.com/
  7.  
  8. You can use this code in any manner so long as the author's
  9.  
  10. name, Web address and this disclaimer is kept intact.
  11.  
  12. **/
  13. function calcage(secs, num1, num2) {
  14.  
  15.     s = ((Math.floor(secs / num1)) % num2).toString();
  16.  
  17.     if (LeadingZero && s.length < 2)
  18.  
  19.     s = "0" + s;
  20.  
  21.     return "<b>" + s + "</b>";
  22.  
  23. }
  24.  
  25.  
  26.  
  27. function CountBack(secs) {
  28.  
  29.     if (secs < 0) {
  30.  
  31.         document.getElementById("cntdwn").innerHTML = FinishMessage;
  32.  
  33.         return;
  34.  
  35.     }
  36.  
  37.     DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs, 86400, 100000));
  38.  
  39.     DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs, 3600, 24));
  40.  
  41.     DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs, 60, 60));
  42.  
  43.     DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs, 1, 60));
  44.  
  45.  
  46.  
  47.     document.getElementById("cntdwn").innerHTML = DisplayStr;
  48.  
  49.     if (CountActive)
  50.  
  51.     setTimeout("CountBack(" + (secs + CountStepper) + ")", SetTimeOutPeriod);
  52.  
  53. }
  54.  
  55.  
  56.  
  57. function putspan(backcolor, forecolor) {
  58.  
  59.     document.write("<span id='cntdwn' style='background-color:" + backcolor +
  60.  
  61.     "; color:" + forecolor + "'></span>");
  62.  
  63. }
  64.  
  65.  
  66.  
  67. if (typeof (BackColor) == "undefined")
  68.  
  69. BackColor = "transparent";
  70.  
  71. if (typeof (ForeColor) == "undefined")
  72.  
  73. ForeColor = "#414141";
  74.  
  75. if (typeof (TargetDate) == "undefined")
  76.  
  77. TargetDate = "05/09/2015 10:00 AM"; //mm dd yyyy
  78. if (typeof (DisplayFormat) == "undefined")
  79.  
  80. DisplayFormat = "%%D%% <span class=\"days\">Days</span> %%H%% <span class=\"hours\">Hours</span> %%M%% <span class=\"minutes\">Minutes</span> <span class=\"sec-number\">%%S%%</span> <span class=\"seconds\">Seconds</span>";
  81.  
  82. if (typeof (CountActive) == "undefined")
  83.  
  84. CountActive = true;
  85.  
  86. if (typeof (FinishMessage) == "undefined")
  87.  
  88. FinishMessage = "Happy Victory Day! Hooray!";
  89.  
  90. if (typeof (CountStepper) != "number")
  91.  
  92. CountStepper = -1;
  93.  
  94. if (typeof (LeadingZero) == "undefined")
  95.  
  96. LeadingZero = true;
  97.  
  98.  
  99.  
  100.  
  101.  
  102. CountStepper = Math.ceil(CountStepper);
  103.  
  104. if (CountStepper == 0)
  105.  
  106. CountActive = false;
  107.  
  108. var SetTimeOutPeriod = (Math.abs(CountStepper) - 1) * 1000 + 990;
  109.  
  110. putspan(BackColor, ForeColor);
  111.  
  112. var dthen = new Date(TargetDate);
  113.  
  114. var dnow = new Date();
  115.  
  116. if (CountStepper > 0)
  117.  
  118. ddiff = new Date(dnow - dthen);
  119.  
  120. else ddiff = new Date(dthen - dnow);
  121.  
  122. gsecs = Math.floor(ddiff.valueOf() / 1000);
  123.  
  124. CountBack(gsecs);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement