var xmlhttp;
function clickDesplegable(strid) {
id = document.getElementById('div_'+strid);
	if(id.style.display=='block') {
		id.style.display='none';
	} else {
		document.getElementById('div_tipoinmueble').style.display='none';
		document.getElementById('div_precio').style.display='none';
		document.getElementById('div_tamanomin').style.display='none';
		document.getElementById('div_dormitorios').style.display='none';
		document.getElementById('div_orden').style.display='none';
		id.style.display='block';		
	}
	return true;
}
function unclickDesplegable(strid) {
	id = document.getElementById('div_'+strid);
	id.style.display='none';
	return true;
}
function eod(strid, strvalue, strtext, strcolor) {
	id = document.getElementById('div_'+strid);
	id.style.display='none';
	idhidden = document.getElementById('input_'+strid);
	idhidden.value = strvalue;
	idtd = document.getElementById('td_'+strid);
	idtd.innerHTML = strtext;
	idtd.style.backgroundColor = '#'+strcolor;
	idtd.style.color = '#0066cc';		
	return true;	
}
function eodo(strid, strvalue, strtext, keyword) {
	id = document.getElementById('div_'+strid);
	id.style.display='none';
	idhidden = document.getElementById('input_'+strid);
	idhidden.value = strvalue;
	idkeyword = document.getElementById('keyword2');
	idkeyword.value = keyword;
	idtd = document.getElementById('td_'+strid);
	idtd.innerHTML = strtext;
	idtd.style.backgroundColor = '#EFF0FF';
	idtd.style.color = '#0066cc';	
	id = document.getElementById('div_'+strid);
	id.style.display='none';
	id = document.getElementById('s2');
	id.value='n';
	a4 = document.getElementById('form');
	a4.submit();
}
function eodz(strid, strvalue, strtext, keyword) {
	id = document.getElementById('div_'+strid);
	id.style.display='none';
	idhidden = document.getElementById('input_'+strid);
	idhidden.value = strvalue;
	idkeyword = document.getElementById('keyword2');
	idkeyword.value = keyword;
	idtd = document.getElementById('td_'+strid);
	idtd.innerHTML = strtext;
	idtd.style.backgroundColor = '#EFF0FF';
	idtd.style.color = '#0066cc';	
	id = document.getElementById('div_'+strid);
	id.style.display='none';
	//id = document.getElementById('s2');
	//id.value='n';
	a4 = document.getElementById('form');
	a4.submit();
}
function eodr(strid, strvalue, strtext, keyword) {
	id = document.getElementById('div_'+strid);
	id.style.display='none';
	idhidden = document.getElementById('input_radiobusqueda');
	idhidden.value = strvalue;
	idkeyword = document.getElementById('keyword');
	idkeyword.value = keyword;
	idtd = document.getElementById('td_'+strid);
	idtd.innerHTML = strtext;
	idtd.style.backgroundColor = '#EFF0FF';
	idtd.style.color = '#0066cc';			
	a4 = document.getElementById('form');
	a4.submit();
}
function eodr2(strid, strvalue, strtext, keyword) {
	id = document.getElementById('div_'+strid);
	id.style.display='none';
	idhidden = document.getElementById('input_radiobusqueda2');
	idhidden.value = strvalue;
	idkeyword = document.getElementById('keyword');
	idkeyword.value = '';
	idtd = document.getElementById('td_'+strid);
	idtd.innerHTML = strtext;
	idtd.style.backgroundColor = '#EFF0FF';
	idtd.style.color = '#0066cc';			
	a4 = document.getElementById('form');
	a4.submit();
}
var encN=3;
function decodeTxt(s){
var s1=unescape(s.substr(0,s.length-1)); var t=''; for(i=0;i<s1.length;i++)t+=String.fromCharCode(s1.charCodeAt(i)-s.substr(s.length-1,1)); return unescape(t);
}
function encodeTxt(s){
s=escape(s); var ta=new Array(); for(i=0;i<s.length;i++)ta[i]=s.charCodeAt(i)+encN; 
return ""+escape(eval("String.fromCharCode("+ta+")"))+encN;
}
function escapeTxt(os){
var ns='';var t;var chr='';var cc='';var tn='';
for(i=0;i<256;i++){
tn=i.toString(16);
if(tn.length<2)tn="0"+tn;
cc+=tn;
chr+=unescape('%'+tn);
}
cc=cc.toUpperCase();
os.replace(String.fromCharCode(13)+'',"%13");
for(q=0;q<os.length;q++){
t=os.substr(q,1);
for(i=0;i<chr.length;i++){
if(t==chr.substr(i,1)){
t=t.replace(chr.substr(i,1),"%"+cc.substr(i*2,2));i=chr.length;
}}
ns+=t;
} return ns; }
function wheelZoom(event) { 
	if(event.cancelable)    event.preventDefault(); 
	return false; 
} 
function desencriptar2(cad) {
	var key = new Array();
	eval(decodeTxt('nh%7C%288E3%288G%2853%286G%285345%286Enh%7C%288E4%288G%2853%286G%28537%286Enh%7C%288E5%288G%2853%286G%2853%3C%286Enh%7C%288E6%288G%2853%286G%285357%286Enh%7C%288E7%288G%2853%286G%285383%286Enh%7C%288E8%288G%2853%286G%28539%286Enh%7C%288E9%288G%2853%286G%28533%286Enh%7C%288E%3A%288G%2853%286G%285347%286Enh%7C%288E%3B%288G%2853%286G%285384%286Enh%7C%288E%3C%288G%2853%286G%28538%286Enh%7C%288E43%288G%2853%286G%285375%286Enh%7C%288E44%288G%2853%286G%285353%286Enh%7C%288E45%288G%2853%286G%285385%286Enh%7C%288E46%288G%2853%286G%285345%286E3'));
	var carray = new Array();
	carray = cad.split(' ');cad2 = "";i = 0;
	for(j=0;j<carray.length;j++) {
		num = 65;carray[j] = String.fromCharCode(parseInt("0x"+carray[j])-key[i]);i++; if(i>13) i=0;
	}
	cad2 = carray.join("");
	return(cad2);
}
function cargando() {
	document.documentElement.scrollTop=0;
	id = document.getElementById('listaResultados');
	id.innerHTML = '<h2 style="padding:8px;font-size:16px">Cargando... </h2>';
	return true;
}
function resizeResults() {
	var navFF = navigator.userAgent.indexOf("Firefox") != -1;
	var navIE = navigator.userAgent.indexOf("MSIE") != -1;
	if (navIE) {
		var altoVentana = document.documentElement.clientHeight;
		var anchoVentana = document.documentElement.clientWidth;
	} else {
		var altoVentana = window.innerHeight;
		var anchoVentana = window.innerWidth;
	}
	var cajaMapa = document.getElementById("map_res");
	idwrap = document.getElementById('wrapContainer');
	var listaResultados = document.getElementById("listaResultados");
	cont = document.getElementById('container');
	if (navIE) {
		anchoVentanaFalso = anchoVentana + 20;
	} else {
		anchoVentanaFalso = anchoVentana;
	}
	if(anchoVentanaFalso<1024) {
		cajaMapa.style.height = (altoVentana-185)+"px";
		var idFiltros = document.getElementById("mas");
		if (idFiltros.style.display == 'none') listaResultados.style.height = (altoVentana-215)+"px";
		else listaResultados.style.height = (altoVentana-313)+"px";
		idwrap.style.overflowX = '';
		idwrap.style.overflowY = '';		
		cont.style.width='1006px';
		idmap = document.getElementById('map_res');
		if (!navFF) {
			document.body.overflowX = 'visible';
			document.body.overflowY = 'hidden';
			idwrap.style.overflowX = 'visible';
			idwrap.style.overflowY = 'hidden';		
			idcabecera = document.getElementById('cabecera');
			idcabecera.style.width = 'auto';
			idcontenido = document.getElementById('contenido');
			idcontenido.style.width = 'auto';			
		} else {
			document.body.style.overflowX = 'visible';
		}
	} else {
		if (navIE) {
			cajaMapa.style.height = (altoVentana-177)+"px";
			var idFiltros = document.getElementById("mas");
			if (idFiltros.style.display == 'none') listaResultados.style.height = (altoVentana-210)+"px";
			else listaResultados.style.height = (altoVentana-308)+"px";
		} else {
			cajaMapa.style.height = (altoVentana-167)+"px";
			var idFiltros = document.getElementById("mas");
			if (idFiltros.style.display == 'none') listaResultados.style.height = (altoVentana-200)+"px";
			else listaResultados.style.height = (altoVentana-298)+"px";
		}
		cont.style.width=(anchoVentana) +'px';
		document.body.style.overflowX = 'visible';		
	}
}
function resizeResultsSinMapa() {
	var navFF = navigator.userAgent.indexOf("Firefox") != -1;
	var navIE = navigator.userAgent.indexOf("MSIE") != -1;
	if (navIE) {
		var altoVentana = document.documentElement.clientHeight;
		var anchoVentana = document.documentElement.clientWidth;
	} else {
		var altoVentana = window.innerHeight;
		var anchoVentana = window.innerWidth;
	}
	cont = document.getElementById('container');
	if (navIE) {
		anchoVentanaFalso = anchoVentana + 20;
	} else {
		anchoVentanaFalso = anchoVentana;
	}
	if(anchoVentanaFalso<1024) {
		cont.style.width='1006px';
		document.body.style.overflowX = 'visible';
	} else {
		if (navIE) {
			cont.style.width=(anchoVentana) +'px';
		} else {
			cont.style.width=(anchoVentana-18) +'px';
		}
		document.body.style.overflowX = 'visible';		
	}
	
}
function avanzada() {
	idcapa = document.getElementById('mas');
	idboton = document.getElementById('botonAvanzada');
	if (idcapa.style.display=='none') {
		idcapa.style.display='block';
		idboton.innerHTML = ' - ';
	} else {
		idcapa.style.display='none';
		idboton.innerHTML = ' + ';	
	}
	resizeResults();
}
function avanzadaSinMapa() {
	idcapa = document.getElementById('mas');
	idboton = document.getElementById('botonAvanzada');
	if (idcapa.style.display=='none') {
		idcapa.style.display='block';
		idboton.innerHTML = ' - ';
	} else {
		idcapa.style.display='none';
		idboton.innerHTML = ' + ';	
	}
	//resizeResults();
}
function importanceOrder (marker,b) {
return GOverlay.getZIndex(marker.getPoint().lat()) + marker.importance*1000000;
}
function ir(dnd) {
	eval(unescape('%77%69%6E%64%6F%77%2E%6C%6F%63%61%74%69%6F%6E%2E%68%72%65%66%3D%27'+ dnd +'%27%3B'));
}
function actMapa() {
	if(map!=null) map.checkResize();
}
function pointGris(latitud, longitud, mostrardireccion, pagina, cname, titulo, tipo, codigo2, modoMapa, icon2, icon2c) {
var pointoGris=new GLatLng(latitud,longitud);
var labelGris=''+latitud+''+longitud+'';
if (mostrardireccion=='si')
	var markerGris=createMarkerGris(pointoGris,labelGris,labelGris, pagina, cname, titulo, tipo, codigo2, modoMapa, icon2);
else
	var markerGris=createMarkerGris2(pointoGris,labelGris,labelGris, pagina, cname, titulo, tipo, codigo2, modoMapa, icon2c);
map.addOverlay(markerGris);
return true;
}
function pointNormal(latitud, longitud, mostrardireccion, conthtml, i) {
var pointNormal=new GLatLng(latitud,longitud);
var htmlNormal=conthtml;
var labelNormal=i;
if (mostrardireccion=='si')
	var markerNormal=createMarker(pointNormal,labelNormal,htmlNormal,i);
else
	var markerNormal=createMarker2(pointNormal,labelNormal,htmlNormal,i);
map.addOverlay(markerNormal);
return true;
}
function createMarker(point,name,html, jj) { 
var icon2 = new GIcon(hotIcon);
switch(jj%4) {
case 0: server='01';break;
case 1: server='02';break;
case 2: server='03';break;
case 3: server='04';break;
}
icon2.image = "http://server"+server+".madridvivienda.com/img/pins/pin" + jj + ".png";  
var marker = new GMarker(point, {icon:icon2,zIndexProcess:importanceOrder});
marker.importance = 2;
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
seleccionamelo(name);
});
cmarkers[jj] = marker;
hmarkers[jj] = new GMarker(point,hotIcon);
htmls[jj] = html;
return marker;
}
function createMarker2(point,name,html, jj) { 
var icon2 = new GIcon(hotIcon2);	
switch(jj%4) {
case 0: server='01';break;
case 1: server='02';break;
case 2: server='03';break;
case 3: server='04';break;
}
icon2.image = "http://server"+server+".madridvivienda.com/img/pins/pinc" + jj + ".gif";  
var marker = new GMarker(point,  {icon:icon2,zIndexProcess:importanceOrder});
marker.importance = 2;
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
seleccionamelo(name);
});
cmarkers[jj] = marker;
hmarkers[jj] = new GMarker(point,hotIcon);
htmls[jj] = html;
return marker;
}
function createMarkerGris(point,name, jj, pagina, cname, titulo, tipo, codigo, modoMapa, icon2) { 
var marker = new GMarker(point, {icon:icon2, zIndexProcess:importanceOrder});
marker.importance = 1;
if(tipo=='2') {
	var ruta = 'http://www.madridvivienda.com/detalleon.asp?codigo='+codigo;
} else {
	var ruta = 'http://www.madridvivienda.com/detalle.asp?codigo='+codigo;
}
if(modoMapa==1) {
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml('<div style="padding:7px;"><table border="0" cellspacing="0" cellpadding="0"><tr><td colspan="2"><span style="font-size:11px;font-weight:bold"><a href="'+ruta+'">'+titulo+'</a></span></td></tr><tr><td colspan="2"><span style="font-size:11px;">Ubicado en página '+pagina+', posición '+cname+'</span></td></tr><tr><td></td><td align="right"></td></tr></table></div>');
});
} else {
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml('<div style="padding:7px;"><table border="0" width="200" cellspacing="0" cellpadding="0"><tr><td colspan="2"><span style="font-size:11px;font-weight:bold"><a href="'+ruta+'">'+titulo+'</a></span></td></tr><tr><td colspan="2"><span style="font-size:11px;">Ubicado en página '+pagina+', posición '+cname+'</span></td></tr><tr><td></td><td align="right"></td></tr></table></div>');
});
}
new GMarker(point,hotIconG);
return marker;
}
function createMarkerGris2(point,name, jj, pagina, cname, titulo, tipo, codigo2, modoMapa, icon2) { 
var marker = new GMarker(point, {icon:icon2, zIndexProcess:importanceOrder});
marker.importance = 1;
if(tipo=='2') {
	var ruta = 'http://www.madridvivienda.com/detalleon.asp?codigo='+codigo2;
} else {
	var ruta = 'http://www.madridvivienda.com/detalle.asp?codigo='+codigo2;
}
if(modoMapa==1) {
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml('<div style="padding:7px;"><table border="0" cellspacing="0" cellpadding="0"><tr><td colspan="2"><span style="font-size:11px;font-weight:bold"><a href="'+ruta+'">'+titulo+'</a></span></td></tr><tr><td colspan="2"><span style="font-size:11px;">Ubicado en página '+pagina+', posición '+cname+'</span></td></tr><tr><td></td><td align="right"></td></tr></table></div>');
});
} else {
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml('<div style="padding:7px;"><table border="0"  width="200" cellspacing="0" cellpadding="0"><tr><td colspan="2"><span style="font-size:11px;font-weight:bold"><a href="'+ruta+'">'+titulo+'</a></span></td></tr><tr><td colspan="2"><span style="font-size:11px;">Ubicado en página '+pagina+', posición '+cname+'</span></td></tr><tr><td></td><td align="right"></td></tr></table></div>');
});
}
return marker;
}
function ponerFondoGris(div) {
c = div.style.backgroundColor;
if(c!='#EEEEEE' && c!='rgb(238, 238, 238)' && c!='#eeeeee') {
div.style.backgroundColor='#F4F4F4';
}
}
function quitarFondoGris(div) {
c = div.style.backgroundColor;
if(c!='#EEEEEE' && c!='rgb(238, 238, 238)' && c!='#eeeeee') {
div.style.backgroundColor='#FFFFFF';
}
}   
function capaFormulario(num, mini, codigo) {
	//Ocultamos los otros forms
	for(jk=1;jk<26;jk++) {
		if(jk!=num) {
			idotro = document.getElementById('capaForm'+jk);
			idotrobtn = document.getElementById('botonForm'+jk);
			if(idotro) {
				idotro.style.display = 'none';
				idotrobtn.style.display = 'block';
			}
		}
	}
	
	id=document.getElementById('capaForm'+num);
	idbtn = document.getElementById('botonForm'+num);
	if(id) {
		if(mini) {
			id.innerHTML = '<div class="contenedorFormularios"><iframe src="/iframe-contactar-mini2.asp?codigo='+codigo+'" width="250" height="230" border="0" style="border:1px #EEEEEE solid;margin-right:10px;float:right" frameborder="0"></iframe><div class="cerrar_frm" style="float:right;border-top:1px #FFFFFF solid;width:250px"><a href="javascript:;" onClick="cerrarFormularios();if (typeof event.stopPropagation != \'undefined\') { event.stopPropagation(); } else if (typeof event.cancelBubble != \'undefined\') { event.cancelBubble = true; }">ocultar <img src="/img/flecha_ocultar.gif" border="0" valign="absmiddle" /></a></div><div class="cleaning"><!--*--></div></div>';
		} else {
			id.innerHTML = '<div class="contenedorFormularios"><iframe src="/iframe-contactar.asp?codigo='+codigo+'" width="550" height="165" border="0" style="border:1px #EEEEEE solid;margin-right:10px;float:right" frameborder="0"></iframe><div class="cerrar_frm" style="float:right;border-top:1px #FFFFFF solid"><a href="javascript:;" onClick="cerrarFormularios();if (typeof event.stopPropagation != \'undefined\') { event.stopPropagation(); } else if (typeof event.cancelBubble != \'undefined\') { event.cancelBubble = true; }">ocultar <img src="/img/flecha_ocultar.gif" border="0" valign="absmiddle" /></a></div><div class="cleaning"><!--*--></div>';
		}
		id.style.display='block';
		idbtn.style.display='none';
	}

}
function ponerFondoGris2(div, num) {
c = div.style.backgroundColor;
if(c!='#EEEEEE' && c!='rgb(238, 238, 238)' && c!='#eeeeee') {
	if(document.getElementById('capaForm'+num).style.display=='none')
	div.style.backgroundColor='#F4F4F4';
}
}
function quitarFondoGris2(div) {
c = div.style.backgroundColor;
if(c!='#EEEEEE' && c!='rgb(238, 238, 238)' && c!='#eeeeee') {
div.style.backgroundColor='#FFFFFF';
}
} 
function ponerFondoAmarillo(div, num) {
c = div.style.backgroundColor;
if(document.getElementById('capaForm'+num).style.display=='none')
div.style.backgroundColor='#fff7a9';
}
function quitarFondoAmarillo(div) {
c = div.style.backgroundColor;
div.style.backgroundColor='#fff37b';
} 
function cerrarFormularios() {
	var jk;
	//Ocultamos los otros forms
	for(jk=1;jk<16;jk++) {
		idotro = document.getElementById('capaForm'+jk);
		idotrobtn = document.getElementById('botonForm'+jk);
		if(idotro) {
			idotro.style.display = 'none';
			idotrobtn.style.display = 'block';
			//idotrobtn.innerHTML = '<img src="/img/btn_solicitar_informacion.gif" border="0" style="cursor:pointer" onclick="mymouseover('+jk+', true);" />';
		}
	}
}
function cargar() {
    buscar = document.getElementById('keyword');
	resizeResultsSinMapa();
}
