
<!-- Countdown in Java Script .. Cameron Gregory http://www.bloke.com/
// permission to use and modify as long as you leave these 4 comment
// lines in tact and unmodified.
// http://www.bloke.com/javascript/Countdown/

var cd_tBegin; // Start time
var cd_tTotal; // Total time to countdown


/**
 * Init countdown timer
 */
function cd_init(seconds) {
	cd_tTotal=seconds;
	cd_tBegin=getCurrentSecs();
	
	// Init timer
	tid=window.setTimeout("doDate()",1000);
}


/*
 * Returns current time expressed in seconds from 01-01-1970
 * */
function getCurrentSecs() {
	var d=new Date();
	return (d.getTime()/1000);	
}

function doDate()
{
  var cTime=getCurrentSecs();
  var show=cd_tTotal-(cTime-cd_tBegin); 
  var days='-';
  var hours='-';
  var minutes='-';
  var seconds='-';
  if(show>0) {
	  //days=intval(show/(24*60*60));
	  //show-=(days*(24*60*60));
	  hours=intval(show/(60*60));
	  show-=(hours*(60*60));
	  minutes=intval(show/60);
	  show-=(minutes*60);
	  seconds=intval(show);
  }
  // SHOW
  //var message="Time: "+days+" days, "+hours+" hours, "+minutes+" min, "+seconds+" sec";
 // alert(message);
  //document.getElementById('counter_days').innerHTML=""+days;
  document.getElementById('counter_hours').innerHTML=""+hours;
  document.getElementById('counter_min').innerHTML=""+minutes;
  document.getElementById('counter_sec').innerHTML=""+seconds;
  
  // Repeat
  tid=window.setTimeout("doDate()",1000);
}

function intval (mixed_var, base) {
    // Get the integer value of a variable using the optional base for the conversion  
    // 
    // version: 910.813
    // discuss at: http://phpjs.org/functions/intval    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: stensi
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Matteo
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)    // *     example 1: intval('Kevin van Zonneveld');
    // *     returns 1: 0
    // *     example 2: intval(4.2);
    // *     returns 2: 4
    // *     example 3: intval(42, 8);    // *     returns 3: 42
    // *     example 4: intval('09');
    // *     returns 4: 9
    // *     example 5: intval('1e', 16);
    // *     returns 5: 30    var tmp;
 
    var type = typeof( mixed_var );
 
    if (type === 'boolean') {        return (mixed_var) ? 1 : 0;
    } else if (type === 'string') {
        tmp = parseInt(mixed_var, base || 10);
        return (isNaN(tmp) || !isFinite(tmp)) ? 0 : tmp;
    } else if (type === 'number' && isFinite(mixed_var) ) {        return Math.floor(mixed_var);
    } else {
        return 0;
    }
}

