code: function countdown(duration) {
  		var endtime = Date.now()+duration;
  		clearInterval(counter);
  		var counter = window.setInterval(function(){
  			remaining = endtime-Date.now();
  			
  			// Highlight remaining time when 20 seconds left, by flashing red text.
  			if(remaining < 20*1000) $('.remaining-time').addClass('blink text-danger');
  			
  			// Stop the timer when count down finishes, otherwise change countdown text.
  			if(remaining < 0) {
  				clearInterval(counter);
  				$('.remaining-time span').text(0);
  				$('.remaining-time').removeClass('blink');
  				//$('#input-form input, #input-form button').prop('disabled', true);
  			} else {
  				$('.remaining-time span').text(Math.round(remaining/1000));
  			}
  			
  		}, 1000);
  	}
docs: http://stackoverflow.com/a/2901298/1053612 Count down