var time;

function getCookie ( gk_key )
{
	if ( document.cookie.length > 0 )
	{
	 	var gk_dump = document.cookie.split( "\;" );
	 	
		for ( i in gk_dump )
		{
			 var gk_find = gk_dump[i].split( "=" );
			 
			 if ( gk_find[0] == gk_key )
		    	 return unescape( gk_find[1] );
		} 
	}
	return null
}

function setCookie ( gk_key, gk_value, gk_day )
{
	var gk_now = new Date( );
	
	gk_now.setDate( gk_now.getDate() + gk_day );
	document.cookie = gk_key + "=" + escape( gk_value ) + ( gk_day == null ? "" : ";expires="+gk_now.toGMTString );
}

function clock ( )
{
	if( time <= 0 )
	{
		time = 0;
		document.mainform.action = "trytest_result_01.asp";
		mainform.submit( );
	}
	time--

	document.mainform.mm.value = Math.floor( time % 3600 / 60 );
	document.mainform.ss.value = time % 60;
	
	var gk_now = new Date( );
	
	gk_now.setTime( gk_now.getTime()+time+5 ); 
	setCookie( "tiots", time, gk_now );
}
  
function load( )
{
	time = getCookie( "tiots" );
	
	if ( time == null )
	{
		time = 2*60 + 1;
		
		var gk_now = new Date( );
		gk_now.setTime( gk_now.getTime()+time+5 ); 
		setCookie( "tiots", time, gk_now );
	}
	
	setInterval( 'clock()', 1000 );
}

