var cdt;
function CountDown( seconds_remaining, span_id )
{
	var span_id = (span_id == null) ? "countdown" : span_id;
	var days = Math.floor( seconds_remaining / 86400 );
	var hours = Math.floor( seconds_remaining / 3600 ) % 24;
	var mins = Math.floor( seconds_remaining / 60 ) % 60;
	var secs = seconds_remaining % 60;
	var time_string = '';
	if( days )
		time_string += days + ' days ';
	time_string += hours + ':' + ( mins < 10 ? '0' : '' ) + mins + ':' + ( secs < 10 ? '0' : '' ) + secs;
	document.getElementById( span_id ).innerHTML = time_string;
	if ( seconds_remaining > 0 )
		cdt = setTimeout( "CountDown(" + ( seconds_remaining - 1 ) + ",'" + span_id +"')", 1000 );
}

function update_draft_panel()
{
	var xmlHttp;
	
	try { xmlHttp = new XMLHttpRequest(); } // Firefox, Opera 8.0+, Safari
	catch (e)
	{
		try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } // Internet Explorer
		catch (e)
		{
			try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (e)
			{
				alert( "Your browser does not support AJAX!" );
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange = function()
	{
		if( xmlHttp.readyState == 4 )
		{
			var result = xmlHttp.responseText;
			var a = new Array();
			a = result.split("\n");
			clearTimeout( cdt );
			document.getElementById( "draft_panel" ).innerHTML = a[1];
			if( parseInt( a[0] ) )
				CountDown( parseInt( a[0] ) );
			else
				window.location.reload( true );
			setTimeout( "update_draft_panel()", 3000 );
		}
	}
	var tm = new Date();
	xmlHttp.open("GET","/draft_panel.php?time="+tm.getTime(),true);
	xmlHttp.send(null);
}

function set_CSS_class_element( css_class, css_selector, css_value )
{
	var cssRules;
	if( document.styleSheets && document.styleSheets[0] )
	{
		if( document.styleSheets[0].cssRules ) // some browsers use cssRules
			css_rules = "cssRules";
		else if (document.styleSheets[0].rules) // some use rules
			css_rules = "rules";
		else
			return;
	}
	else
		return;
	for( var sheet = 0; sheet < document.styleSheets.length; sheet++ )
		for( var rule = 0; rule < document.styleSheets[sheet][cssRules].length; rule++ )
			if (document.styleSheets[sheet][css_rules][rule].selectorText == css_class )
				document.styleSheets[sheet][css_rules][rule].style[css_selector] = css_value;
}