	var idInmueble = "";
	var correoElectronico = "";
	var cargado = false;

	//Funcion que coge todas las imagenes y les hace un clip centrado
	$(window).load(function () {
		$('.dAImg .imgL').each(function () {
			var divImagen = document.getElementById(this.parentNode.id);
			var posArriba = (divImagen.offsetHeight-113)/2;
			var posAbajo = posArriba + 113;
			
			divImagen.style.clip='rect('+posArriba+'px, 150px, '+posAbajo+'px, 0)';
			divImagen.style.top=(posArriba*-1)+'px';
			divImagen.style.left='0px';
			
		});
	});
	
	$(document).ready
	(
		function()
		{
			cargado = true;
			
			$("tr.filaInmueble").mouseover
			(
				function()
				{
					this.className="filaInmuebleAct";
				}
			);
			$("tr.filaInmueble").mouseout
			(
				function()
				{
					this.className="filaInmueble";
				}
			);
			
			$("td.favorito").click
			(
				function()
				{
					try {
						document.getElementById("guardarPPG").style.visibility = "hidden";
					} catch(e){;}
					var aux = $(this).attr("id");
					document.getElementById("formGuardarInmuebleCapa").idInmueble.value = aux.substring(11);
					try {
						document.getElementById("formGuardarInmuebleCapaPPG").idInmueble.value = aux.substring(11);
					} catch(e){;}
					document.getElementById("idFormGuardarInmueble").idInmueble.value = aux.substring(11);
					if(document.getElementById("idFormGuardarInmueble").idUsuario.value == "0" || document.getElementById("idFormGuardarInmueble").idUsuario.value == "")
					{
						posicionaObjeto("guardar", posicionRelativaXObjetoDeOtro(document.getElementById($(this).attr("id")), 'container')-296, posicionRelativaYObjetoDeOtro(document.getElementById($(this).attr("id")), 'container')+0);
						document.getElementById("guardar").style.visibility = "visible";
					}
					else
					{
						guardaFavorito(document.getElementById('formGuardarInmuebleCapa'));
						muestra(document.getElementById("idFormGuardarInmueble").idInmueble.value);
					}
				}
			);
			
			$("td.contacto").click
			(
				function()
				{
					$("#imagenEnviarAmigo").hide();
					var aux = $(this).attr("id");
					$("#imagenEnviarAmigo").attr("src", $("#f" + aux.substring(11)).attr("src"));
					$("#direccionEnviarAmigo").html($("#d" + aux.substring(11)).html());
					var precio = $("#precio" + aux.substring(11)).html();
					(precio != null && precio != '-')? $("#precioEnviarAmigo").html(precio.replace("&euro;", "") + " &euro;") : $("#precioEnviarAmigo").html("");
					posicionaObjeto("enviarAmigo", posicionRelativaXObjetoDeOtro(document.getElementById($(this).attr("id")), 'container')-295, posicionRelativaYObjetoDeOtro(document.getElementById($(this).attr("id")), 'container')+1.5);
					document.getElementById("enviarAmigo").style.visibility = "visible";
					if($("#" + aux + " #idPromocion").size() > 0){
						document.enviarAmigoForm.idPromocion.value = aux.substring(11);
					}else{
						document.enviarAmigoForm.idInmueble.value = aux.substring(11);
					}
					if($("#" + aux + " #idAgencia").size() > 0){
						document.enviarAmigoForm.idAgencia.value = $("#" + aux + " #idAgencia").val();
					}
				}
			);
		}
	);

	function abreFavorito(obj)
	{
		document.getElementById("guardar").style.visibility = "hidden";
		var aux = $(obj).attr("id");
		document.getElementById("formGuardarInmuebleCapa").idInmueble.value = aux.substring(11);
		try {
			document.getElementById("formGuardarInmuebleCapaPPG").idInmueble.value = aux.substring(11);
		} catch(e){;}
		document.getElementById("idFormGuardarInmueble").idInmueble.value = aux.substring(11);
		if(document.getElementById("idFormGuardarInmueble").idUsuario.value == "0" || document.getElementById("idFormGuardarInmueble").idUsuario.value == "")
		{
			try {
				posicionaObjeto("guardarPPG", posicionRelativaXObjetoDeOtro(document.getElementById($(obj).attr("id")), 'container')-318, posicionRelativaYObjetoDeOtro(document.getElementById($(obj).attr("id")), 'container')-112);			
				document.getElementById("guardarPPG").style.visibility = "visible";
			} catch(e){;}
		}
		else
		{
			try {
				guardaFavorito(document.getElementById('formGuardarInmuebleCapaPPG'));
			} catch(e){;}
			muestra2(document.getElementById("idFormGuardarInmueble").idInmueble.value);
		}
	}
	
	function abreContacto(obj)
	{
		$("#imagenEnviarAmigo").hide();
		var aux = $(obj).attr("id");
		$("#imagenEnviarAmigo").attr("src", $("#imagen" + aux.substring(11)).attr("src"));
		$("#direccionEnviarAmigo").html($("#direccion" + aux.substring(11)).html());
		var precio = $("#precio" + aux.substring(11)).html();
		(precio != null && precio != '-')? $("#precioEnviarAmigo").html(precio) : $("#precioEnviarAmigo").html("");
		posicionaObjeto("enviarAmigo", posicionRelativaXObjetoDeOtro(document.getElementById($(obj).attr("id")), 'container')-244, posicionRelativaYObjetoDeOtro(document.getElementById($(obj).attr("id")), 'container')-15);
		document.getElementById("enviarAmigo").style.visibility = "visible";
		if($("#" + aux + " #idPromocion").size() > 0){
			document.enviarAmigoForm.idPromocion.value = aux.substring(11);
		}else{
			document.enviarAmigoForm.idInmueble.value = aux.substring(11);
		}
		if($("#" + aux + " #idAgencia").size() > 0){
			document.enviarAmigoForm.idAgencia.value = $("#" + aux + " #idAgencia").val();
		}		
	}

	function guardarFavoritoPPG()
	{
		document.getElementById("formGuardarInmuebleCapa").emailUsuario.value = document.getElementById("formGuardarInmuebleCapaPPG").emailUsuario.value;
		guardaFavorito(document.getElementById('formGuardarInmuebleCapaPPG'));
		muestra2(document.getElementById("idFormGuardarInmueble").idInmueble.value);
	}

	function guardarFavorito()
	{
		try {
			document.getElementById("formGuardarInmuebleCapaPPG").emailUsuario.value = document.getElementById("formGuardarInmuebleCapa").emailUsuario.value;
		} catch(e){;}
		guardaFavorito(document.getElementById('formGuardarInmuebleCapa'));
		muestra(document.getElementById("idFormGuardarInmueble").idInmueble.value);
	}

	function muestra(id)
	{
		posicionaObjeto
		(
				"favGuardado" + id
			, (posicionRelativaXObjetoDeOtro(document.getElementById("favoritoSel" + id), "container") - 2)
			, (posicionRelativaYObjetoDeOtro(document.getElementById("favoritoSel" + id), "container") + 9)
		);

		document.getElementById("favGuardado" + id).style.visibility = 'visible';
	}

	function muestra2(id)
	{
		posicionaObjeto
		(
				"favGuardado" + id
			, (posicionRelativaXObjetoDeOtro(document.getElementById("favoritoSel" + id), "ppgDIV") - 4)
			, (posicionRelativaYObjetoDeOtro(document.getElementById("favoritoSel" + id), "ppgDIV") - 4)
		);

		document.getElementById("favGuardado" + id).style.visibility = 'visible';
		document.getElementById("guardarPPG").style.visibility = "hidden";		
	}
	
