//Busqueda de por nombre de establecimientos
function MiramapaNombre(nombre,establecimientos,txt_nombre,contenedor){
	this.nombre = nombre;
	this.establecimientos = document.getElementById(establecimientos);
	this.txt_nombre = document.getElementById(txt_nombre);
	this.contenedor = document.getElementById(contenedor);
}
MiramapaNombre.prototype.setTXTNombre = function(param){
	if(param != null)this.txt_nombre.value = param;
	else this.txt_nombre.value = "";
}
MiramapaNombre.prototype.showEstablecimientos = function(){
	
	//Borramos markas y la info de mapa
	//map.clearOverlays();
	miramapaBusqueda.setPaginacion(null);
	miramapaBusqueda.setTitulo(null);
	
	this.visualizar();
	this.establecimientos.top = this.txt_nombre.offsetTop + 20;
	this.establecimientos.left = this.txt_nombre.offsetLeft + 20;
	this.establecimientos.innerHTML = "<img id='cargandoEstablecimientos' src='/miramapa/imagenes/ajax-loader-2.gif' />";
	
	var url = '/buscar/?des=' + escape(this.txt_nombre.value);
	
	FAjax(url, 'recepcionDatos', 'GET',null,null);
}
MiramapaNombre.prototype.listarEstablecimientos = function(arrEstablecimientos){
	
	var html = "";
	
	if(arrEstablecimientos != null){
		//var obj = new Establecimiento(arrEstablecimientos[p].COD_ESTABLECIMIENTO,arrEstablecimientos[p].DES_ESTABLECIMIENTO,arrEstablecimientos[p].COD_TIPO_ESTABLECIMIENTO,arrEstablecimientos[p].COD_POBLACION,null,arrEstablecimientos[p].LATITUD,arrEstablecimientos[p].LONGITUD,arrEstablecimientos[p].COD_TIPO_VIA,arrEstablecimientos[p].NOMBRE_VIA,arrEstablecimientos[p].NUMERO_VIA,arrEstablecimientos[p].ESCALERA,arrEstablecimientos[p].PLANTA,arrEstablecimientos[p].PUERTA,arrEstablecimientos[p].CODIGO_POSTAL,arrEstablecimientos[p].TELEFONO,arrEstablecimientos[p].URL_VIDEO,arrEstablecimientos[p].WEB,true,arrEstablecimientos[p].DES_TIPO_VIA,arrEstablecimientos[p].IMAGEN_ICONO,arrEstablecimientos[p].IMAGEN_SOMBRA,arrEstablecimientos[p].TEXTO_LIBRE);
		for(var p = 0; p <arrEstablecimientos.length; p++){
			html +=  "<a href='javascript:void(null)' onclick='miramapaNombre.goEstablecimiento(arrEstablecimientos[" + p + "]);'> - " + arrEstablecimientos[p].DES_ESTABLECIMIENTO + "</a><br/>"
		}
		
		if(arrEstablecimientos.length > 1){
			
			html += "<br /><a href='javascript:miramapaNombre.cerrar();' title='cerrar'>[x]</a>";
			this.establecimientos.innerHTML = html;
			this.visualizar();
		} else if (arrEstablecimientos.length == 1) {
			
			this.cerrar();
			miramapaNombre.goEstablecimiento(arrEstablecimientos[0]);
			this.txt_nombre.value = arrEstablecimientos[0].DES_ESTABLECIMIENTO;
			
		}
	} else {
		this.visualizar();
		//this.txt_nombre.focus();
		html = "<p class='sinResultados txtNegr11'>Busqueda sin resultados.</p>";
		this.establecimientos.innerHTML = html;
	}
}

MiramapaNombre.prototype.isEnter = function(evt){
		var key = (evt) ? evt.which : evt.keyCode;
		if(key==13)return true;
		return false;
}
			
MiramapaNombre.prototype.cerrar = function(){
			this.establecimientos.innerHTML = "";
			this.ocultar();
}
MiramapaNombre.prototype.ocultar = function(){
			this.establecimientos.style.display = "none";
}
MiramapaNombre.prototype.visualizar = function(){
			
			var pos = this.getAbsoluteElementPosition(this.contenedor.id)
			var aux = (isIE7)? 81 : 0;
			this.establecimientos.style.top = (pos.top + aux) + "px";
			this.establecimientos.style.left = pos.left + "px";
	
			this.establecimientos.style.display = "block";
}
MiramapaNombre.prototype.goEstablecimiento = function(destacado){
	
	this.txt_nombre.value = destacado.DES_ESTABLECIMIENTO;
	
	var lat = parseFloat(destacado.LATITUD);
	var lng = parseFloat(destacado.LONGITUD);
	var point = new GLatLng(lat,lng);
	
	goDestacados(destacado);

}
MiramapaNombre.prototype.goDireccion = function(lat,lng,zoom){
	map.setCenter(new GLatLng(lat,lng),zoom);
}
MiramapaNombre.prototype.getAbsoluteElementPosition = function(element) {
	  if (typeof element == "string")
		    element = document.getElementById(element)
		    
		  if (!element) return { top:0,left:0 };
		  
		  var y = 0;
		  var x = 0;
		  while (element.offsetParent) {
		    x += element.offsetLeft;
		    y += element.offsetTop;
		    element = element.offsetParent;
		  }
		  return {top:y,left:x};
}
