function selec_operacion_desac(clase){
var selec_operacion_desac = '<select name="operacion_ajax" class="'+clase+'" id="operacion_ajax">';
selec_operacion_desac += '<option value="0" selected>-</option></select>';
document.getElementById('selec_operacion').innerHTML = selec_operacion_desac;
}

var myConn_crear_variable_session_ad = new XHConn();
var terminado_crear_variable_session_ad = function (oXML) { document.getElementById('oculto').innerHTML = oXML.responseText; };
function crear_variable_session_ad(pas){
	//alert(pas);		
	myConn_crear_variable_session_ad.connect("estadisticas/variable_session_ad.php", "GET","pas="+pas, terminado_crear_variable_session_ad);
}


var con_selec_tipo = new XHConn();
if (!con_selec_tipo) alert("XMLHTTP no disponible. Navegador web antiguo o incompatible.");
var fin_selec_tipo = function (oXML) { document.getElementById('selec_tipo').innerHTML = oXML.responseText; };
function include_selec_tipo (idlocalidad,op){
	if (idlocalidad != "0"){
	document.getElementById('selec_tipo').innerHTML = "&nbsp;&nbsp;<img src=\"img/cargando_selec.gif\" width=\"75\" height=\"12\">";
		if (op == 'corp'){
		selec_operacion_desac('campos_busc3');
		}
		if (op == 'main'){
		selec_operacion_desac('campos_busc5');
		}
	window.setTimeout("con_selec_tipo.connect('buscador/selec_tipo.php', 'GET', 'idlocalidad="+idlocalidad+"&op="+op+"', fin_selec_tipo)", 1000);
	}
}


function activa_boton(){
var activa = '<a href="#" onclick="javascript:buscar();">';
activa += '<img src="img/bot_buscar_az2.gif" width="64" height="20" border="0"></a>';
document.getElementById('boton_buscar').innerHTML = activa;
}

var con_selec_operacion = new XHConn();
var fin_selec_operacion = function (oXML) { document.getElementById('selec_operacion').innerHTML = oXML.responseText; };
function include_selec_operacion (idlocalidad,idtipo,op){
	if ((idlocalidad != "0") && (idtipo != "0")) {
	document.getElementById('selec_operacion').innerHTML = "&nbsp;&nbsp;<img src=\"img/cargando_selec.gif\" width=\"75\" height=\"12\">";
	window.setTimeout("con_selec_operacion.connect('buscador/selec_operacion.php', 'GET', 'idlocalidad="+idlocalidad+"&idtipo="+idtipo+"&op="+op+"', fin_selec_operacion)", 1000);
	}
}

var con_previo_tabla = new XHConn();
function include_previo_tabla (idtipo, idlocalidad, tipo_previo){
	var fin_previo_tabla = function (oXML) { document.getElementById('previo').innerHTML = oXML.responseText; resize_tabla_previo(idtipo, idlocalidad, tipo_previo);};
	con_previo_tabla.connect("buscador/tabla_previo.php", "GET", "", fin_previo_tabla);
}

var con_previo_informativo = new XHConn();
var fin_previo_informativo = function (oXML) { document.getElementById('previo_informativo').innerHTML = oXML.responseText;};
function include_previo_informativo(idtipo, idlocalidad, tipo_previo){
	con_previo_informativo.connect("buscador/previo_informativo.php", "GET", "idtipo="+idtipo+"&idlocalidad="+idlocalidad+"&tipo_previo="+tipo_previo, fin_previo_informativo);
}

function muestra_previo(idtipo, idlocalidad, tipo_previo){

if (idlocalidad != "0"){
	if (tabla_previo_visible == "no"){
	include_previo_tabla (idtipo, idlocalidad, tipo_previo);
	} else {
	alfa_tabla_previo_informativo(idtipo, idlocalidad, tipo_previo);
	}
}

}

var tabla_previo_visible = "no";
function resize_tabla_previo(idtipo, idlocalidad, tipo_previo){
new Rico.Effect.Size( 'tabla_previo', 
null, // width 
163, // height
200, // 200ms
4, // steps
{complete:function() {include_previo_informativo(idtipo, idlocalidad, tipo_previo); carga_mapa(idlocalidad); tabla_previo_visible = "si";}} );
}

