
function remaintime(TimeLeft, format)
{
     html_code = '<div id="countdown"></div>';
     document.write(html_code);
     countdown(TimeLeft, format);                
}
function countdown(Time_Left, format)
{
	TimeLeft=Time_Left;
	if(Time_Left < 0)
	{
	    window.location.reload();
	}
	
	switch(format)
	{
		case 0:
			//The simplest way to display the time left.
			document.all.countdown.innerHTML = Time_Left + ' giây';
			break;
		case 1:
			//More datailed.
			
			days = Math.floor(Time_Left / (60 * 60 * 24));
			Time_Left %= (60 * 60 * 24);
			hours = Math.floor(Time_Left / (60 * 60));
			Time_Left %= (60 * 60);
			minutes = Math.floor(Time_Left / 60);
			Time_Left %= 60;
			seconds = Time_Left;
			
			dps = ''; hps = ''; mps = ''; sps = '';
			//ps is short for plural suffix.
			if(days == 1) dps ='';
			if(hours == 1) hps ='';
			if(minutes == 1) mps ='';
			if(seconds == 1) sps ='';
			
			a = '';
			a = days + ' ngày' + dps + ' ';
			a += hours + ' giờ' + hps + ' ';
			a += minutes + ' phút' + mps + ' ';
			a += Math.round(seconds) + ' giây' + sps;
			document.getElementById('countdown').innerHTML = a;
			break;
		default: 
			document.all.countdown.innerHTML = Time_Left + ' giây';
	}					
	setTimeout("countdown(" + (TimeLeft-1) +","+format+ ")", 1000);		
}
