
function showTimeImg(obj, src)
{
	obj.src = "/tournament/images/s_" + src + ".gif";
}

function showBTimeImg(obj, src)
{
	obj.src = "/tournament/images/b_" + src + ".gif";
}

function displayTime(watchid, partHour, partMin, partSec)
{
	if(partSec >= 10) 
	{
		partSec = partSec.toString();
		
		showTimeImg(document.getElementById("imgSecond" + parseInt(watchid)), partSec.substring(0,1))
		showTimeImg(document.getElementById("imgSecond" + (parseInt(watchid) + 1)), partSec.substring(1,2))
	}
	else
	{
		showTimeImg(document.getElementById("imgSecond" + parseInt(watchid)), '0')
		showTimeImg(document.getElementById("imgSecond" + (parseInt(watchid) + 1)), partSec)
	}
	
	if(partMin >= 10) 
	{
		partMin = partMin.toString();
		
		showTimeImg(document.getElementById("imgMinute" + watchid), partMin.substring(0,1))
		showTimeImg(document.getElementById("imgMinute" + (parseInt(watchid) + 1)), partMin.substring(1,2))
	}
	else
	{
		showTimeImg(document.getElementById("imgMinute" + watchid), '0')
		showTimeImg(document.getElementById("imgMinute" + (parseInt(watchid) + 1)), partMin)
	}
	
	if(partHour >= 10) 
	{
		partHour = partHour.toString();
		
		showTimeImg(document.getElementById("imgHour" + watchid), partHour.substring(0,1))
		showTimeImg(document.getElementById("imgHour" + (parseInt(watchid) + 1)), partHour.substring(1,2))
	}
	else
	{
		showTimeImg(document.getElementById("imgHour" + watchid), '0')
		showTimeImg(document.getElementById("imgHour" + (parseInt(watchid) + 1)), partHour)
	}
}

function calTime(secTime)
{
	var partSecond = 0;
	var partMinute = 0;
	var partHour = 0;
	
	if((secTime / 60) >= 1)
	{
		partSecond = secTime % 60;
		secTime -= partSecond; 
		secTime /= 60;
		
		if((secTime / 60) >= 1)
		{
			partMinute = secTime % 60;
			secTime -= partMinute; 
			partHour = secTime / 60;
		}
		else
		{
			partMinute = secTime
		}
	
	}
	else
	{
		partSecond = secTime
	}
	
	displayTime(2, partHour, partMinute, partSecond);
	
}

function checkTime()
{
	if(leftTime >= 0)
	{
		if (leftTime >= 360000)
		{
			displayTime(2,99,99,99);
		}
		else
		{
			calTime(leftTime);
			leftTime -= 1;
			setTimeout('checkTime()',1000);
		}
	}else{
		displayTime(2,0,0,0);
	}
	
}

function TOfunc() {
	
	var today = new Date();
	var hours = today.getHours();
	var minutes = today.getMinutes();
	var secs = today.getSeconds();
	
	//¿ùÇ¥½Ã
	var yearpart = today.getFullYear().toString(); 
	for(var i=0;i < 4;i++)
		showBTimeImg(document.getElementById("imgYear" + i), yearpart.substring(i,i+1));
		
	//´ÞÇ¥½Ã
	showBTimeImg(document.getElementById("imgMonth"), 'm' + today.getMonth());
		
	//ÀÏÇ¥½Ã	
	if(today.getDate() >= 10)
	{
		var datepart = today.getDate().toString();
		for(var i=0;i < 2;i++)
			showBTimeImg(document.getElementById("imgDate" + i), datepart.substring(i,i+1));
	}
	else
	{
		showBTimeImg(document.getElementById("imgDate0"), '0');
		showBTimeImg(document.getElementById("imgDate1"), today.getDate());
	}
	
	//½Ã°£Ç¥½Ã
	if (hours > 12)
		{
			showTimeImg(document.getElementById("imgAmpm0"), 'p');
			showTimeImg(document.getElementById("imgAmpm1"), 'm');
			displayTime(0, hours - 12, minutes, secs);
		}
	else
		{
			
			if(hours == 12)
				showTimeImg(document.getElementById("imgAmpm0"), 'p');	
			else
				showTimeImg(document.getElementById("imgAmpm0"), 'a');
				
			showTimeImg(document.getElementById("imgAmpm1"), 'm');
			
			if(hours == 0)
				displayTime(0, hours + 12, minutes, secs);
			else
				displayTime(0, hours, minutes, secs);
			
		}
	
	today.setSeconds(today.getSeconds() + 1);
	setTimeout( "TOfunc()", 1000 );
}
