
function selec_filtroB(filtroA){
	var myConn_filtroB = new XHConn();
	document.getElementById('div_selec_filtroB').innerHTML = '<img src="img/cargando_selec2.gif" width="66" height="20">';
	//alert(filtroA+' '+tipo_global+' '+idlocalidad_global+' '+operacion_global);
	var fin_filtroB = function (oXML) { document.getElementById('div_selec_filtroB').innerHTML = oXML.responseText;};
	myConn_filtroB.connect("../buscador/selec_filtroB.php", "GET", "filtroA="+filtroA+"&tipo="+tipo_global+"&idlocalidad="+idlocalidad_global+"&operacion="+operacion_global, fin_filtroB);
}

var con_list_inmuebles = new XHConn();
var fin_list_inmuebles = function (oXML) { document.getElementById('list_inmuebles').innerHTML = oXML.responseText; bb_save_state();};
function include_list_inmuebles (){
	cargando_inmuebles = '<table width="628" height="120" border="0" align="center" cellpadding="0" cellspacing="0" class="borde_exterior_gr"><tr>';
	cargando_inmuebles += '<td><div align="center"><span class="txt_gr_12">Localizando inmuebles...</span><br> <br>';
	cargando_inmuebles += '<img src="img/barra_progreso.gif" width="214" height="15"></div></td></tr></table>';
	document.getElementById('list_inmuebles').innerHTML = cargando_inmuebles;
	//alert('idlocalidad='+idlocalidad_global+'&idtipo='+tipo_global+'&operacion='+operacion_global+'&pagina='+pagina_global+'&precio_min='+precio_min_global+'&precio_max='+precio_max_global);
	window.setTimeout("con_list_inmuebles.connect('../list_inmuebles.php', 'GET', 'idlocalidad="+idlocalidad_global+"&idtipo="+tipo_global+"&operacion="+operacion_global+"&pagina="+pagina_global+"&precio_min="+precio_min_global+"&precio_max="+precio_max_global+"&filtro_global="+filtro_global+"&busca_ref="+buscar_global+"', fin_list_inmuebles)", 1000);
}


var con_alertas = new XHConn();
var fin_alertas  = function (oXML) { document.getElementById('sistema_alertas').innerHTML = oXML.responseText; bb_save_state();};
function include_alertas (){
	document.getElementById('sistema_alertas').innerHTML = "<div align=\"center\"><br><br><img src=\"img/cargando_previo.gif\" width=\"32\" height=\"32\"><br><br></div>";
	con_alertas.connect("sistema_alertas.php", "GET", "", fin_alertas);
}

var con_selector_precios = new XHConn();
function include_selector_precios(idlocalidad,idtipo,operacion){
	fin_selector_precios = function (oXML) { document.getElementById('selector_precios').innerHTML = oXML.responseText; carga_mapa(idlocalidad,idtipo,operacion); bb_save_state();};
	document.getElementById('selector_precios').innerHTML = "<div align=\"center\"><br><br><img src=\"img/cargando_previo.gif\" width=\"32\" height=\"32\"><br><br></div>";
	window.setTimeout("con_selector_precios.connect('../buscador/selector_precios.php', 'GET', 'idlocalidad="+idlocalidad_global+"&idtipo="+tipo_global+"&operacion="+operacion_global+"', fin_selector_precios)", 1000);
}


function valores_selector(visu_min,visu_max){
pagina_global = 1;
filtro_global = "0";
precio_min_global = visu_min;
precio_max_global = visu_max;
include_list_inmuebles();
}

function click_barrio(idbarrio){
pagina_global = 1;
filtro_global = "barrio/"+idbarrio;
precio_min_global = "0";
precio_max_global = "0";
include_list_inmuebles();
}

function ir_a_pagina(pagina){
	pagina_global = pagina;
	include_list_inmuebles();
}

var selec_operacion_desac = '<select name="operacion_ajax" class="campos_busc4" id="operacion_ajax">';
selec_operacion_desac += '<option value="0" selected>-</option></select>';




