// ===================================================================================================
//  Descricao..: Relacao de funcoes basicas de browser, escrita, eventos e ajax
//  Autor......: Bicalho
//  Data.......: 03/07/2007
//  Referencia.: Apostila ()
// ===================================================================================================

// Criação de objeto XMLHTTPRequest cross-browser - Parâmetros: N/A
   function XMLHTTPRequest() { 
      var tXHR=0;
      if (window.XMLHttpRequest) { tXHR=new XMLHttpRequest(); } //Objeto nativo (FF/Safari/Opera7.6+)
      else {
         try { tXHR=new ActiveXObject("Msxml2.XMLHTTP"); } //activeX (IE5.5+/MSXML2+)
         catch(e) {
            try { tXHR=new ActiveXObject("Microsoft.XMLHTTP"); } //activeX (IE5+/MSXML1)
            catch(e) { /* O navegador não tem suporte */ tXHR=false; }
         }
      }
      return tXHR;
   }

// Retorna o elemento do formulario identificado pelo ID e/ou nome
   function lib_gE(tID) {
      return ( document.getElementById(tID) );
   }

// Inclui um evento associado a um elemento de tela
   function lib_adEvento(tObj, tEvent, tFunc) { 
      if (window.addEventListener) return tObj.addEventListener(tEvent, tFunc, true);
      else if (window.attachEvent) return tObj.attachEvent('on'+ tEvent, tFunc);
      else return false; 
   } 

// Atribui valores referentes ao browser a uma variável 
   function lib_browser_check()
   {  this.ver=navigator.appVersion;
      this.agent=navigator.userAgent;
      this.dom=document.getElementById?1:0;
      this.opera5=this.agent.indexOf("Opera 5")>-1;
      this.opera6=this.agent.indexOf("Opera 6")>-1;
      this.opera7=this.agent.indexOf("Opera 7")>-1;
      this.opera=this.opera5||this.opera6||this.opera7;
      this.ie4=(document.all && !this.dom && !this.opera)?1:0;
      this.ie5=(this.dom && this.ver.indexOf("MSIE 5")>-1 && !this.opera)?1:0;
      this.ie6=(this.dom && this.ver.indexOf("MSIE 6")>-1 && !this.opera)?1:0;
      this.ie=this.ie4||this.ie5||this.ie6;
      this.mac=this.agent.indexOf("Mac")>-1;
      this.ns4=(document.layers && !this.dom)?1:0;
      this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
      this.ns7=(this.dom && parseInt(this.ver) >= 5) ?1:0;
      this.ns=this.ns4||this.ns6||this.ns7;
      this.bw=this.ie||this.ns||this.opera;
      return this
   }

// Escreve no documento em um ponto identificado pelo ID informado
   function lib_write(local_ID, local_HTML)
   {  if (lib_bw.ie) {  
          lib_gE(local_ID).innerHTML = local_HTML;
      }
      else if (lib_bw.ns && document.getElementById) { 
         rng = document.createRange();
         el = lib_gE(local_ID);
         rng.setStartBefore(el);
         htmlFrag = rng.createContextualFragment(local_HTML);
         while (el.hasChildNodes()) el.removeChild(el.lastChild);
         el.appendChild(htmlFrag);
      }
      else if (document.layers) {
         document.layer_name.document.write(local_HTML);
         document.layer_name.document.close();
      }
   }

// Altera o conteudo (value) de um componente
   function lib_value(tID, tConteudo) {
      lib_gE(tID).value = tConteudo;
   }

// Inicializacao de duas variaveis (GLOBAIS)
   var lib_bw=new lib_browser_check();
   var tXHR=XMLHTTPRequest();
