/* *******************************
Progressbar - Version 1.0
Author: Marcelo C. Melo
(c) Copyright, CleanBrain Software, Inc. All rights reserved.
****************************** */

	var loadedcolor='#0066cc';                // PROGRESS BAR COLOR
	var unloadedcolor='white';                // BGCOLOR OF UNLOADED AREA
	var barheight=35;                         // HEIGHT OF PROGRESS BAR IN PIXELS (MIN 25)
	var barwidth=400;                         // WIDTH OF THE BAR IN PIXELS
	var bordercolor='#003366';                // COLOR OF THE BORDER
	var barlength = 400;                			// PROGRESS BAR LENGTH
	var blocksize=1;                					// SIZE OF A BLOCK IN THE PROGRESS BAR
	var loaded=0, outerlayer, innerlayer;     // PROGRESS BAR FLAG, PROGRESS BAR LAYERS
	var displaymessage = '<b>PLEASE WAIT.</b> Processing Request...';  // PROGRESS BAR MESSAGE

	floatX=10;
	floatY=10;
	align="center";
	valign="center";
	delayspeed=3;

	NS6=false;
	IE4=(document.all);
	if (!IE4) {NS6=(document.getElementById);}
	NS4=(document.layers);

	var txt = '';
	barheight=Math.max(barheight,25);
	txt='<iframe id="PBShim" src="javascript:false;" scrolling="no" frameborder="0" style="position:absolute; top:'+floatY+'; left:'+floatX+'; display:none; z-index:105;"></iframe>';
	if (NS4) txt +='<LAYER NAME="outerlayer" LEFT="'+floatX+'" TOP="'+floatY+'" bgcolor="'+bordercolor+'" visibility="hide">';
	if ((IE4) || (NS6)) txt += '<div id="outerlayer" style="position:absolute; left:'+floatX+'; top:'+floatY+'; visibility:hidden; background-color:'+bordercolor+'; z-index:100">';

	txt += '<table cellpadding="0" cellspacing="1" border="0"><tr><td width="'+barwidth+'" height="'+barheight+'" valign="center">';
	if(NS4)txt+='<ilayer width="100%" height="100%"><layer width="100%" height="100%" bgcolor="'+unloadedcolor+'" top="0" left="0">';
	txt+='<table cellpadding="0" cellspacing="0" border="0"><tr><td valign="center" width="'+barwidth+'" height="'+barheight+'" bgcolor="'+unloadedcolor+'"><center><img src="/global/images/icons/email.gif" align="absmiddle" border="0"><font color="'+loadedcolor+'" size="2" face="sans-serif">&nbsp;&nbsp;'+displaymessage+'</font></center></td></tr></table>';
	if(NS4) txt+='</layer>';
	txt+=(NS4)? '<layer name="innerlayer" width="100%" height="'+barheight+'" bgcolor="'+loadedcolor+'" top="0" left="0">' : '<div id="innerlayer" style="position:absolute; top:1px; left:1px; width:'+barwidth+'px; height:'+barheight+'px; background-color:'+loadedcolor+'; z-index:100">';
	txt+='<table cellpadding="0" cellspacing="0" border="0"><tr><td valign="center" width="'+barwidth+'" height="'+barheight+'" bgcolor="'+loadedcolor+'"><center><img src="/global/images/icons/email.gif" align="absmiddle" border="0"><font color="'+unloadedcolor+'" size="2" face="sans-serif">&nbsp;&nbsp;'+displaymessage+'</font></center></td></tr></table>';
	txt+=(NS4)? '</layer></ilayer>' : '</div>';
	txt+='</td></tr></table>';
	txt+=(NS4)?'</layer>' : '</div>';
	txt+='<script>hideouterlayer();</script>';
	document.write(txt);

	ifloatX=floatX;
	ifloatY=floatY;
	define();
	window.onresize=define;
	lastX=-1;
	lastY=-1;
	adjust();

	function adjust() {
	if ((NS4) || (NS6)) {
		if (lastX==-1 || delayspeed==0)
		{
		lastX=window.pageXOffset + floatX;
		lastY=window.pageYOffset + floatY;
		}
		else
		{
			dx=Math.abs(window.pageXOffset+floatX-lastX);
			dy=Math.abs(window.pageYOffset+floatY-lastY);
			d=Math.sqrt(dx*dx+dy*dy);
			c=Math.round(d/10);
			if (window.pageXOffset+floatX>lastX) {lastX=lastX+delayspeed+c;}
			if (window.pageXOffset+floatX<lastX) {lastX=lastX-delayspeed-c;}
			if (window.pageYOffset+floatY>lastY) {lastY=lastY+delayspeed+c;}
			if (window.pageYOffset+floatY<lastY) {lastY=lastY-delayspeed-c;}
		}
		if (NS4){
			document.layers['outerlayer'].pageX = lastX;
			document.layers['outerlayer'].pageY = lastY;
		}
		if (NS6){
			document.getElementById('outerlayer').style.left=lastX;
			document.getElementById('outerlayer').style.top=lastY;
			document.getElementById('PBShim').style.left=lastX;
			document.getElementById('PBShim').style.top=lastY;
		}
		}
		else if (IE4){
			if (lastX==-1 || delayspeed==0){
				lastX=document.body.scrollLeft + floatX;
				lastY=document.body.scrollTop + floatY;
			}
			else{
				dx=Math.abs(document.body.scrollLeft+floatX-lastX);
				dy=Math.abs(document.body.scrollTop+floatY-lastY);
				d=Math.sqrt(dx*dx+dy*dy);
				c=Math.round(d/10);
				if (document.body.scrollLeft+floatX>lastX) {lastX=lastX+delayspeed+c;}
				if (document.body.scrollLeft+floatX<lastX) {lastX=lastX-delayspeed-c;}
				if (document.body.scrollTop+floatY>lastY) {lastY=lastY+delayspeed+c;}
				if (document.body.scrollTop+floatY<lastY) {lastY=lastY-delayspeed-c;}
			}
			document.all['outerlayer'].style.posLeft = lastX;
			document.all['outerlayer'].style.posTop = lastY;
			document.all['PBShim'].style.posLeft = lastX;
			document.all['PBShim'].style.posTop = lastY;
		}
		setTimeout('adjust()',50);
	}

	function define()
	{
		if ((NS4) || (NS6)){
			if (align=="left") {floatX=ifloatX};
			if (align=="right") {floatX=window.innerWidth-ifloatX-barwidth-20};
			if (align=="center") {floatX=Math.round((window.innerWidth-20)/2)-Math.round(barwidth/2)};
			if (valign=="top") {floatY=ifloatY};
			if (valign=="bottom") {floatY=window.innerHeight-ifloatY-barheight};
			if (valign=="center") {floatY=Math.round((window.innerHeight-20)/2)-Math.round(barheight/2)};
		}
		if (IE4){
		if (align=="left") {floatX=ifloatX};
		if (align=="right") {floatX=document.body.offsetWidth-ifloatX-barwidth-20}
		if (align=="center") {floatX=Math.round((document.body.offsetWidth-20)/2)-Math.round(barwidth/2)}
		if (valign=="top") {floatY=ifloatY};
		if (valign=="bottom") {floatY=document.body.offsetHeight-ifloatY-barheight}
		if (valign=="center") {floatY=Math.round((document.body.offsetHeight-20)/2)-Math.round(barheight/2)}
		}
	}
    function resetProgressBar(){
      loaded = 0;
    }
    function forcedStartProgressBar(){
      resetProgressBar();
      startProgressBar();      
      dispbars();      
    }
	function startProgressBar(){
		if(NS4){
		outerlayer=document.outerlayer;
		innerlayer=document.outerlayer.document.layers[0].document.innerlayer;
		}
		if(NS6){
		outerlayer=document.getElementById('outerlayer');
		innerlayer=document.getElementById('innerlayer');
		}
		if(IE4){
		outerlayer=document.all.outerlayer;
		innerlayer=document.all.innerlayer;
		}
		if(NS4){
		outerlayer.visibility="show";
		}
		if(IE4||NS6){
		outerlayer.style.visibility="visible";
		}
		var PBShim = document.getElementById("PBShim");
		PBShim.style.width = outerlayer.offsetWidth;
	    PBShim.style.height = outerlayer.offsetHeight;
	    PBShim.style.top = outerlayer.style.top;
	    PBShim.style.left = outerlayer.style.left;
	    PBShim.style.zIndex = outerlayer.style.zIndex - 1;
	    PBShim.style.display = "block";
		
		cliplayer(innerlayer,0,0,barheight,0);
		setTimeout('dispbars()', 20);	
	    return true;
	}
    function stopProgressBar(){
      loaded=barlength+1;
    }
	function dispbars(){
		if(loaded<=barlength) {
			loaded++;
			cliplayer(innerlayer, 0, blocksize*loaded, barheight, 0);
			if(loaded>=barlength) {
				loaded = 0;		
			}
			setTimeout('dispbars()', 20);
		}
	}

	function hideouterlayer(){
		if (outerlayer != null) {
			(NS4)? outerlayer.visibility="hide" : outerlayer.style.visibility="hidden";
		}
		if (document.getElementById("PBShim") != null) {
			document.getElementById("PBShim").style.display = "none";
		}
	}

	function cliplayer(layer, ct, cr, cb, cl){
		if(NS4){
		layer.clip.left=cl;
		layer.clip.top=ct;
		layer.clip.right=cr;
		layer.clip.bottom=cb;
		}
		if(IE4||NS6)layer.style.clip='rect('+ct+' '+cr+' '+cb+' '+cl+')';
	}