function alfa_tabla_previo_informativo(idtipo, idlocalidad, tipo_previo){
new Rico.Effect.FadeTo( 'tabla_previo_informativo', 
.0, // 20% opacity
500, // 500ms (1/2 second)
3, // 10 steps
{complete:function() {

document.getElementById('previo_informativo').innerHTML = "<div align=\"center\"><img src=\"img/cargando_previo.gif\" width=\"32\" height=\"32\"></div>";
window.setTimeout("include_previo_informativo('"+idtipo+"', '"+idlocalidad+"', '"+tipo_previo+"')", 1000);

}} );
}

var map; //hacemos global la variable para poder interactuar con otras funciones
function carga_mapa(idlocalidad) {
	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);
       		}
    	 }
	}
	request.send(null);
	
function inicia_mapa(longitud_centro, latitud_centro){
	document.getElementById('previo_mapa').style.width = '240px';
	document.getElementById('previo_mapa').style.height = '161px';

	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("previo_mapa"));
	map.addControl(new GSmallMapControl());
	map.setCenter(new GLatLng(latitud_centro, longitud_centro), 10);
	map.setMapType(G_NORMAL_MAP);

	function createInfoMarker(point, idlocalidad) {
	var marker = new GMarker(point, icon);
	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_main.php?idlocalidad='+idlocalidad+'\' marginheight=0 width=200 height=10></iframe></div>'); } );
	GEvent.addListener(marker, "mouseout", function() { hideddrivetip(); } );
	GEvent.addListener(marker, "click", function() { document.location.href='#';} );
	return marker;
	}
	
	var urlstr="buscador/xml_marcas_mapa.php";
	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 idlocalidad = parseFloat(markers[i].getAttribute("idlocalidad"));
			var marker = createInfoMarker(point, idlocalidad);
			map.addOverlay(marker);
       		}
    	 }
	}
 	 request.send(null);

} // fin funcion inicia mapa

} // fin carga_mapa


function desplaza_mapa(idlocalidad){
	
if ((tabla_previo_visible == "si") && (idlocalidad != "0")){
	
	muestra_previo('0', idlocalidad, 'localidad');
	
	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"));
			mueve_mapa(longitud_centro, latitud_centro, idlocalidad);
       		}
    	 }
	}
	request.send(null);

}
	
	function mueve_mapa(longitud_centro, latitud_centro, idlocalidad){
	map.panTo(new GLatLng(latitud_centro, longitud_centro));
	}

}

// 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;
}

function buscar(){
document.form_buscador.idlocalidad.value = document.form_selec_localidad.localidad_ajax.value;
document.form_buscador.idtipo.value = document.form_selec_tipo.tipo_ajax.value;
document.form_buscador.operacion.value = document.form_selec_operacion.operacion_ajax.value;
	if (document.form_buscador.idlocalidad.value == "0"){
	alert ("Seleccione una localidad");
	} else {
		if (document.form_buscador.idtipo.value == "0"){
		alert ("Seleccione el tipo de inmueble que quiere buscar");
		} else {
		document.form_buscador.submit();
		}
	}
}
function buscar_referencia(){
	buscar_global = document.getElementById('busca_ref').value;
	buscar_global = buscar_global.replace(/'/g, ""); 
	if (buscar_global == ""){
		alert("Debe escribir una referencia");
	} else {
		//alert('ok');
		document.form_referencia.submit();
	}

}

// Buscador corporativo (en js_directorio.js existe un duplicado de funciones de buscador corporativo)------------------------------------------------

var con_buscador_corporativo = new XHConn();
var fin_buscador_corporativo = function (oXML) { document.getElementById('div_buscador_corporativo').innerHTML = oXML.responseText; };
function include_buscador_corporativo (){
	document.getElementById('div_buscador_corporativo').innerHTML = "<div align=\"center\"><br><br><img src=\"img/cargando_previo.gif\" width=\"32\" height=\"32\"><br><br></div>";
	con_selec_operacion.connect("buscador_corporativo.php", "GET", "", fin_buscador_corporativo);
}

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);
}

// 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="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';
	}
}

