// JavaScript Document
var mostrar_mas_zoom = 11;
////////////////////////////

////////////////////////


function cargar_mapa(dat_1, dat_2, dat_3) {
var longitud=dat_1;
var latitud=dat_2;
var zoom=dat_3;

      if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(latitud, longitud), zoom, G_HYBRID_MAP);
		//map.enableScrollWheelZoom();
		
		var customUI = map.getDefaultUI();
        map.setUI(customUI);
        map.addControl(new GOverviewMapControl());
		
		
		var center = map.getCenter();
		
  		document.getElementById("lat_c").innerHTML = center.lat().toString();
		document.getElementById("lng_c").innerHTML = center.lng().toString();
		document.getElementById("zo_c").innerHTML = zoom.toString();
		



////////////////////

////////
////////

function makeRequest_inmobiliarias_zoom(minlongitud, maxlongitud, minlatitud, maxlatitud) {
	var http_request = false;
	var minlongitud = minlongitud;
	var maxlongitud = maxlongitud;
	var minlatitud = minlatitud;
	var maxlatitud = maxlatitud;
	
	var url = "http://www.infobiliaria.es/javascript/otras_inmos_zoom_grande.php?js=inmueble&inmueble_url=11015&minlongitud="+minlongitud+"&maxlongitud="+maxlongitud+"&minlatitud="+minlatitud+"&maxlatitud="+maxlatitud;

	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		//alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = function() { 
		// do the thing
		alertContents_inmo_zoom(http_request); 
	};
	
	http_request.open('GET', url, true);
	http_request.send(null);

}

function alertContents_inmo_zoom(http_request) {

	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
				
			var icono_s = new GIcon();
			icono_s.image = "http://www.infobiliaria.es/images/icono_inmo.png";
			icono_s.iconSize = new GSize(15, 27);
			icono_s.iconAnchor = new GPoint(7, 27);	
			
			
			var xmldoc = http_request.responseXML;			
			var xml_resultados = xmldoc.getElementsByTagName('resultados').item(0);
			resultados= xml_resultados.firstChild.data;			
			
			
			
			function createMarker(icono, number, long, lat) {
			  var marker = new GMarker(new GLatLng(lat, long),{icon: icono, title:"informaci�n de esta inmobiliaria"});
			  GEvent.addListener(marker, "click", function() {
				map.openInfoWindowHtml(new GLatLng(lat, long),number, {maxWidth:310});	
			  });
			  return marker;
			}
			
			for(i=0; i<(resultados-1); i++)
				{
				
				var xml_info_inmo_window = xmldoc.getElementsByTagName('info_inmo_window').item(i);
				var info_inmo_window= xml_info_inmo_window.firstChild.data;
		
				var xml_longitud = xmldoc.getElementsByTagName('longitud').item(i);
				var longitud= xml_longitud.firstChild.data;
				
				var xml_latitud = xmldoc.getElementsByTagName('latitud').item(i);
				var latitud= xml_latitud.firstChild.data;							
				
				map.addOverlay(createMarker(icono_s, info_inmo_window, longitud, latitud));
	
				}
			
		} else {
			alert('Ha habido un problema con la solicitud. Int�ntalo m�s tarde');
		}
	}

}

////////
////////

function makeRequest_inmuebles_zoom(minlongitud, maxlongitud, minlatitud, maxlatitud) {
	var http_request = false;
	var minlongitud = minlongitud;
	var maxlongitud = maxlongitud;
	var minlatitud = minlatitud;
	var maxlatitud = maxlatitud;
	
	var url = "http://www.infobiliaria.es/javascript/otros_inmus_zoom_grande.php?js=inmueble&inmueble_url=11015&minlongitud="+minlongitud+"&maxlongitud="+maxlongitud+"&minlatitud="+minlatitud+"&maxlatitud="+maxlatitud;

	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		//alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = function() { 
		// do the thing
		alertContents_inmu_zoom(http_request); 
	};
	
	http_request.open('GET', url, true);
	http_request.send(null);

}