// Inicio Para mostrar la descripcion al pasar por encima
  var mousex = 0;
  var mousey = 0;
  
  function verDesc(capa, capaA, obj, event)
  {
  	if(cargado)
  	{  	
			getMouseXY(event);
			$("#" + capa).css({"top" : (mousey + 22 - document.getElementById("container").offsetTop) + "px"});
			if(mousex >= 630){$("#" + capa).css({"left" : (mousex- 495 + 15) + "px"});}
			else{$("#" + capa).css({"left" : (mousex-181) + "px"});}
	  	$("#" + capa).show();
		}
  }
	
  function ocultarDesc(capa)
  {
   	$("#" + capa).hide();
  }
  
  function getMouseXY(e){ // works on IE6,FF,Moz,Opera7  
  	if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)
  	if (e){ 
    	if (e.pageX || e.pageY){ // this doesn't work on IE6!! (works on FF,Moz,Opera7)
	      mousex = e.pageX;
	      mousey = e.pageY;
	      algor = '[e.pageX]';
	      if (e.clientX || e.clientY) algor += ' [e.clientX] '
    	}else if (e.clientX || e.clientY){ // works on IE6,FF,Moz,Opera7
    	  mousex = e.clientX + document.body.scrollLeft;
    	  mousey = e.clientY;
    	  if(document.body.scrollTop > 0){
	      	mousey = mousey + document.body.scrollTop;
    	  }else if(document.documentElement.scrollTop > 0){
    	  	mousey = mousey + document.documentElement.scrollTop;
    	  }
    	  algor = '[e.clientX]';
	      if (e.pageX || e.pageY) algor += ' [e.pageX] '
    	}  
    	//window.status = "x: " + mousex + " y: " + mousey + " clientY: " + e.clientY + " ScrollTop: " +  document.body.scrollTop + " opc: " + document.documentElement.scrollTop;
  	}
  }

  nombreProv = "";
  
  function posicionamiento()
  {
		document.getElementById("iframePosicionamiento").src="/www/es/include/buscador/comun/posicionamiento.jsp?accion=listPisos";
  }
