﻿<!--
// Thomas A. Semple - thomas.semple@t4w.com.br
// T4W Soluções Empresariais e Web
// Todos direitos reservados
// http://www.t4w.com.br
var bNaoFechar = false;
var sGlobalPagina = '';
var sParamAdicional = '';
var iCountExibir = 0;
var oDiv;
var odivMostrar;
var GlobalPagina = '';
var GlobalCampoID = '';
var GlobalTexto = '';
var GlobalCampoValor = '';
var GlobalFornecedorID = '';
function exibirOpcoes(oCampo, keypress, sPagina, sCampoValor, sNomeDiv, sLeftPx, iFornID) {
    try{
        ocultarDDLs('none');
    }catch(e){
    }
    var sTexto = oCampo.value;	 
    if ((sNomeDiv != null) && (sNomeDiv != null)){
       oDiv = document.getElementById('opcoes_' + sNomeDiv);
       odivMostrar = document.getElementById('mostrar_' + sNomeDiv );
    } else {
       oDiv = document.getElementById('opcoes_' + sPagina );
       odivMostrar = document.getElementById('mostrar_' + sPagina );
    }
    if (sLeftPx != null) oDiv.style.left = sLeftPx + 'px';
    var iCountMAX = 10;
    sGlobalPagina = sPagina;
    var whichCode = (window.Event) ? keypress.which : keypress.keyCode;
    if (whichCode == undefined) whichCode = keypress.keyCode;
    if (whichCode == 13) return false;
    if (whichCode == 9 ) {
     	oDiv.style.display='none';
        tmrocultarOpcoes();
        return false;
    }
    if (whichCode == 40) {
        iCountExibir = iCountExibir + 1;
    } else {
        if (whichCode == 38) {
            iCountExibir = iCountExibir - 1;
       }  else {
            iCountExibir = 0;
       }
    }
    if (iCountExibir < 0 || iCountExibir > iCountMAX) iCountExibir = 0;	
    if ((sTexto.length > 0) && (iCountExibir == 0)) {
        oDiv.style.display = '';
        document.getElementById(sCampoValor).value = '0';
        oDiv.style.width = oCampo.style.width;
        odivMostrar.innerHTML = "...loading...";        
        GlobalPagina = sPagina;
        GlobalCampoID = oCampo.id;
        GlobalTexto = sTexto;
        GlobalCampoValor = sCampoValor;
        GlobalFornecedorID = iFornID;
        setTimeout(chamarXMLListaTMR, 10);    
    }
    else {
       oDiv.style.display='none';
    }
	if (iCountExibir > 0) {
	    for (var iLiBG=0;iLiBG<= iCountMAX;iLiBG++) {
	      try{
	         var oLiBG = document.getElementById('valor' + sPagina + '0' + iLiBG );
	         oLiBG.style.backgroundColor = '';
	      }catch(e){
	      }
	    }
	    try{
	        var oLi = document.getElementById('valor' + sPagina + '0' + iCountExibir );
	        oLi.style.backgroundColor = 'gold';
	        if (sCampoValor != '') document.getElementById(sCampoValor).value = oLi.value;
	       	oCampo.value = oLi.innerHTML;
	        oDiv.style.display='';
	    } catch(e) {
	    }
	}
	return false
}
function chamarXMLListaTMR(){
   var resultado = chamarXMLLista(GlobalCampoID, GlobalTexto, GlobalPagina, GlobalCampoValor,GlobalFornecedorID);
   if (odivMostrar != null) odivMostrar.innerHTML = resultado;
}                  
function ocultarOpcoes() {
    if (oDiv != null) oDiv.style.display='none';
    try{
        ocultarDDLs('');
    }catch(e){
    }
}
function atribuirValor( sControleID, sValor, sPagina, sCampoValor, sValorOculto ) {
    var oControle = window.document.getElementById(sControleID);
    oControle.value = sValor;
    if (sCampoValor != '') document.getElementById(sCampoValor).value = sValorOculto;
    tmrocultarOpcoes();
}
function chamarXMLLista( sControle, sPesquisa, sPagina, sCampoValor,iFornID ) {
  var ajax;
  ajax = ajaxT4W();
  try{
     var data = new Date();
     ajax.open("GET", '../AutoComplete/' + sPagina + '.aspx?psq=' + sPesquisa + sParamAdicional + '&ctr=' + sControle + '&fldVlue=' + sCampoValor +'&FornecedorID='+ iFornID +'&d=' + data +'&AutoID='+sPagina , false);
     ajax.setRequestHeader('Content-Type', 'text/xml');
     ajax.onreadystatechange = function () {
     if (ajax.readyState == 4) {
         if (ajax.status == 200) return ajax;
        }
     }
     ajax.send(null);
  }
     catch(e){
     alert('erro pag: ' + e);
  }
  return ajax.responseText;
}
function tmrocultarOpcoes(){
    setTimeout( ocultarOpcoes, 500);
}
function ajaxT4W() {
   try{
       var sErr = "O Browser não possui suporte a XMLHttp."
       if (typeof XMLHttpRequest != "undefined") {
           return new XMLHttpRequest();
        } else if (window.ActiveXObject) {
           var arrVersao = ["Microsoft.XMLHttp","XMLHttpRequest","MSXML2.XMLHttp.5.0",
           "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp"];
          for (var i = 0; i < arrVersao.length; i++) {
          try {
             var oXmlHttp = new ActiveXObject(arrVersao[i]);
             return oXmlHttp;
            } catch (e01) {
          }
        }
      }
    }
    catch(e02)
    {
    }
}
function blockenter(keypress) {
    var whichCode = (window.Event) ? keypress.which : keypress.keyCode;     
    if (whichCode == undefined) whichCode = keypress.keyCode;   
    if ( whichCode == 13 ) {
       tmrocultarOpcoes();
       return false;
    }
    else{
       return true;
    }
}
function atualizarRPT(sEndereco, sDiv) {
  var oDiv = window.document.getElementById(sDiv);
  var ajax;
  ajax = ajaxT4W();
  try{
     var data = new Date();
     var qry = "&";
     var auxEndereco = sEndereco.split("?");
     if (auxEndereco.length <=1) qry = "?";
     sEndereco = sEndereco + qry + data;
     ajax.open("GET", sEndereco , false);
     ajax.setRequestHeader('Content-Type', 'text/xml');
     ajax.onreadystatechange = function () {
     if (ajax.readyState == 4) {
         if (ajax.status == 200) return ajax;
        }
     }
     try{
        ajax.send(null);  
     } catch(eSend){     
     }
  }
  catch(e){
      alert('erro pag: ' + e);
  }
  if (oDiv != null) oDiv.innerHTML = ajax.responseText;
}
function registrarJSAjaxT4W(JSAjax, chamada) {
    eval(JSAjax);
    var ret = eval(chamada);
}

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
 
 
} 




-->