function alertContents_inmu_zoom(http_request) {

	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
				
			var icono_s = new GIcon();
			icono_s.image = "http://www.infobiliaria.es/images/icono_inmu_select.png";
			icono_s.iconSize = new GSize(15, 27);
			icono_s.iconAnchor = new GPoint(7, 27);	
			
			
			var xmldoc = http_request.responseXML;			
			var xml_resultados = xmldoc.getElementsByTagName('resultados').item(0);
			resultados= xml_resultados.firstChild.data;			
			
			
			function createMarker(icono, number, long, lat) {
			  var marker = new GMarker(new GLatLng(lat, long),{icon: icono, title:"informaci�n de este inmueble"});
			  GEvent.addListener(marker, "click", function() {
				map.openInfoWindowTabsHtml(new GLatLng(lat, long),number, {maxWidth:310});	
			  });
			  return marker;
			}
			
			for(i=0; i<(resultados-1); i++)
				{
				var xml_info_inmo_window = xmldoc.getElementsByTagName('info_inmo_window').item(i);
				var info_inmo_window= xml_info_inmo_window.firstChild.data;
				
				var xml_info_inmu_window = xmldoc.getElementsByTagName('info_inmu_window').item(i);
				var info_inmu_window= xml_info_inmu_window.firstChild.data;
				
				var xml_info_foto_inmu = xmldoc.getElementsByTagName('info_foto_inmu').item(i);
				var info_foto_inmu= xml_info_foto_inmu.firstChild.data;
		
				var xml_longitud = xmldoc.getElementsByTagName('longitud').item(i);
				var longitud= xml_longitud.firstChild.data;
				
				var xml_latitud = xmldoc.getElementsByTagName('latitud').item(i);
				var latitud= xml_latitud.firstChild.data;							
				
				
				var infoTabs = [
				  new GInfoWindowTab("Inmueble", info_inmu_window),
				  new GInfoWindowTab("Inmobiliaria", info_inmo_window),
				  new GInfoWindowTab("Fotos", info_foto_inmu)
				];
				
				map.addOverlay(createMarker(icono_s, infoTabs, longitud, latitud));
	
				}
			
		} else {
			alert('Ha habido un problema con la solicitud. Int�ntalo m�s tarde');
		}
	}

}

