function set_focus() {
	//document.getElementById("txt_palabrabuscar").focus();
}

var xmlhttp_pool = new Array();
function search_me() {
	var xmlhttp;

	// Set up the XmlHttp object (This is some ugly uber cross browser way to do it)
	xmlhttp_pool[xmlhttp_pool.length] = false;
	var xmlhttp = xmlhttp_pool[xmlhttp_pool.length];

	if (!xmlhttp && typeof XMLHttpRequest!="undefined") {
		try {
			xmlhttp = new XMLHttpRequest();			
		} catch (e) {
			xmlhttp = false;
		}
	}

	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}

	//necesario para funcionar en iexplorer 6
	/*@cc_on @if (@_win32 && @_jscript_version >= 5) if (!window.XMLHttpRequest)
		window.XMLHttpRequest = function() { return new ActiveXObject('Microsoft.XMLHTTP') }
	@end @*/
			
	xmlhttp.open("POST", "/systems/resultadobusqueda.asp", true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			var results = unescape(xmlhttp.responseText);
			results=results.replace(/\+/gi," ");

			// The first line is "txt_palabrabuscar:matches:time_it_took" and everything after that are HTML search results
			var lines = results.split("\n");
			// Get the first line meta-data
			var data = lines.shift();
			data = data.split(":");
			
			txt_palabrabuscar = data[0];
			match_count = data[1];
			search_time = data[2];

			// The HTML search data is everything left over			
			var search_results = lines.join("");			
			var arreglocategorias = search_results.split("otracategoria")

			//var header_str = "Se encontraton " + match_count + " registros en " + search_time + " segundos";
			//if (match_count == 0) { header_str = ""; }
			var lngarticulos = arreglocategorias[0].length;			
			document.getElementById("articulos_resultados").innerHTML = "<ul>" + arreglocategorias[0] + "</ul>";
			if(lngarticulos > 1){ //si hay resultados de articulos 
				document.getElementById("articulos_vermas").style.display='block'; 
			}else{
				document.getElementById("articulos_vermas").style.display='none'; 
				
			}
			
			document.getElementById("medicinas_resultados").innerHTML = "<ul>" + arreglocategorias[1] + "</ul>";
			document.getElementById("productos_resultados").innerHTML = "<ul>" + arreglocategorias[2] + "</ul>";
			//document.getElementById('medicinas_resultados').scrollTop  = 0;			
			//document.getElementById("search_header").innerHTML = header_str;
		}
	}	
	
	var txt_palabrabuscar = document.getElementById("txt_palabrabuscar").value;
	txt_palabrabuscar = escape(txt_palabrabuscar);	
	
	//checkbox opcionales
	//palabra completa
	var varTipobusqueda = "";
	//var rtipobusqueda0 = document.frm_buscador.rtipobusqueda[0].checked;
	//if (rtipobusqueda0 == true) {
	//	varTipobusqueda = "&rtipobusqueda=1";
	//}

	//var rtipobusqueda1 = document.frm_buscador.rtipobusqueda[1].checked;
	//if (rtipobusqueda1 == true) {
	//	varTipobusqueda = "&rtipobusqueda=2";		
	//}
		
	var params = "txt_palabrabuscar=" + txt_palabrabuscar + varTipobusqueda;
	xmlhttp.send(params);	
}

