/**
 * progress.js: a simple controllable progress bar
 */

var w3c=(document.getElementById)?true:false;
var ie4=(document.all && !w3c)?true:false;
var ie5=(document.all && w3c)?true:false;
var onepercent;
var progress=0;
var barbg; //background color
var barfg; //foreground color

function drawBar(w,h,fg,bg,txt,txtc){
	onepercent = (w-4)/100;
	h=Math.max(4,h);
	var text= txt || '';
	var textc= txtc || 'black';
	var fntsize= h*0.8; //make font fit within height

	if (navigator.appName == "Netscape") {
		stylefix = " bottom:5px; left:2px; ";
		if(navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Safari") != -1) {
			stylefix = " bottom:-5px; left:2px; ";
		}
	} else {
		stylefix = " top:1px; left:1px; ";		
	}

	var html='<div id="pmeter" name="pmeter" style="position:relative; background-color:'+bg+'; width:'+w+'px; height:'+h+'px; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; border-right: 1px solid #AAAAAA; border-bottom: 1px solid #AAAAAA;">'
		+'<span id="text" style="position:absolute; top:0px; left:1px; z-index:2; width:'+(w-2)+'; color:'+textc+'; font-size:'+fntsize+'px; text-align:center;" class="form">'+text+'</span>'
		+'<hr id="barfg" name="barfg" style="position:absolute; ' + stylefix + ' width:0px; height:'+(h-4)+'px; color: '+fg+'; background-color: '+fg+'; z-index:1;"/>'
		+'</div>';
	document.write(html);
	barbg=(ie4)?document.all['barbg']:document.getElementById('barbg');
	barfg=(ie4)?document.all['barfg']:document.getElementById('barfg');
}

function increment(prcnt){
 	prcnt=prcnt||1;
	progress+=prcnt;
	setPercent(progress);
}

function decrement(prcnt){
	prcnt=prcnt||1;
	progress-=prcnt;
	setPercent(progress);
}

function setPercent(prcnt){
	progress=prcnt;
	if(progress<0)progress=0;
	if(progress>=100){
		progress=100;
	}
	barfg.style.width=onepercent*progress;
}

function hidebar(){
	pmeter.outerHTML="<!--bar-->";
}

function setText(txt,color){
  var text = document.getElementById('text');
  text.innerHTML=txt;
  text.style.color=color;
}

function setColor(color){
  document.getElementById('barfg').style.color=color;
}
