Countdown v2

ship countdown timer

HTML

<div id="countdownTimer"></div>

CSS

#countdownTimer {
  padding: 20px 10px 20px 10px;
  background-color: #afc8c5
}

JavaScript

// JavaScript Document
if (document.getElementById('countdownTimer')) {
  pad = function(n, len) { // leading 0's
    var s = n.toString();
    return (new Array((len - s.length + 1)).join('0')) + s;
  };

  var timerRunning = setInterval(
    function countDown() {
      var now = new Date();
      if ((now.getDay() >= 1) && (now.getDay() <= 7)) { // Monday to Friday only
        var target = 17; // 15:00hrs is the cut-off point -------- Trying to get 6pm EST regardless of user time zone
        if (now.getHours() < target) { // would be best if could hide the whole counter if past cutoff point each day
        	var arr_parts = [];
          var hrs = (target - 1) - now.getHours();
          var mins = 59 - now.getMinutes();
          var secs = 59 - now.getSeconds();
          
          if ( hrs ) {
          	arr_parts.push( hrs );
          }
          if( mins ) {
          	arr_parts.push( pad( mins, 2 ) );
          }
          if ( secs ) {
          	arr_parts.push( pad( secs, 2 ) );
          }
          
          // number of parts to the countdown 
          // 3 = h:m:s
          // 2 = m:s
          // 1 = s
          part_length = arr_parts.length;
          
          // the biggest unit for the countdown 
          // so length of 1 means we need seconds at index 0)
          arr_units = [ 'seconds', 'minutes', 'hours' ]
          str_unit = arr_units[ part_length - 1 ];
          
          var str = 'Order within the next <strong>' 
          	+ arr_parts.join( ':' ) 
            + ' ' + str_unit
            + '</strong> to ship <strong>today</strong>.';
          document.getElementById('countdownTimer').innerHTML = str;
        }
      }
    }, 1000
  );
}