// Final Para mostrar la descripcion al pasar por encima

	function cambiaZonas(d)
	{
		for(i = d+1; i <= 3; i++)
		{
			document.getElementById("DD_" + (i)).value = 0;
		}
		document.getElementById("zonasF").submit();
	}

	function reordena(valor)
	{
		form = document.criteriosBusqueda;
		form.criterioOrden.value = valor;
		form.nPag.value = "1";
		form.buscar.value = "3";
		form.submit();
 	}

 	function cambiaZona()
 	{
 		var frm = document.getElementById("zonasF");
 		var dd = null;
 		
 		for(d = 1; d <= 3; d++)
 		{
 			dd = document.getElementById("DD_" + d);
 			eval("frm." + dd.name.substring(3) + ".value=dd.value");
 		}
 		frm.action = frm.direccion.value;
 		frm.target = "_self";
 		frm.submit();
 	}
 	
 	function cambiaCriterios()
 	{
  	var frm = document.getElementById("caracteristicasF");
  	var frmCriterios = document.getElementById("criteriosBusqueda");
  	if(frm.precioS.value != "-1")
  	{
  		frmCriterios.precio.value = "1";
  	}
  	else
  	{
  		frmCriterios.precio.value = "0";
  	}
  	frmCriterios.precioS.value = frm.precioS.value;
  	if(frm.superficieS.value != "-1")
  	{
  		frmCriterios.superficie.value = "1";
  	}
  	else
  	{
  		frmCriterios.superficie.value = "0";
  	}
  	frmCriterios.superficieS.value = frm.superficieS.value;
  	frmCriterios.dormitorios.value = frm.dormitorios.value;
  	frmCriterios.tipos.value = frm.tipos.value;
  	frmCriterios.submit();
 	}

	var lzn = -1;
 		
	function muestraZonas(idListado)
	{
		if(lzn >= 0)
		{
			document.getElementById("listadoZonasN" + lzn).style.visibility = "hidden";
		}
		lzn = idListado;
		document.getElementById("listadoZonasN" + idListado).style.visibility = "visible";
	}
	
	function cerrarZonas()
	{
		if(lzn >= 0)
		{
			document.getElementById("listadoZonasN" + lzn).style.visibility = "hidden";
		}
	}
	
	function cerrarFavoritoPPG()
	{
		document.getElementById("guardarPPG").style.visibility = "hidden";
	}
	
	function cerrarFavorito()
	{
		document.getElementById("guardar").style.visibility = "hidden";
	}
 	
