// global variable for countdown timer
var seconds_left;

// start the countdown timer
function start_timer(seconds) // this function is called from the <body onload=""> event
{	
	seconds_left = seconds + 1; // always adds an additional second to your total
	redo(); 
}

// output time as "hh:mm:ss"
function format_time(seconds) 
{
	var disp;
	
	hours = parseInt(seconds/3600);
	mins = parseInt(seconds/60%60);
	secs = parseInt(seconds%60);
	
	if(hours <= 9)
	{
		disp = "0";
	}
	else
	{
		disp = "";
	}
	
	disp += hours + ":";
	
	if(mins <= 9) 
	{
		disp += "0";
	}
	else
	{
		disp += "";
	}
	
	disp += mins + ":";
	
	if(secs <= 9) 
	{
		disp += "0" + secs;
	}
	else 
	{
		disp += secs;
	}
	
	return(disp); 
}

// advance timer by one second
function redo() 
{
	seconds_left--;
	
	document.countdown_timer.display.value = format_time(seconds_left); // setup additional displays here.
	
	if(seconds_left == 0) 
	{
		//showhide('dialog');
		document.form1.submit();
	}
	else 
	{
		setTimeout("redo()",1000); 
	}
}

var state = 'hidden';
var scrollbars = 'hidden';
var overf_x = 'hidden';
//function for popup div - make background disabled.
function showhide(layer_ref) {

	layer_ref2 = layer_ref+'2';
	layer_ref3 = layer_ref+'2_shadow';
	layer_ref4 = layer_ref+'3';
	
	if (state == 'visible') {
		state = 'hidden';
		scrollbars = 'hidden';
	}
	else {
		state = 'visible';
		scrollbars = 'auto';
	}
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.visibility = state");
		eval( "document.all." + layer_ref2 + ".style.visibility = state");
		eval( "document.all." + layer_ref3 + ".style.visibility = state");
		
		eval( "document.all." + layer_ref4 + ".style.overflow = scrollbars");
		eval( "document.all." + layer_ref4 + ".style.overflowX = overf_x");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].visibility = state;
		document.layers[layer_ref2].visibility = state;
		document.layers[layer_ref3].visibility = state;
		
		document.layers[layer_ref4].overflow = scrollbars;
		document.layers[layer_ref4].overflowX = overf_x;
	}
	if (document.getElementById && !document.all) {
		maxwell_smart = document.getElementById(layer_ref);
		maxwell_smart.style.visibility = state;

		maxwell_smart2 = document.getElementById(layer_ref2);
		maxwell_smart2.style.visibility = state;
		
		maxwell_smart3 = document.getElementById(layer_ref3);
		maxwell_smart3.style.visibility = state;
		
		maxwell_smart4 = document.getElementById(layer_ref4);
		maxwell_smart4.style.overflow = scrollbars;
		maxwell_smart4.style.overflowX = overf_x;

	}
}

// stops the system for the specified amount of time in milliseconds
function sleep(milliseconds) 
{
	var startDate = new Date();
	var curDate = null;
	
	do
	{
		curDate = new Date();
	} 
	while(curDate-startDate < milliseconds);
} 
