// JavaScript Document
function mostra(id){
	document.getElementById(id).style.display='';
}
			
function esconde(id){
	document.getElementById(id).style.display='none';
}

function openAjax() {

var ajax;

try{
    ajax = new XMLHttpRequest(); 
}catch(ee){
    try{
        ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
    }catch(e){
        try{
            ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
        }catch(E){
            ajax = false;
        }
    }
}
return ajax;
}

function qryDinamica() {
	if(document.getElementById) { 
		var termo = document.getElementById('produto').value; 
		cod_categoria = document.getElementById('codigo_categoria').value;
		var exibeResultado = document.getElementById('res'); 
		if(termo !== "" && termo !== null && termo.length >= 3) { 
			var ajax = openAjax(); 
			ajax.open("get", "busca_dinamica.asp?produto=" + termo + "&tipo_busca=palavra&codigo_categoria=" + cod_categoria + "&varLang=pt_BR", true); 
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 1) { 
					exibeResultado.innerHTML = "";
				}
				if(ajax.readyState == 4) { 
					if(ajax.status == 200) {
						var resultado = ajax.responseText; 
						resultado = resultado.replace(/\+/g," "); 
						resultado = unescape(resultado); 
						exibeResultado.innerHTML = resultado;
						mostra('res'); 
					} else {
						exibeResultado.innerHTML = "";
						esconde('res'); 
					}
				}
			}
			ajax.send(null); 
		} 
	}
}	
	function fill(thisValue) {
		setTimeout("esconde('res'); ", 200);
	}