////////			
	var icono = new GIcon();
	icono.image = "http://www.infobiliaria.es/images/icono_grande_inmu.png";
	icono.iconSize = new GSize(30, 50);
	icono.iconAnchor = new GPoint(15, 50);
				var infoTabs = [
			  new GInfoWindowTab("Inmueble", "<div style=\"font-family: Verdana; width: 300px; margin: auto; font-size: 12px;\">Ref. Web.: <b>11015</b><br />Ref. Inmo.: LLOBET 10<br /><b>PLAZAS DE PARKING MOTO GUINARD&Oacute; OBRA NUEVA,INVER</b>...<br />VENDO 4 PL.PK.MOTO, OBRA NUEVA, SUELTAS O LOTE COMPLETO, IDEAL INVERSI&Oacu...<br />En venta<br />Superficie: 2 m2 <br />Precio: 6100 &#8364; <br /><a href=\"http://www.infobiliaria.es/inmueble_11015_plazas_de_parking_moto_guinard_obra_nuevainversin/#inmueble_ref\" title=\"ver ficha completa\">M&aacute;s informaci&oacute;n</a> <a href=\"http://www.infobiliaria.es/pdf_inmueble_11015_plazas_de_parking_moto_guinard_obra_nuevainversin/\" target=\"_blank\" title=\"descargar ficha en pdf\"><img src=\"http://www.infobiliaria.es/images/pdf_map.png\" width=\"12\" height=\"14\" border=\"0\"></a> <a href=\"http://www.infobiliaria.es/kml_inmueble_11015_plazas_de_parking_moto_guinard_obra_nuevainversin/\" title=\"visualizar en Google Earth\"><img src=\"http://www.infobiliaria.es/images/kml_map.png\" width=\"12\" height=\"12\" border=\"0\"></a> </div>"),
			  new GInfoWindowTab("Inmobiliaria", "<div style=\"font-family: Verdana; width: 300px; margin: auto; font-size: 12px;\"><b><a href=\"http://www.infobiliaria.es/inmobiliaria_10924_promotora_llobet/\">PROMOTORA LLOBET</a></b><br />Tlf.: 637&nbsp;511&nbsp;907, 637&nbsp;511&nbsp;909<br />Plaza Catalana 8<br />Barcelona<br />Barcelona<br /></div>"),
			  new GInfoWindowTab("Fotos", "<a href=\"http://www.infobiliaria.es/foto_inmueble/1276461341sin_titulo10.jpg\" target=\"_blank\"><img src=\"http://www.infobiliaria.es/foto_inmueble/thumbnail/1276461341sin_titulo10.jpg\" height=\"65\" width=\"59\" border=\"1\" style=\"float: left; margin: 4px;\" /></a> <a href=\"http://www.infobiliaria.es/foto_inmueble/1276501121sin_titulo7.jpg\" target=\"_blank\"><img src=\"http://www.infobiliaria.es/foto_inmueble/thumbnail/1276501121sin_titulo7.jpg\" height=\"48\" width=\"65\" border=\"1\" style=\"float: left; margin: 4px;\" /></a> <a href=\"http://www.infobiliaria.es/foto_inmueble/1276464073sin_titulo4.jpg\" target=\"_blank\"><img src=\"http://www.infobiliaria.es/foto_inmueble/thumbnail/1276464073sin_titulo4.jpg\" height=\"48\" width=\"65\" border=\"1\" style=\"float: left; margin: 4px;\" /></a> <a href=\"http://www.infobiliaria.es/foto_inmueble/1276464743sin_titulo2.jpg\" target=\"_blank\"><img src=\"http://www.infobiliaria.es/foto_inmueble/thumbnail/1276464743sin_titulo2.jpg\" height=\"65\" width=\"48\" border=\"1\" style=\"float: left; margin: 4px;\" /></a> <a href=\"http://www.infobiliaria.es/foto_inmueble/1276476408sin_titulo1.jpg\" target=\"_blank\"><img src=\"http://www.infobiliaria.es/foto_inmueble/thumbnail/1276476408sin_titulo1.jpg\" height=\"65\" width=\"40\" border=\"1\" style=\"float: left; margin: 4px;\" /></a> ")
			];
			
			
			var marker = new GMarker(new GLatLng(41.4220815, 2.1720303), {icon: icono, title:"informaci�n de este inmueble"});
			map.addOverlay(marker);
			GEvent.addListener(marker, "click", function() {
				
				map.openInfoWindowTabsHtml(new GLatLng(41.4220815, 2.1720303), infoTabs, {maxWidth:310});
	  });
	  		
////////////////////
////////////////////
		if(map.getZoom()>mostrar_mas_zoom)
			{
			var bounds = map.getBounds();
			var southWest = bounds.getSouthWest();
			var northEast = bounds.getNorthEast();	
			makeRequest_inmuebles_zoom(southWest.lng(), northEast.lng(), southWest.lat(), northEast.lat());
			}
		GEvent.addListener(map, "moveend", function() {
		if(map.getZoom()>mostrar_mas_zoom)
			{
			var bounds = map.getBounds();
			var southWest = bounds.getSouthWest();
			var northEast = bounds.getNorthEast();	
			makeRequest_inmuebles_zoom(southWest.lng(), northEast.lng(), southWest.lat(), northEast.lat());
			}
});

////////////////////
////////////////////		
		
			
		
		GEvent.addListener(map, "moveend", function() {
 		var center = map.getCenter();
  		document.getElementById("lat_c").innerHTML = center.lat().toString();
		document.getElementById("lng_c").innerHTML = center.lng().toString();
		document.getElementById("zo_c").innerHTML = map.getZoom().toString();
});
				
      }
}



