
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);		
}

function showDialog(vLink, vWidth, vHeight)
{
return showWindow(vLink, false, false, false, false, false, false, true, true, vWidth, vHeight, 0, 0);
}



function showWindow(vLink, vStatus, vResizeable, vScrollbars, vToolbar, vLocation, vFullscreen, vTitlebar, vCentered, vWidth, vHeight, vTop, vLeft)
{
var sLink = (typeof(vLink.href) == 'undefined') ? vLink : vLink.href;

winDef = '';
winDef = winDef.concat('status=').concat((vStatus) ? 'yes' : 'no').concat(',');
winDef = winDef.concat('resizable=').concat((vResizeable) ? 'yes' : 'no').concat(',');
winDef = winDef.concat('scrollbars=').concat((vScrollbars) ? 'yes' : 'no').concat(',');
winDef = winDef.concat('toolbar=').concat((vToolbar) ? 'yes' : 'no').concat(',');
winDef = winDef.concat('location=').concat((vLocation) ? 'yes' : 'no').concat(',');
winDef = winDef.concat('fullscreen=').concat((vFullscreen) ? 'yes' : 'no').concat(',');
winDef = winDef.concat('titlebar=').concat((vTitlebar) ? 'yes' : 'no').concat(',');
winDef = winDef.concat('height=').concat(vHeight).concat(',');
winDef = winDef.concat('width=').concat(vWidth).concat(',');

if (vCentered)
{
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
}
else
{
	winDef = winDef.concat('top=').concat(vTop).concat(',');
	winDef = winDef.concat('left=').concat(vLeft);
}

open(sLink, '_blank', winDef);

if (typeof(vLink.href) != 'undefined')
{
	return false;
}
}