var progBar = 0;






function getRefToDivNest( divID, oDoc ) {
	if( !oDoc ) { oDoc = document; }
	if( document.layers ) {
		if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {
			for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
				y = getRefToDivNest(divID,oDoc.layers[x].document); }
			return y; } }
	if( document.getElementById ) { return document.getElementById(divID); }
	if( document.all ) { return document.all[divID]; }
	return document[divID];
}

function progressBar( oBt, oBc, oBg, oBa, oWi, oHi, oDr ) {

	document.write( '<form action="/s_engine.php" method="GET" name="sf">\n' );
	progBar++; this.id = 'progBar' + progBar; this.dir = oDr; this.width = oWi; this.height = oHi; this.amt = 0;
	document.write( '<table border="0" cellspacing="0" cellpadding="'+oBt+'"><tr><td bgcolor="'+oBc+'">'+
		'<table border="0" cellspacing="0" cellpadding="0"><tr><td height="'+oHi+'" width="'+oWi+'" bgcolor="'+oBg+'">' );
	if( document.layers ) {
		document.write( '<ilayer height="'+oHi+'" width="'+oWi+'"><layer bgcolor="'+oBa+'" name="progBar'+progBar+'"></layer></ilayer>' );
	} else {
		document.write( '<div style="position:relative;top:0px;left:0px;height:'+oHi+'px;width:'+oWi+';">'+
			'<div style="position:absolute;top:0px;left:0px;height:0px;width:0;font-size:1px;background-color:'+oBa+';" id="progBar'+progBar+'"></div><div style="position:absolute;top:0px;left:0px;height:0px;background:transparent;align:center;"><input type="text" style="background:transparent;width=600;border:0;text-align: center;font-weight: bold; color: #FFFFFF; font-size: 10px" name="q1" value="" size="145"></div></div>' );

	}
	document.write( '</td></tr></table></td></tr></table>\n' );
	this.setBar = resetBar; //doing this inline causes unexpected bugs in early NS4
	this.setCol = setColour;

//	document.write( '<input type="text" class="PROGRESS2" name="q2" value="" size="46"><input type="text" class="PROGRESS3" name="q3" value="" size="45"><input type="text" class="PROGRESS3" name="q4" value="" size="1">\n' );
	document.write( '</form>\n' );


}


function resetBar( a, b, size ) {
	this.amt = ( typeof( b ) == 'undefined' ) ? a : b ? ( this.amt + a ) : ( this.amt - a );
	if( isNaN( this.amt ) ) { this.amt = 0; } if( this.amt > 1 ) { this.amt = 1; } if( this.amt < 0 ) { this.amt = 0; }
	var theWidth = Math.round( this.width * ( ( this.dir % 2 ) ? this.amt : 1 ) );
	var theHeight = Math.round( this.height * ( ( this.dir % 2 ) ? 1 : this.amt ) );
	var theDiv = getRefToDivNest( this.id ); if( !theDiv ) { window.status = 'Progress: ' + Math.round( 100 * this.amt ) + '%'; return; }
	if( theDiv.style ) { theDiv = theDiv.style; theDiv.clip = 'rect(0px '+theWidth+'px '+theHeight+'px 0px)'; }
	var oPix = document.childNodes ? 'px' : 0;
	theDiv.width = theWidth + oPix; theDiv.pixelWidth = theWidth; theDiv.height = theHeight + oPix; theDiv.pixelHeight = theHeight;
	if( theDiv.resizeTo ) { theDiv.resizeTo( theWidth, theHeight ); }
	theDiv.left = ( ( this.dir != 3 ) ? 0 : this.width - theWidth ) + oPix; theDiv.top = ( ( this.dir != 4 ) ? 0 : this.height - theHeight ) + oPix;


	var a1 = Math.round(theWidth / 600 * 100);
	var a2 = Math.round((theWidth / 600) * size);
	var a3 = Math.round(size - a2);


	var a2show = '';
	var a2showFT = '';
	var a3show = '';
	var a3showFT = '';
	var filesize = '';
	var filesizeFT = '';

if (a2 > 1024){ 
a2show = Math.round((theWidth / 600) * size /1024*10)/10;
a2showFT = "MB";
 }else{
a2show = Math.round((theWidth / 600) * size);
a2showFT = "kB";
}

if (size > 1024){ 
filesize = Math.round(size / 1024);
filesizeFT = "MB";
 }else{
filesize = Math.round(size);
filesizeFT = "kB";
}


if (a3 > 1024){ 
a3show = Math.round((size - a2)/1024*10)/10;
a3showFT = "MB";
 }else{
a3show = Math.round((size - a2)*10)/10;
a3showFT = "kB";
}



//document.sf.q.value = '* '+a1+'% complete   **   '+a2show+''+a2showFT+'  downloaded   **   '+a3show+''+a3showFT+' remaining   **   '+filesize+''+filesizeFT+' test *';

document.sf.q1.value = ''+a1+'% complete';
document.sf.q1.focus();

//document.sf.q2.value = '**   '+a2show+''+a2showFT+'  downloaded   **';
//document.sf.q2.focus();

//document.sf.q3.value = '**   '+a3show+''+a3showFT+' remaining   **';
//document.sf.q3.focus();

//document.sf.q4.value = '';
//document.sf.q4.focus();




}



function setColour( a ) {
	var theDiv = getRefToDivNest( this.id ); if( theDiv.style ) { theDiv = theDiv.style; }
	theDiv.bgColor = a; theDiv.backgroundColor = a; theDiv.background = a;
}