///////////////


function select_provincia() {
	if (!document.getElementById) return false;
	var select_provincia = document.getElementById("select_provincia");
	select_provincia.title="personalizar con mi provincia";
	select_provincia.onchange = function() {
		location.href= "http://www.infobiliaria.es/?"+"per_prov="+document.forms.form_provincia.select_provincia.value;
		return false;
    	}
	return false;
}





////////////////////
function makeRequest(id_respuesta,id_provincia) {
	var http_request = false;
	var id_respuesta = id_respuesta;
	
	var url = "http://www.infobiliaria.es/javascript/mostrar_municipio.php?id_provincia="+id_provincia;

	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		//alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = function() { 
		// do the thing
		alertContents(http_request,id_respuesta); 
	};
	
	http_request.open('GET', url, true);
	http_request.send(null);

}

function alertContents(http_request,id_respuesta) {

	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			//alert(http_request.responseText);
			
			var xmldoc = http_request.responseXML;
			
			var xml_municipio = xmldoc.getElementsByTagName('select_municipio').item(0);
			if(xml_municipio.firstChild.data!="") 
				{
				document.getElementById(id_respuesta).innerHTML='<select name="id_municipio" class="campo"><option value="">selecciona </option>'+xml_municipio.firstChild.data+'</select>';
				document.form1.id_municipio.disabled=false;
				}
				else
				{
				document.form1.id_municipio.disabled=true;
				}
			/////////////////////google maps
			/*
			var xml_latitud = xmldoc.getElementsByTagName('latitud').item(0);
			latitud= xml_latitud.firstChild.data;
			var xml_longitud = xmldoc.getElementsByTagName('longitud').item(0);
			longitud= xml_longitud.firstChild.data;
			var xml_zoom = xmldoc.getElementsByTagName('zoom').item(0);
			zoom= parseInt(xml_zoom.firstChild.data);
			
			*/
			////////////////////////////////ggogle maps			

			//aqui codigo para mostrar provincia en mapa
			return false;
		} else {
			alert('Ha habido un problema con la solicitud. Int�ntalo m�s tarde');
		}
	}

}

//////


function mostrar_municipio() {
	if (!document.getElementById("id_provincia")) return false;
	document.form1.id_municipio.disabled=true;	var id_provincia = document.getElementById("id_provincia");
	id_provincia.title="personalizar con mi provincia";
	id_provincia.onchange = function() {
	id_provincia=document.form1.id_provincia.value;
	var id_respuesta="id_municipio_ajax";
	document.getElementById(id_respuesta).innerHTML='<select name="id_municipio" class="campo"><option value="">selecciona </option></select>';
	makeRequest(id_respuesta,id_provincia);
	if(id_provincia=="" || id_provincia==0) document.form1.id_municipio.disabled=true;
	}
}

///////////////////


function externalLinks(){
 if (!document.getElementsByTagName) return;
   var anchors = document.getElementsByTagName("a");
   for (var i=0; i<anchors.length; i++){
    var anchor = anchors[i];
    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external"){
      anchor.target = "_blank";
     }
   }
}

function escondeshow() {
 if (!document.getElementsByTagName) return;
   var anchors = document.getElementsByTagName("div");
   for (var i=0; i<anchors.length; i++){
    var anchor = anchors[i];
    if (anchor.className == "texto_informacion"){
      anchor.style.display = "none";
	  anchor.style.visibility = "hidden";	  
     }
   }
}

function email_value() {
 if (!document.getElementById("email")) return false;
   var email=document.getElementById("email");
   email.onfocus= function() {
   if(email.value=="email") 
   	{email.value="";}
   }
   email.onblur= function() {
   if(email.value=="") 
   	{email.value="email";}
   }
   
 if (!document.getElementById("email_busqueda")) return false;
   var email_busqueda=document.getElementById("email_busqueda");
   email_busqueda.onfocus= function() {
   if(email_busqueda.value=="email") 
   	{email_busqueda.value="";}
   }
   email_busqueda.onblur= function() {
   if(email_busqueda.value=="") 
   	{email_busqueda.value="email";}
   }
}