var map; //hacemos global la variable para poder interactuar con otras funciones
function carga_mapa(idlocalidad,idtipo,operacion) {
	var urlstr="buscador/xml_centro_mapa.php?idlocalidad="+idlocalidad;
	var request = GXmlHttp.create();
	request.open("GET", urlstr, true);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
		var xmlDoc = request.responseXML;
		var markers = xmlDoc.documentElement.getElementsByTagName("marker");
			for (var i = 0; i < markers.length; i++) {
			longitud_centro = parseFloat(markers[i].getAttribute("lng"));
			latitud_centro = parseFloat(markers[i].getAttribute("lat"));
       		inicia_mapa(longitud_centro,latitud_centro,idlocalidad,idtipo,operacion);
			}
    	 }
	}
	request.send(null);
	
function inicia_mapa(longitud_centro,latitud_centro,idlocalidad,idtipo,operacion){

	document.getElementById('mapa_busqueda').style.width = '228px';
	document.getElementById('mapa_busqueda').style.height = '230px';

	var icon = new GIcon();
	icon.image = "http://www.promofincas.es/img/marca_promo.png";
	icon.shadow = "http://www.promofincas.es/img/sombra_marca.png";
	icon.iconSize = new GSize(20, 34);
	icon.shadowSize = new GSize(37, 34);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(5, 1);

	map = new GMap2(document.getElementById("mapa_busqueda"));
	map.addControl(new GSmallMapControl());
	map.setCenter(new GLatLng(latitud_centro, longitud_centro), 13);
	map.setMapType(G_NORMAL_MAP);

	function createInfoMarker(point, idbarrio, idlocalidad, idtipo, operacion) {
	var marker = new GMarker(point, icon);
	// cargamos el contenido del detalle dentro de un iframe para solucionar el bug de Explorer con el z-index de los desplegables
	GEvent.addListener(marker, "mouseover", function() { ddrivetip('<div id=\'div_detalle_mapa\' align=\'center\'><IFRAME name=\'f_detalles\' id=\'f_detalles\' frameborder=0 scrolling=no marginwidth=0 src=\'../buscador/detalles_mapa_busqueda.php?idbarrio='+idbarrio+'\' marginheight=0 width=200 height=10></iframe></div>');} );
	GEvent.addListener(marker, "mouseout", function() { hideddrivetip(); } );
	GEvent.addListener(marker, "click", function() { document.location.href='javascript:click_barrio('+idbarrio+');';} );
	return marker;
	}
	
	var urlstr="../buscador/xml_marcas_mapa_busqueda.php?idlocalidad="+idlocalidad;
	var request = GXmlHttp.create();
	request.open("GET", urlstr, true);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
		var xmlDoc = request.responseXML;
		var markers = xmlDoc.documentElement.getElementsByTagName("marker");
			for (var i = 0; i < markers.length; i++) {
			var point = new GPoint(parseFloat(markers[i].getAttribute("lng")), parseFloat(markers[i].getAttribute("lat")));
			//var address = '<table width=\"182\" height=\"90\" border=\"0\" class=\"borde_tabla_azul\" bgcolor=\"#FFFFCC\"><tr><td height=\"18\" bgcolor=\"#4D6DA8\" class=\"txt2 Estilo1\"><div align=\"center\">'+markers[i].getAttribute("localidad")+'</div></td></tr><tr><td class=\"txt2\"><div align=\"center\">'+markers[i].getAttribute("nom_tipo")+' en venta: <span class=\"Estilo4\">'+markers[i].getAttribute("inmuebles_venta")+'</span></div></td></tr><tr><td class=\"txt2\"><div align=\"center\">'+markers[i].getAttribute("nom_tipo")+' en alquiler: <span class=\"Estilo4\">'+markers[i].getAttribute("inmuebles_alquiler")+'</span> </div></td></tr><tr><td class=\"txt2\"><div align=\"center\">Precio medio venta: <span class=\"Estilo4\">'+markers[i].getAttribute("precio_medio")+' €</span> </div></td></tr></table>';
			//var address = 'prueba';
			var marker = createInfoMarker(point, parseFloat(markers[i].getAttribute("idbarrio")),idlocalidad,idtipo,operacion);
			map.addOverlay(marker);
       		}
			bb_save_state();
    	 }
	}
 	 request.send(null);
} // fin funcion inicia mapa

} // fin carga_mapa


