/* variabili progress bar */
var loadedcolor='#437CCB';              // PROGRESS BAR COLOR
var unloadedcolor='#E0EAFA';            // COLOR OF UNLOADED AREA
var bordercolor='navy';                 // COLOR OF THE BORDER
var barheight=20;                       // HEIGHT OF PROGRESS BAR IN PIXELS
var barwidth=250;                       // WIDTH OF THE BAR IN PIXELS
var waitTime=2;                         // NUMBER OF SECONDS FOR PROGRESSBAR
var blocksize=(barwidth-2)/waitTime/10; // numero di steps
var loaded=0;
var PBouter;
var PBdone;
var PBbckgnd;
var Pid=0;
var txt='';

/* variabili finestra di waiting */

var w=320;                              // larghezza finestra waiting
var h=120;                              // altezza finestra waiting
var borderclr="#437CCB";                // colore bordo finestra waiting  



/* funzione "UpdateIt()" per definire le coordinate dinamiche della finestra 
   e della progressive bar.
   
   LeftPosition: coordinata left della finestra di waiting
   TopPosition:  coordinata top della finestra di waiting
   LeftPosBar:   coordinata left della progress bar
   TopPosBar:    coordinata top della progress bar */
function UpdateIt(){
  // finestra di waiting
  docwidth = document.body.clientWidth; 
  docheight = document.body.clientHeight;
  LeftPosition=document.body.scrollLeft+(docwidth-w)/2;
  TopPosition=document.body.scrollTop+(docheight-h)/2;
  document.all["wait"].style.top = TopPosition;
  document.all["wait"].style.left = LeftPosition;
  
  // progressive bar
  LeftPosBar=LeftPosition+((w-barwidth)/2);
  TopPosBar=TopPosition+(h-(barheight*2));
  document.all["PBouter"].style.top = TopPosBar;
  document.all["PBouter"].style.left = LeftPosBar;
  
  setTimeout("UpdateIt()", 10);
}

function incrCount(){
  window.status=windowWaitingText;
  loaded++;
  if(loaded<0)loaded=0;
  if(loaded>waitTime*10)
    loaded=0;            //per creare il loop continuo

  resizeEl(PBdone, 0, blocksize*loaded, barheight-2, 0);
}

function progressBarInit(){
  PBouter=document.getElementById('PBouter');
  PBdone=document.getElementById('PBdone');
  resizeEl(PBdone,0,0,barheight-2,0);
  PBouter.style.visibility="visible";
  Pid=setInterval('incrCount()',95);
}

function resizeEl(id,t,r,b,l){
  id.style.width=r+'px';
}

/* funzione che nasconde i dati e visualizza la finestra di waiting 
   con la progress bar*/
function makeWait() {
  document.getElementById("myData").style.visibility = "hidden";  
  document.getElementById("wait").style.visibility = "visible";
  progressBarInit();
  UpdateIt();
}

/* funzione "makeWaitingDiv()" che costruisce la finestra di waiting e la progressive bar*/
function makeWaitingDiv(message) {
  txt+=   '<div id="wait" style="position:absolute; left:0px; top:0px; z-index:7; width:'+ w +'px; height:'+ h +'px; overflow: visible; background-image: url('
  txt+=   imageURL + 'fondogeneralchiaro.gif); visibility: hidden; border: 3px solid '+ borderclr +'">';
  txt+=   '<table border=0 width="100%"><tr><td width="'+ w +'" height="'+ (h-20) +'" align="center" valign="middle" class="waiting">';
  txt+=   message;      
  txt+=   '</td></tr></table></div>';
  txt+=   '<div id="PBouter" style="position:absolute; left:0px; top:0px; z-index:100; visibility:hidden; background-color:'+bordercolor+'; width:'+barwidth+'px; height:'+barheight+'px;">';
  txt+=   '<div style="position:absolute; top:1px; left:1px; width:'+(barwidth-2)+'px; height:'+(barheight-2)+'px; background-color:'+unloadedcolor+'; font-size:1px;"></div>';
  txt+=   '<div id="PBdone" style="position:absolute; top:1px; left:1px; z-index:200; width:0px; height:'+(barheight-2)+'px; background-color:'+loadedcolor+'; font-size:1px;"></div>';
  txt+=   '</div>';     
  document.write(txt);  
}                       
                        