function fAdicionaEventoAguardePF(objecto, evento, funcao) {
  if (objecto.attachEvent) {
    objecto.attachEvent(evento, funcao);
  } else {
    objecto.addEventListener(evento.substr(2), funcao, false);
  }
}  
function fInsereAguardePF() {
	var dvAguardePF;
	//verificar se o dvAguardePF existe
	if (!document.getElementById('dvAguardePF')) {
	  dvAguardePF = document.createElement('DIV');
	  //desenhar conteúdo do dvAguardePF
	  dvAguardePF.id = 'dvAguardePF';
	  dvAguardePF.style.position = 'absolute';
	  dvAguardePF.style.left = '0px';
	  dvAguardePF.style.top = '0px';
	  dvAguardePF.style.width = '100%';
	  dvAguardePF.style.height = '100%';
	  dvAguardePF.style.display = 'none';
	  dvAguardePF.innerHTML = '<iframe id="ifAguardePF" src="about:blank" style="position:absolute; left:0px; top:0px;" width="100%" height="100%" onload="fInicializaAguardePF();" frameborder=0></iframe>';
    document.body.appendChild(dvAguardePF);
	}
}
fAdicionaEventoAguardePF(self, 'onload', fInsereAguardePF);
function fInicializaAguardePF() {
  var dvAguardePF, i, lSS, ifAguardePF, head;
  dvAguardePF = document.getElementById('dvAguardePF');
  ifAguardePF = document.getElementById('ifAguardePF');
  if (dvAguardePF && ifAguardePF) {
	  //Configurar conteudo da ifAguardePF
	  // -> obter style sheets
	  lSS = document.getElementsByTagName('link');
	  head = ifAguardePF.contentWindow.document.getElementsByTagName('head')[0];
		if (head && head.appendChild) {
	    for (i = 0; i < lSS.length; i++) {
	      if (lSS[i].rel == 'stylesheet' && lSS[i].type == 'text/css') {
		      var oCSS = ifAguardePF.contentWindow.document.createElement('LINK')
		      oCSS.rel = 'stylesheet';
		      oCSS.type = 'text/css';
		      oCSS.href = lSS[i].href;
		      head.appendChild(oCSS);
		    }
		  }//for
	  }//if
	  // -> verificar se tem que inicializar o background-color do Body
	  if (typeof(corFundoAguardePorFavor) == 'string') {
	    ifAguardePF.contentWindow.document.body.style.backgroundColor = corFundoAguardePorFavor;
	  }else if (document.body.bgColor != '') {
	    ifAguardePF.contentWindow.document.bgColor = document.body.bgColor; 
	  } else if (document.body.style.backgroundColor != '') {
	    ifAguardePF.contentWindow.document.body.style.backgroundColor = document.body.style.backgroundColor;
	  }
	  // -> acrescentar conteudo
	  ifAguardePF.contentWindow.document.body.innerHTML = '<div style="margin:25px; text-align:left;' + (typeof(corTextoAguardePorFavor) == 'string' ? 'color:' + corTextoAguardePorFavor : '') + '">Aguarde um momento, por favor...</div>';
	}
}
function fMensagemAguardePF() {
  if (typeof(bAguardePFSemTimeout) != 'boolean') { bAguardePFSemTimeout = false; }
  if (document.getElementById('dvAguardePF')) {
    var alt = (document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight);
    document.getElementById('dvAguardePF').style.height = alt + 'px';
    if (bAguardePFSemTimeout) {
	    document.getElementById('dvAguardePF').style.display = 'block';
	    document.body.scrollTop = 0;
	  } else {
	    setTimeout('document.getElementById(\'dvAguardePF\').style.display = \'block\'; document.body.scrollTop = 0;', 1000);
	  }
	}
}

