/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Arquivo..: aguarde.js
 * Linguagem: JavaScript
 * Autor....: Sergio Vicente (svicente99@yahoo.com)
 * Conteudo.: Monta uma "janelinha aguarde" para o caso de respostas longas
 *            Pode ser passado como parametro (url) uma janela customizada
 *            pelo usuario
 * Data.....: 13/fevereiro/2000
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

var FECHA_AGUARDE = true;

var TIME_TO_CLOSE = 1;     // control here the time (in milisecs) to close the "wait window"
var x = screen.width;                     
var y = screen.height;                    
var w = x*0.3;                            // window width 
var h = y*0.05;                           // window height
var l = (x - w) / 2;                      // window left (to center)
var t = (y - h) / 2;                      // window top  (to center)

var WIN_PARAMETERS="width="+w+",height="+h+",top="+t+",left="+l+",resizable=no";

function aguarde(url)
{
	FECHA_AGUARDE = false;
	if( arguments.length>0 )
		window.open(url,'winWait',WIN_PARAMETERS);
	else
		createWinWait();
}

function createWinWait()
{	
	var newWin = window.open ("","",WIN_PARAMETERS);
	
  	if( newWin != null )
		{
		var html = 	"<HTML><HEAD><TITLE>Aguarde...</TITLE>" +
					"<SCRIPT>"+ checkToClose_code() +"</SCRIPT></HEAD>" +
				   	"<BODY bgcolor=white><MARQUEE id='msgRoll' style='font:14pt Verdana;color:#A0A0A0'>A g u a r d e . . .</MARQUEE>" +
					"<script>window.setTimeout('checkToClose()',1000);</script>" +
					"</BODY></HTML>";
		newWin.document.write(html);
		newWin.document.close();
	}
}

function checkToClose_code()
{
	return( "function checkToClose() {" +
			"	window.setTimeout('checkToClose()',1000);" +
			"	if( window.opener.FECHA_AGUARDE ) " +
			"		{" +
			"		document.all.msgRoll.innerText = 'Veja o resultado';" +
			"		window.setTimeout('self.close()',"+TIME_TO_CLOSE+");" +
			"		}" +
			"}" );
}
