   /**
    *    Identifica o browser do usuario
    */
	function Browser() {
		var agent = navigator.userAgent.toLowerCase();
		this.major = parseInt(navigator.appVersion);
		this.minor = parseFloat(navigator.appVersion);
		this.ns = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
		this.ns2 = (this.ns && (this.major == 3));
		this.ns3 = (this.ns && (this.major == 3));
		this.ns4b = (this.ns && (this.minor < 4.04));
		this.ns4 = (this.ns && (this.major >= 4));
		this.ie = (agent.indexOf("msie") != -1);
		this.ie3 = (this.ie && (this.major == 2));
		this.ie4 = (this.ie && (this.major >= 4));
		this.op3 = (agent.indexOf("opera") != -1);
		this.win = (agent.indexOf("win")!=-1);
		this.mac = (agent.indexOf("mac")!=-1);
		this.unix = (agent.indexOf("x11")!=-1);
	}

	var browser = new Browser();

	// definicao dos objetos, depende do browser	
	if(browser.ns4) {
		doc = "document";
	  	sty = "";
	  	htm = ".document";
	} else if(browser.ie4) {
	  	doc = "document.all";
	  	sty = ".style";
	  	htm = "";
	}

   /**
    *    Identifica a resolução da tela e alimenta variáveis
    *
    *		como usar: var tela = new resolucaoTela('document');
    */
	function resolucaoTela(psDocument)	{

      //	identifica o document
      var pDocument = null;
      if (typeof psDocument == "string")	{
      	pDocument = eval(psDocument);      	

      }
      else	{
      	pDocument = psDocument;
      }

		//	dimensoes da tela 
		this.screen_width  = screen.width;
		this.screen_height = screen.height;

		//	dimensoes da janela
		this.available_width  = 0;
		this.available_height = 0;

		if(browser.ns4) {
 			this.available_width  = innerWidth;
 			this.available_height = innerHeight;
 		} else if(browser.ie4) {
 			this.available_width  = pDocument.body.clientWidth;
 			this.available_height = pDocument.body.clientHeight;
 		}
	}
   
   /**
    *    Identifica e retorna um layer(div) de uma janela
    *
    * Parâmetros
    *    - pObjLayer
    *       Objeto ou nome ou indice de um layer a ser identificado e retornado
    *
    *    - pDocument
    *       Documento a ser analisado na identificação do layer
    *
    */
   function Dhtml_obtemLayer(
                     pObjLayer
                  ,  psDocument
                  )  {
   
      // inicializa o retorno
      var objLayer = null;

      //	identifica o document
      if (typeof psDocument == "string")	{
      	pDocument = eval(psDocument);      	
      }
      else	{
      	pDocument = psDocument;
      }

      // define que o objeto informado é o retorno
      if (typeof pObjLayer != "string") {
         objLayer = pObjLayer;
      }            
      // identifica o objeto a ser retornado pelo nome informado
      else if (   String(pDocument) != "undefined"
               && (
                     String(pDocument.getElementById) != "undefined"
                  || String(pDocument.layers)         != "undefined"
                  || String(pDocument.all)            != "undefined"
               )
              )   {

         if (document.getElementById && pDocument.getElementById(pObjLayer) != null) {
            objLayer = pDocument.getElementById(pObjLayer);
         }
         else if (document.layers && pDocument.layers[pObjLayer] != null)  {
            objLayer = pDocument.layers[pObjLayer];
         }
         else if (document.all) {
            objLayer = pDocument.all.item(pObjLayer);
         }
      }
   
      // valida o retorno
      if (String(objLayer) == "undefined")   {
         objLayer = null;
      }

      // retorna
      return objLayer;      
   }


   /**
    *    Inicia valores no objeto para dar efeito de typewriting
    *
    * Parâmetros
    *    - sNomeObj: nome do layer a ser 'digitado'
    *
    *		- iCont: contador de itens do menu
    *
    *		- iMax: numero maximo de itens do menu
    *
    *		- psDocument: objeto document que contem o layer
    *
    */
   function Typed_initializeItem(sNomeObj, iCont, iMax, psDocument)	{   
   	
		objItem = Dhtml_obtemLayer(sNomeObj + iCont, psDocument);

		if (String(objItem) != "undefined")	{
	      mytext = objItem.innerText;
	      var myheight = objItem.offsetHeight;
	      objItem.innerText='';
	      objItem.style.height=myheight;
	      objItem.style.visibility="visible";	      

	      Typed_typeIt(sNomeObj, iCont, iMax, 0, psDocument);
	   }
   }
   
   /**
    *    Simula a digitacao do texto contido no layer
    *
    * Parâmetros
    *    - sNomeObj: nome do layer a ser 'digitado'
    *
    *		- iCont: contador de itens do menu
    *
    *		- iMax: numero maximo de itens do menu
    *
    *		- psDocument: objeto document que contem o layer
    *
    */
   function Typed_typeIt(sNomeObj, iCont, iMax, iTxt, psDocument){
		objItem = Dhtml_obtemLayer(sNomeObj + iCont, psDocument);
		if (String(objItem) != "undefined")	{
	      objItem.insertAdjacentText("beforeEnd",mytext.charAt(iTxt));
	      if (iTxt < mytext.length-1){
	         iTxt++;
	         setTimeout("Typed_typeIt('"+ sNomeObj + "', " + iCont + ", " + iMax + "," + iTxt + ",'" + psDocument + "')",100);
	      }
	      else  {
	         iCont++;
	         if (iCont <= iMax)  {
	            Typed_initializeItem(sNomeObj, iCont, iMax, psDocument);
	         }
	         else  {
	            return;
	         }
	      }
	  	}
   }


   /**
    *    Retorna uma string com a data do dia no formato:
    *			"Quinta-Feira, 3 de Outubro de 2002 "
    *
    */
	function escreveDataExtenso()	{
		
		hoje   = new Date(); 
 		arrayDiaSemana = new Array('Domingo','Segunda-Feira','Terça-Feira','Quarta-Feira','Quinta-Feira','Sexta-Feira','Sábado');
 		arrayMes 		= new Array('Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro');
 		diaSemana 		= arrayDiaSemana[hoje.getDay()];

 		(hoje.getDate() == 1) ? diaMes = "1&ordm;" : diaMes = hoje.getDate();
 		mes = arrayMes[hoje.getMonth()];
 		ano = hoje.getYear();

		if (ano < 2000) { 
			if (ano <= 50) 
			       ano = "20" + ano 
			else 
			       ano = 1900 + ano 
		} 
		

		//	retorna
		return diaSemana + ", " + diaMes + " de " + mes + " de " + ano;
	}
	  
   /**
    *    Adiciona no favoritos do browser do
    *		usuário a página informada
    *		(função que só funciona no IE)
    *
    */
   function addbookmark(bookmarkurl, bookmarktitle)  { 
   	
   	if (browser.ie)	{
      	window.external.AddFavorite(bookmarkurl,bookmarktitle);
      }
      else	{
      	if (browser.ns)	{
      		alert(
      				"No navegador Netscape, para incluir uma página no bookmarks,\n"
      			+	"deve-se pressionar as teclas CTRL e a letra D ao mesmo tempo."
      		);
      	}
      }
   }

   /**
    *    Verifica a consistência do endereço
    *    de email passado como parametro
    */
   function checkEmail(strng, quem) {
      var error = ""
      var emailFilter=/^.+@.+\..{2,3}$/;
      if (!(emailFilter.test(strng))) { 
         error = "Favor digitar um endereço de email válido.\n";
      }
   
      var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
      if (strng.match(illegalChars)) {
         error = "O endereço de email contém caracteres inválidos.\n";
      }
      return error;
   }

   /**
    *    Verifica a consistência do endereço
    *    de email passado como parametro
    */
   function checkEmail2(vform, pWindow) {
      
      // verifica o email do destinatario
      error = checkEmail(vform.destinatario.value);
      if (error!= "")   {
         error = error.replace(/email/, "email do destinatário");
         alert(error);
         return false;
      }
      // verifica o email do remetente
      var error = checkEmail(vform.remetente.value);
      if (error!= "")   {
         error = error.replace(/email/, "email do remetente");
         alert(error);
         return false;
      }
      return true;
      // versao 1
      /*
      window.location.href = 
            "mailto:"+ vform.destinatario.value
         +  "?cc=" + vform.remetente.value
         +  "&subject=Site%20recomendado:%20www.lematta.com"
         +  "&body=Entrei%20no%20site%20do%20escritor%20Luis%20Eduardo%20Matta%20e%20recomendo%20a%20visita:%20http://www.lematta.com"
         +  "%0D%0A%0D%0A"
         +  vform.comentario.value
      ;
      */
      
      // versao 2 - 03/2007
     /* window.location.href = 
      		vform.pagina.value + "?"
      	+	"dest=" + vform.destinatario.value
      	+	"&rem=" + vform.remetente.value
      	+ 	"&subject=Site%20recomendado:%20www.lematta.com"
         +  "&body=Entrei%20no%20site%20do%20escritor%20Luis%20Eduardo%20Matta%20e%20recomendo%20a%20visita:%20http://www.lematta.com"
         +  "%0D%0A%0D%0A"
         +  vform.comentario.value
      ;
      */
   }

   /**
    *    Chama o window.open para abrir uma 
    *    nova janela do broswer
    *
    *    Parametros:
    *       url, nome, tamanho e 
    *       caracteristicas da janela
    */
	function abreJanela(sUrl, sNome, iWidth, iHeight, toolbar, menubar, status)   {

      // centraliza a nova janela
      if (browser.major >= 4) {
      	iLeft = (screen.width) ? (screen.width-iWidth)/2 : 0;
      	iTop  = (screen.height) ? (screen.height-iHeight)/2 : 0;
      }
      else  {
      	iLeft = 260;
      	iTop  = 260;
      }

      win = window.open(
            sUrl
         ,  sNome
         ,     'toolbar='+ toolbar +',status=' + status + ',menubar='
            +  menubar + ',width=' + iWidth + ',height='+ iHeight 
            +  ',left=' + iLeft + ',top=' + iTop
            +  ',titlebar=no,directories=no,hotkeys=no,resizable=no,copyhistory=no,scrollbars=no'
      );

      if(win.window.focus) {
         win.window.focus();
      }
   }

   /**
    *    Identifica um dado informado em window location,
    *    na forma:
    *       url?NomeDado1=valor1&NomeDado2=valor2
    *
    *    Parametro:
    *       sNomeDado:  string 'NomeDado='
    */
   function pegaDado(sNomeDado, bTemQueAchar) {
      return Global_obtemParametro(
            unescape(window.location.search).substring(1)
         ,  sNomeDado, "&"
         ,  bTemQueAchar
      );
   }

   /**
    *    Identifica um dado informado em uma location
    *    informada, na forma:
    *       url?NomeDado1=valor1&NomeDado2=valor2
    *
    *    Parametro:
    *       sNomeDado:  string 'NomeDado='
    */
   function pegaDadoDaJanela(sNomeDado, pLocation, bTemQueAchar) {
      return Global_obtemParametro(
            unescape(pLocation.search).substring(1)
         ,  sNomeDado, "&"
         ,  bTemQueAchar
      );
   }

   /**
    *    Retorna o conteúdo de uma String
    *
    *    Parâmetros
    *    - psDados
    *       Dados a serem analisados
    *
    *    - psChave
    *       Chave a ser identificada
    *
    *    - pSepDados
    *       Separador dos dados
    *
    *    - pbTemQueAchar
    *       Define se a inexistência do parâmetro deve retornar "undefined"
    *
    */
   function Global_obtemParametro(psDados, psChave, psSepDados, pbTemQueAchar)   {
      
      // inicializa variáveis
      var dado   = psDados;
   	var pos    = psDados.indexOf(psChave);
   	var posFin = psDados.indexOf(psSepDados, pos);
      
      // verifica se foi encontrada a chave e esta deve existir
      if (pos < 0 && pbTemQueAchar == true)   {
         return 'undefined';
      }
      
      // verifica o retorno
   	if (posFin == -1) {
   		dado = dado.slice(pos+psChave.length);
   	}  
   	else {
   		dado = dado.slice(pos+psChave.length, posFin);
   	}
   	
   	// return
   	return dado;   	
   }
		
