// script functions for showing countdown timer and 
// hiding countdown message and cancel button if countdown is cancelled
//
// another interesting approach is with server scripting, where the result of the ticket generation
// is presented asynchronously.
// http://www.ashleyit.com/rs/main.htm
//
// and http://www.experts-exchange.com/Web/Q_20138762.html
// describes IE specific <IE:Download ID="oDownload" STYLE="behavior:url(#default#download)" />
//
// This script is thanx to bas

var timer ;
var counter = 10 ;
var valueRedirect = "http://fattires.jbshosting.com/home2.nsf/site.htm?Open";

function keypress(event) {
	if( event.keyCode == 27 ) {
		cancel_countdown() ;
	}
}

function countdown() {
	//do any necessary doings here before resubmitting
	if( counter == 0 ) {
		window.location.href=valueRedirect;
	} else {
		update_countdown( counter-- ) ;
		timer = window.setTimeout("countdown();",1000);
	}
}

function update_countdown(counter) {
	// see http://www.the-cool-place.co.uk/javascript/tutorial/javascript2.html
	var msg = "" + counter ;
	
	if(document.layers) {
		 //thisbrowser="NN4";
		layer = document.layers[0];
		layer.document.open();
		layer.document.write( msg ) ;
		layer.document.close();
	}
	
	if(document.all){
		//thisbrowser="ie"
		layer = document.all["countdown"];
		layer.innerHTML=msg ;
	}
	
	if( !document.all && document.getElementById ) {
		//thisbrowser="NN6";
		layer = document.getElementById("countdown");
		layer.innerHTML=msg;
	}
}

function cancel_countdown() {
	// see http://getelementbyid.com/scripts/index.aspx?CodeID=27#
	window.clearTimeout(timer) ;
	
	if(document.layers) {
		 //thisbrowser="NN4";
		document.layers['cancelcountdown'].visibility = "hide";
		document.layers['countdownmsg'].visibility = "hide";
	}
	
	if(document.all){
		//thisbrowser="ie"
		document.all['cancelcountdown'].style.visibility = "hidden";
		document.all['countdownmsg'].style.visibility = "hidden";
	}
	
	if( !document.all && document.getElementById ) {
		//thisbrowser="NN6";
		document.getElementById('cancelcountdown').style.visibility = "hidden";
		document.getElementById('countdownmsg').style.visibility = "hidden";
	}
}