// función que redimensiona el iframe que se carga en el div de detalles de marca
function redimensiona()
{
  var altura=document.getElementById('f_detalles').contentWindow.document.body.scrollHeight;
  document.getElementById('f_detalles').height=altura;
//  document.getElementById('div_detalle_mapa').style.height=altura;
}

//var con_detalle_mapa = new XHConn();
//var fin_detalle_mapa = function (oXML) { document.getElementById('div_detalle_mapa').innerHTML = oXML.responseText; };
//function include_detalle_mapa (idbarrio){
	//document.getElementById('div_detalle_mapa').innerHTML = "<img src=\"img/cargando_selec.gif\" width=\"75\" height=\"12\">";
	//con_detalle_mapa.connect("buscador/detalles_mapa_busqueda.php", "GET", "idbarrio="+idbarrio, fin_detalle_mapa);
//}

var con_modo_alerta = new XHConn();
var fin_modo_alerta = function (oXML) { document.getElementById('div_modo_contacto').innerHTML = oXML.responseText;};
function include_modo_alerta(modo){
	var cargando_modo = '<table width="393" height="100" border="0" align="center" cellpadding="0" cellspacing="10" class="borde_exterior_gr"><tr>';
    cargando_modo += '<td height="10"><table width="100%"  border="0" cellpadding="0" cellspacing="0"><tr><td><div align="center" class="txt_az_11">';
    cargando_modo += '<span class="txt_az2_14_">Cargando...</span> <img src="img/cargando_selec.gif" width="75" height="12" align="absmiddle"><br></div></td></tr></table></td></tr></table><br>';
	document.getElementById('div_modo_contacto').innerHTML = cargando_modo;
	if (modo == "email"){
	window.setTimeout("con_modo_alerta.connect('../buscador/sistema_alertas/opcion_email.php', 'GET', '', fin_modo_alerta)", 1000);
	}
	if (modo == "sms"){
	window.setTimeout("con_modo_alerta.connect('../buscador/sistema_alertas/opcion_sms.php', 'GET', '', fin_modo_alerta)", 1000);
	}
	if (modo == "telefono"){
	window.setTimeout("con_modo_alerta.connect('../buscador/sistema_alertas/opcion_telefono.php', 'GET', '', fin_modo_alerta)", 1000);
	}
}

var con_solicitar_alerta = new XHConn();
var fin_solicitar_alerta = function (oXML) { document.getElementById('div_form_alertas').innerHTML = oXML.responseText; };
function solicitar_alerta(modo,localidad,inmueble,operacion,obra_nueva,superficie,habitaciones,ascensor,precio_desde,precio_hasta,nombre,comentarios,dato_opcion){
	document.getElementById('div_form_alertas').innerHTML = "<div align=\"center\"><br><br><img src=\"img/cargando_previo.gif\" width=\"32\" height=\"32\"><br><br></div>";
	con_solicitar_alerta.connect("../buscador/sistema_alertas/procesa_solicitud.php", "GET", "modo="+modo+"&localidad="+localidad+"&inmueble="+inmueble+"&operacion="+operacion+"&obra_nueva="+obra_nueva+"&superficie="+superficie+"&habitaciones="+habitaciones+"&ascensor="+ascensor+"&precio_desde="+precio_desde+"&precio_hasta="+precio_hasta+"&nombre="+nombre+"&comentarios="+comentarios+"&dato_opcion="+dato_opcion, fin_solicitar_alerta);
}


function buscar(){
 precio_min_global = "0";
 precio_max_global = "0";
 filtro_global = "0";
	buscar_global = "0";
 pagina_global = 1;
 idlocalidad_global = document.form_selec_localidad.localidad_ajax.value;
 tipo_global = document.form_selec_tipo.tipo_ajax.value;
 operacion_global = document.form_selec_operacion.operacion_ajax.value;
	//alert(pagina_global+' '+precio_min_global+' '+precio_max_global);
	//alert(tipo_global+' '+idlocalidad_global+' '+operacion_global);
	if (idlocalidad_global == "0"){
	alert ("Seleccione una localidad");
	} else {
		if (tipo_global == "0"){
		alert ("Seleccione el tipo de inmueble que quiere buscar");
		} else {
		bb_save_state (); //guarda historico virtual
		contador_historico(); // incrementamos el contador del histórico virtual
		include_list_inmuebles();
		carga_mapa(idlocalidad_global,tipo_global,operacion_global);
		include_selector_precios(idlocalidad_global,tipo_global,operacion_global);
		}
	}
}