///////////////////////		
var t=100;
function esconder(nom, bcolor){
	  var nombre = nom.id;
	  var d2 = nombre+"_textop";
	  setTimeout("esconde('"+d2+"')",t);
	  nom.style.background='#'+bcolor;
}

  function fun(e,nom) {
	  var nombre = nom.id;
	  var ddd = document.getElementById(nombre+"_textop");
	  nom.style.background='#F0F0F0';
	  
	  if(e.pageX || e.pageY)
		{
		x= e.pageX;
		y= e.pageY;
		}
	  else if(e.clientX || e.clientY)
		{
		x= e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		y= e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop :document.body.scrollTop);
		}

	  ddd.style.left = (x-380) + "px";
	  ddd.style.top = (y-125) + "px";
	  ddd.style.visibility = "visible";
	  ddd.style.display= "block";
	  ddd.style.width = "360px";
	  ddd.style.height = "92px";
	  ddd.style.position = "absolute";
	  }

function esconde(d2)
	{
	  var ddd = document.getElementById(d2);
	  ddd.style.visibility = "hidden";
	  ddd.style.display= "none";
	}

//////////////
/*
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5 && version < 7.0) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}
*/
function showPic (whichpic) {
  if (!document.getElementById) return true;
  document.getElementById('placeholder').src = whichpic.href;
  return false;
}

function contraermapa() {
	if (!document.getElementById("contraer_mapa")) return false;
	var desplegar = document.getElementById("contraer_mapa");
	desplegar.style.cursor="pointer";
	desplegar.title="contraer mapa";
	var map = document.getElementById("map");
	desplegar.onclick = function() {
		if(map.style.height=="0px")
			{
			map.style.height="80%";
			map.style.visibility="visible";
			desplegar.title="contraer mapa";
			desplegar.innerHTML='<img src="http://www.infobiliaria.es/images/desplegado_mapa.png" alt="desplagar/contraer mapa" width="12" height="6" />';
			}
			else
			{
			map.style.height="0px";
			map.style.visibility="hidden";
			desplegar.title="desplegar mapa";
			desplegar.innerHTML='<img src="http://www.infobiliaria.es/images/contraido_mapa.png" alt="desplagar/contraer mapa" width="12" height="6" />';
			}
		return false;
    	}
	return false;
}


///////////////////////
function mail_pie()
{
		if (!document.getElementById) return false;
	var correo_consulta_pie="<a href=\"mailto:webmaster@infobiliaria.es\">webmaster@infobiliaria.es</a> ";
	// info@clamav.net
	// webmaster@clamav.net
	// info@symantec.com
	// webmaster@symantec.com
		document.getElementById('webmaster').innerHTML=correo_consulta_pie;
	return false;
}

////////////////////
function aviso_legal() {
	if (!document.getElementById("aviso_legal")) return false;
	var link_aviso_legal = document.getElementById("aviso_legal");
	link_aviso_legal.onclick = function() {
	window.open('http://www.infobiliaria.es/aviso_legal.htm','aviso_legal','scrollbars=yes,resizable=yes,width=470,height=520');
	}
}
////////////////////

function select_link() {
	if (!document.getElementById("link_inmueble")) return false;
	var link_inmueble = document.getElementById("link_inmueble");
	link_inmueble.onclick = function() {
	link_inmueble.focus();
	link_inmueble.select();
	}
}

window.onload = function() {
 
  cargar_mapa(2.1720303,41.4220815,16);
  externalLinks();
  email_value();
  //correctPNG();
  select_provincia();
  mostrar_municipio();
  contraermapa();
  select_link();
  mail_pie();
  escondeshow();
  aviso_legal();
};

window.onunload = function() {
  GUnload();
};