function filtro_busqueda(){
	precio_min_global = "0";
	 precio_max_global = "0";
 	filtro_global = "0";
	buscar_global = "0";
	pagina_global = 1;
	var filtroA = document.getElementById('filtroA').value;
	var filtroB = document.getElementById('filtroB').value;
	//alert(filtroA+'/'+filtroB);
	if (filtroA == "0"){
		alert("Debe seleccionar una opción de filtrado");
	} else {
		filtro_global = filtroA+'/'+filtroB;
		include_list_inmuebles();
	}
}

function busqueda_ref(){
	 precio_min_global = "0";
	 precio_max_global = "0";
 	filtro_global = "0";
	 pagina_global = 1;
	 buscar_global = document.getElementById('busca_ref').value;
	//alert(buscar_global);
	buscar_global = buscar_global.replace(/'/g, ""); 
	if (buscar_global == ""){
		alert("Debe escribir una referencia");
	} else {
		include_list_inmuebles();
		include_selector_precios(idlocalidad_global,tipo_global,operacion_global);
	}
}




function overTD(td,color){td.style.background=color;} 
function outTD(td,color){td.style.cursor='hand';td.style.background=color;} 


//-- Ficha de inmueble ---------------------------------------//


var con_ficha= new XHConn();
var fin_ficha = function (oXML) { document.getElementById('ficha_inmueble').innerHTML = oXML.responseText; contador_historico(); bb_save_state();};
function ficha(idinmueble,idlocalidad,idtipo,operacion,pagina,precio_min,precio_max,idespecial,idsubtipo,idbarrio){
	cargando_ficha = '<table width="628" height="120" border="0" align="center" cellpadding="0" cellspacing="0" class="borde_exterior_gr"><tr>';
	cargando_ficha += '<td><div align="center"><span class="txt_gr_12">Cargando ficha de inmueble...</span><br> <br>';
	cargando_ficha += '<img src="img/barra_progreso.gif" width="214" height="15"></div></td></tr></table>';
	document.getElementById('ficha_inmueble').innerHTML = cargando_ficha;
	window.setTimeout("con_ficha.connect('../ficha.php', 'GET', 'idinmueble="+idinmueble+"&idlocalidad="+idlocalidad+"&idtipo="+idtipo+"&operacion="+operacion+"&pagina="+pagina+"&precio_min="+precio_min+"&precio_max="+precio_max+"&idespecial="+idespecial+"&idsubtipo="+idsubtipo+"&idbarrio="+idbarrio+"', fin_ficha)", 1000);
}

var con_aviso_legal= new XHConn();
var fin_aviso_legal = function (oXML) { document.getElementById('aviso_legal').innerHTML = oXML.responseText; };
function aviso_legal(){
	con_aviso_legal.connect('../buscador/aviso_legal.php', 'GET', '', fin_aviso_legal);
}

var con_tiene_hipoteca= new XHConn();
var fin_tiene_hipoteca = function (oXML) { document.getElementById('tiene_hipoteca').innerHTML = oXML.responseText; };
function tiene_hipoteca(){
	con_tiene_hipoteca.connect('../buscador/iframe_tiene.php', 'GET', '', fin_tiene_hipoteca);
}

var con_sorteo_hipoteca= new XHConn();
var fin_sorteo_hipoteca = function (oXML) { document.getElementById('sorteo_hipoteca').innerHTML = oXML.responseText; };
function sorteo_hipoteca(){
	con_sorteo_hipoteca.connect('../buscador/iframe_sorteo.php', 'GET', '', fin_sorteo_hipoteca);
}

var con_contacto_ficha= new XHConn();
var fin_contacto_ficha = function (oXML) { document.getElementById('div_contacto').innerHTML = oXML.responseText; };
function contacto_ficha(nombre,telefono,email,comentarios,idinmueble,aleatorio){
con_contacto_ficha.connect("../mailform/mail_contacto_ficha.php", "GET", "nombre="+nombre+"&telefono="+telefono+"&email="+email+"&comentarios="+comentarios+"&idinmueble="+idinmueble+"&aleatorio="+aleatorio, fin_contacto_ficha);
}


var con_foto = new XHConn();
var fin_foto= function (oXML) { document.getElementById('div_cont_img').innerHTML = oXML.responseText; };
function visu_img(foto){
	var cargando = '<table width="180" height="180" border="0" cellpadding="0" cellspacing="0"><tr>';
    cargando += '<td><div align="center" class="txt_12_ng"><img src="http://www.promofincas.es/img/cargando2.gif" width="16" height="16"><br><br>cargando imagen...<br></div></td></tr></table>';
	document.getElementById('div_cont_img').innerHTML = cargando;
	window.setTimeout("con_foto.connect('../buscador/visu_foto.php', 'GET', 'foto="+foto+"', fin_foto)", 1000);
}
var con_tour = new XHConn();
var fin_tour= function (oXML) { document.getElementById('div_cont_img').innerHTML = oXML.responseText; };
function visu_tour(tour){
	var cargando = '<table width="180" height="180" border="0" cellpadding="0" cellspacing="0"><tr>';
    cargando += '<td bgcolor="#FFFFFF"><div align="center" class="txt_12_ng"><img src="http://www.promofincas.es/img/cargando2.gif" width="16" height="16"><br><br>cargando imagen...<br></div></td></tr></table>';
	document.getElementById('div_cont_img').innerHTML = cargando;
	window.setTimeout("con_tour.connect('../buscador/visu_tour.php', 'GET', 'tour="+tour+"', fin_tour)", 1000);
}
var con_video = new XHConn();
var fin_video= function (oXML) { document.getElementById('div_cont_img').innerHTML = oXML.responseText; };
function visu_video(video){
	var cargando = '<table width="180" height="210" border="0" cellpadding="0" cellspacing="0"><tr>';
    cargando += '<td bgcolor="#FFFFFF"><div align="center" class="txt_12_ng"><img src="http://www.promofincas.es/img/cargando2.gif" width="16" height="16"><br><br>cargando video...<br></div></td></tr></table>';
	document.getElementById('div_cont_img').innerHTML = cargando;
	window.setTimeout("con_video.connect('../buscador/visu_video.php', 'GET', 'video="+video+"', fin_video)", 1000);
}

function inicia_calculo_hipoteca(){

	if (document.form_hipoteca.importe_selec.value == ""){
	alert ("Debe especificar el importe de hipoteca que desea solicitar");
	} else {

	document.miForm.importe.value = "";
	document.miForm.interes.value = "";
	document.miForm.amortizacion.value = "";
	document.miForm.cuota.value = "";

	document.miForm.importe.value = document.form_hipoteca.importe_selec.value;
	document.miForm.interes.value = document.form_hipoteca.interes_selec.value;
	document.miForm.amortizacion.value = document.form_hipoteca.amortizacion_selec.value;

	calcula();
	document.getElementById('div_cuota_hipoteca').innerHTML = "<span class=\"txt_nar_16_n\">&nbsp;"+document.miForm.cuota.value+" &euro;</span>";
	
	}

}

function validar_contacto(){
	if (document.form_contacto.nombre.value == ''){
	alert ("Por favor, escribe tu nombre");
	} else {
		if ((document.form_contacto.telefono.value == '') && (document.form_contacto.email.value == '')){
		alert ("Por favor, especifica tu número de teléfono o tu dirección de e-mail para que podamos contactar contigo");
		} else {
		contacto_ficha(document.form_contacto.nombre.value,document.form_contacto.telefono.value,document.form_contacto.email.value,document.form_contacto.comentarios.value,document.form_contacto.idinmueble.value,document.form_contacto.aleatorio.value)
		}
	}
}

// Gerenador de etiquetas ALT--------------------------------------------

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="http://www.promofincas.es/img/arrow2.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip
//------------------------------------------------------------


function menu(bot,accion){
	if (accion == "over"){
	document.getElementById('bot'+bot).className = 'bot_menu_over';
	} else {
	document.getElementById('bot'+bot).className = 'bot_menu';
	}
}
