var map;

var geocoder;

var address;

var zoom = 9;

var puntoInicio = null;

var pais;

var codPostal;

var numeroForm = false;

var pais = "España";

var provincia = "Pontevedra";

var localidad = null;

var codPostal = null;

var calle = null;

var numero = null;

var piso = null;

var marcador = null;

var tipoOferta = "empresa";

var marcas = null;

var markers = null;

var marcasW = null;

var ofertas = null;

var idOfertaSelec = 0;

var idMarcaSelec = -1;

var sensorMovimiento = null;

var selectTab = null;

var ofSel = -1;

var marcaSel = -1;

var numeroOfertasListado = 5;

/* NUEVO DEL BUSCADOR POR C.P. */

var postcode=null;

var point2=null;


function calls(val)

{

	if(document.getElementById("dcha") || document.getElementById("der")){eval(val);}

}

	function usePointFromPostcode(postcode, callbackFunction) {

	var localSearch = new GlocalSearch();

		localSearch.setSearchCompleteCallback(null,

		function() 

		{

		

			if (localSearch.results[0])

			{

				var resultLat2 = localSearch.results[0].lat;

				var resultLng2 = localSearch.results[0].lng;

				point2 = new GLatLng(resultLat2,resultLng2);

				callbackFunction(point2);

			}

			else

			{

				alert("C.P: "+postcode+" no encontrado");

				document.getElementById("inputcodpostalInmueble").value='';	

				document.getElementById("inputcodpostalEmpresa").value='';		

				document.getElementById("inputcodpostal3dExt").value='';		

				document.getElementById("inputcodigoInteriores").value='';	

				puntoInicio = new GLatLng(42.399122,-8.502045);

				map = new GMap2(document.getElementById("mapa"));

				map.setCenter(puntoInicio, zoom);

				map.addControl(new GSmallMapControl());

				geocoder = new GClientGeocoder();

				var mapControl = new GMapTypeControl();

				map.addControl(mapControl);

				activaBusqueda();

				cargaDatos();

				

			}

		});

		

		localSearch.execute(postcode + ", Spain");

	}



	function runSetCenterToPoint()

	{

	usePointFromPostcode(postcode, setCenterToPoint);

	}

	

	function setCenterToPoint(point2)

	{

			map.setCenter(point2, zoom+2);

	}



/* FIN DEL BUSCADOR POR C.P. */



function init() {

	map = new GMap2(document.getElementById("mapa"));

	puntoInicio = new GLatLng(42.399122,-8.502045);

	

	pasocp=0;	

	postcode=0;

	cpI=document.getElementById("inputcodpostalInmueble").value;	

	cpE=document.getElementById("inputcodpostalEmpresa").value;		

	cp3=document.getElementById("inputcodpostal3dExt").value;		

	cp3i=document.getElementById("inputcodigoInteriores").value;			

	

	if (cpI!='c.postal' && cpI!='')

	{

		pasocp=1;		

		postcode=cpI;

		usePointFromPostcode(cpI, runSetCenterToPoint);



	}

	if (cpE!='c.postal' && cpE!='')

	{

		pasocp=1;

		postcode=cpE;

		usePointFromPostcode(cpE, runSetCenterToPoint);

	}

	if (cp3!='c.postal' && cp3!='')

	{

		pasocp=1;	

		postcode=cp3;

		usePointFromPostcode(cp3, runSetCenterToPoint);	

	

	}

	if (cp3i!='c.postal' && cp3i!='')	

	{

		pasocp=1;			

		postcode=cp3i;

		usePointFromPostcode(cp3i, runSetCenterToPoint);		

	}



	if (pasocp==0)

	{

		map.setCenter(puntoInicio, zoom);

	}

	//map.disableDragging();

	//panoClient = new GStreetviewClient();

	map.addControl(new GSmallMapControl());

	geocoder = new GClientGeocoder();

	var mapControl = new GMapTypeControl();

	map.addControl(mapControl);

	//GEvent.addListener(map, "click", getAddress);

	activaBusqueda();



	//cargaCmbCategorias(tipoOferta);



	/*



	GEvent.addListener(map, "moveend", function(){

		//var center = map.getCenter();

		//alert(center.toString());

		cargaDatos();

		marcas = null;

		marcasW = null;

		ofertas = null;

		actualizaBarraDir();

	});

	*/

	cargaDatos();



	//geocoder = new GClientGeocoder();

	//buscadorHTML();

}

function desactivaBusqueda(){

	GEvent.removeListener(sensorMovimiento);

}

function activaBusqueda(){

	

	function actualizaTodo()

	{

		cargaDatos();

		marcas = null;

		marcasW = null;

		ofertas = null;

		actualizaBarraDir();

	}

	

	//dragend

	//moveend

	sensorMovimiento = GEvent.addListener(map, "dragend", function(){

		//var center = map.getCenter();

		//alert(center.toString());

//alert('g');

		actualizaTodo();

	});

	

	  //añadimos a GEvent un escuchador de eventos para cuando cambia el zoom

        function tratamiento_zoom(antiguoZoom, nuevoZoom) {

			actualizaTodo();

            //alert("Has cambiado el zoom del mapa!\n Antiguo Zoom: " + antiguoZoom + "\n Nuevo Zoom: " + nuevoZoom);

        }

		GEvent.addListener(map, "zoomend", tratamiento_zoom);

}

function actualizaBarraDir(){

	

}

function cargaCmbCategorias(nuevaCat){

	ruta = "cmbcat.php?tOferta="+nuevaCat;

	ajax=objetoAjax();

	ajax.open("GET", Utf8.encode(ruta),true);

	

	//GLog.write("ruta : " + Utf8.encode(ruta) );

	

	ajax.onreadystatechange=function() {

	if (ajax.readyState==1){

		//cargando

		//GLog.write("cargando : ");

	}

	else if (ajax.readyState==4) {

			if(ajax.status==200){

				//GLog.write("200 : " + ajax.responseText);

				document.getElementById("contcmbcat").innerHTML = ajax.responseText;

			}

		}

	}

	ajax.send(null);

}

function getCategoria(){

	valor = 0;

	 if (tipoOferta=="empresa")

	 {

		if(document.getElementById("cmbempresa").options[document.getElementById("cmbempresa").options.selectedIndex].value != 0)

		{

			valor += document.getElementById("cmbempresa").options[document.getElementById("cmbempresa").options.selectedIndex].value;

		}		 	

	 }

	 if (tipoOferta=="inmueble")

	 {

		if(document.getElementById("cmbinmueble").options[document.getElementById("cmbinmueble").options.selectedIndex].value != 0)

		{

			valor += document.getElementById("cmbinmueble").options[document.getElementById("cmbinmueble").options.selectedIndex].value;

		}		 

	 }

	 

	return valor;

}

function cambiaTipoOfertaBuscador(nueva){

	tipoOferta = nueva;

	document.getElementById('res_buscador').style.display='block';

	//cargaCmbCategorias(nueva);

	//cargaDatos2();

	//javi - para restablecer zoom y centrar mapa cuando se cambia de inmuebles a empresas

	zoom=9;

	init();

}

function valoresDefault()

{

	document.getElementById("inputcalleEmpresa").value='calle';

	document.getElementById("inputcodpostalEmpresa").value='c.postal';	

	document.getElementById("inputnombreEmpresa").value='nombre';		

	document.getElementById("inputcalleInmueble").value='calle';

	document.getElementById("inputcodpostalInmueble").value='c.postal';	

	document.getElementById("inputtamanoInmueblesMin").value='Medidas Min. (m2)';

	document.getElementById("inputtamanoInmueblesMax").value='Medidas Max. (m2)';	

	document.getElementById("inputprecioInmuebleMin").value='Precio Min.';	

	document.getElementById("inputprecioInmuebleMax").value='Precio Max.';		

	document.getElementById("inputhabitacionesInmueble").value='Habitaciones';

	document.getElementById("inputregimenInmueble").options.selectedIndex = 0;

	document.getElementById("inputlocalidad3d").options.selectedIndex = 0;
	document.getElementById("inputcalle3dExt").value='calle';

	document.getElementById("inputcodpostal3dExt").value='c.postal';	

	document.getElementById("inputlocalidad3di").options.selectedIndex = 0;
	document.getElementById("inputcalleInteriores").value='calle';

	document.getElementById("inputcodigoInteriores").value='c.postal';	

	document.getElementById("inputlocalidadEmpresa").options.selectedIndex = 0;

	document.getElementById("cmbempresa").options.selectedIndex = 0;

	document.getElementById("inputlocalidadInmueble").options.selectedIndex = 0;

	document.getElementById("cmbinmueble").options.selectedIndex = 0;

	document.getElementById('res_buscador').style.display='block';

}

function cambiaTipoOferta(nueva){

	tipoOferta = nueva;

	valoresDefault();

	if (nueva=="empresa")

	{

			document.getElementById("inputlocalidadEmpresa").options.selectedIndex = 0;

			document.getElementById("cmbempresa").options.selectedIndex = 0;

			document.getElementById("inputcalleEmpresa").value='calle';

			document.getElementById("inputcodpostalEmpresa").value='c.postal';		

			document.getElementById("inputnombreEmpresa").value='nombre';					

			document.getElementById('InputEmpresas').style.display='block';

			document.getElementById('InputInmuebles').style.display='none';

			document.getElementById('InputExteriores').style.display='none';

			document.getElementById('InputInteriores').style.display='none';			

			document.getElementById('buscador_i').innerHTML = "<a href=\"javascript:;\" onClick=\"cambiaTipoOfertaBuscador('empresa');\"><img src=\"images/empresas_21.gif\" border=\"0\">";

	}

    if (nueva=="inmueble")

	{	

			document.getElementById("inputcalleInmueble").value='calle';

			document.getElementById("inputcodpostalInmueble").value='c.postal';		

			document.getElementById("inputlocalidadInmueble").options.selectedIndex = 0;

			document.getElementById("cmbinmueble").options.selectedIndex = 0;

			document.getElementById('InputEmpresas').style.display='none';

			document.getElementById('InputInmuebles').style.display='block';

			document.getElementById('InputExteriores').style.display='none';

			document.getElementById('InputInteriores').style.display='none';				

			document.getElementById('buscador_i').innerHTML = "<a href=\"javascript:;\" onClick=\"cambiaTipoOfertaBuscador('inmueble');\"><img src=\"images/inmuebles_21.gif\" border=\"0\">";

	}

			

    if (nueva=="3d")

	{	
			document.getElementById("inputlocalidad3d").options.selectedIndex = 0;
			document.getElementById('InputEmpresas').style.display='none';

			document.getElementById('InputInmuebles').style.display='none';

			document.getElementById('InputExteriores').style.display='block';

			document.getElementById('InputInteriores').style.display='none';				

			document.getElementById('buscador_i').innerHTML = "<a href=\"javascript:;\" onClick=\"cambiaTipoOfertaBuscador('3d');\"><img src=\"images/calles_21.gif\" border=\"0\">";   	

	}

			

    if (nueva=="3di")

	{	
			document.getElementById("inputlocalidad3di").options.selectedIndex = 0;
			document.getElementById('InputEmpresas').style.display='none';

			document.getElementById('InputInmuebles').style.display='none';

			document.getElementById('InputExteriores').style.display='none';

			document.getElementById('InputInteriores').style.display='block';				

			document.getElementById('buscador_i').innerHTML = "<a href=\"javascript:;\" onClick=\"cambiaTipoOfertaBuscador('3di');\"><img src=\"images/interiores_21.gif\" border=\"0\">";   	

	}

			

//	cargaCmbCategorias(nueva);

	cargaDatos();

}

function infoMiniWindow(i, tipoOfer, idMarca){

	

	html = '<div id="infoTab">';

	if(ofertas[i].getAttribute("imagen")!=''){imagen=ofertas[i].getAttribute("imagen");}else{imagen='images/sinimagen.gif';}

	html += '<div id="imglist"><img class="peqs" src="'+imagen+'"/></div>';

	html += '<ul id="listado" onClick="irAOferta('+i+')">';

	

	if(tipoOfer == "empresa"){

		html += '<li class="emp"><span>'+ofertas[i].getAttribute("nombre")+', <span class="peq">'+ofertas[i].getAttribute("telefono")+'</span></span></li>';

//		html += '<span class="txt_res2">'+ofertas[i].getAttribute("calle")+' '+ofertas[i].getAttribute("numero")+' '+ofertas[i].getAttribute("piso")+' |  +34 '+ofertas[i].getAttribute("telefono")+'  |  +34 '+ofertas[i].getAttribute("fax")+'</span>';

//		html += '<span class="txt_res3">'+ofertas[i].getAttribute("email")+'  |  '+ofertas[i].getAttribute("web")+'</span>';

//		html += '</div></div></div></li>';

	}

	else if(tipoOfer == "inmueble"){

		html += '<li class="inmu"><span>'+ofertas[i].getAttribute("calle").toUpperCase()+' '+ofertas[i].getAttribute("numero").toUpperCase()+' '+ofertas[i].getAttribute("piso").toUpperCase()+'</span></li>';

		html += '<li><span>'+ofertas[i].getAttribute("n_habitaciones")+' habitaciones  |  exteriores '+ ofertas[i].getAttribute("exteriores") +' </span></li>';

		html += '<li><span>'+ofertas[i].getAttribute("tamano")+'m <super>2</super> </span></li>';

	}

	else if(tipoOfer == "3d"){

		html += '<li><span class="txt_res1" onClick="irAOferta('+i+')">'+ofertas[i].getAttribute("calle").toUpperCase()+' '+ofertas[i].getAttribute("numero").toUpperCase()+'</span></li>';

		html += '<li><span class="txt_res2">[ '+ofertas[i].getAttribute("dX")+' , '+ ofertas[i].getAttribute("dY") +' ] </span></li>';

		html += '<li><span class="txt_res3">c.p '+ofertas[i].getAttribute("codpostal")+'</span></li>';

	}
	
	else if(tipoOfer == "3di"){

		html += '<li><span class="txt_res1" onClick="irAOferta('+i+')">'+ofertas[i].getAttribute("calle").toUpperCase()+' '+ofertas[i].getAttribute("numero").toUpperCase()+'</span></li>';

		html += '<li><span class="txt_res2">[ '+ofertas[i].getAttribute("dX")+' , '+ ofertas[i].getAttribute("dY") +' ] </span></li>';

		html += '<li><span class="txt_res3">c.p '+ofertas[i].getAttribute("codpostal")+'</span></li>';

	}

	

	html += '</ul>';

	html += '</div>';

	

	return html;

}

function dibujaStats(nOfertas)

{

	if (tipoOferta=='3d')

		document.getElementById('stats').innerHTML = "Ofertas de Calles 3D : "+nOfertas;								

	if (tipoOferta=='3di')			

		document.getElementById('stats').innerHTML = "Ofertas de Interiores 3D : "+nOfertas;								

	if (tipoOferta=='empresa')			

			document.getElementById('stats').innerHTML = "Ofertas de Empresas : "+nOfertas;								

	if (tipoOferta=='inmueble')			

			document.getElementById('stats').innerHTML = "Ofertas de Inmueble : "+nOfertas;								

}

function createMarker2(marker,myHtml,idofUno,totalenGota) {

 // var marker = new GMarker(point);

//GLog.write(idofUno);

//alert('llega a createmarker2 con '+idofUno);

  marker.value = myHtml;

  GEvent.addListener(marker, "click", function() {

	

	if(totalenGota==1){irAOferta(idofUno);}

	else{

		if(totalenGota>5){centrarAumentarZoom(idofUno);}else{marker.openInfoWindowHtml(myHtml);}

	}

  });

  return marker;

}

function centrarAumentarZoom(idOferta)

{

	//GLog.write(idOferta);

	//idOfertaSelec = ofertas[idOferta].getAttribute("id");

	if(idOferta==3)

	{

		puntoOferta = new GLatLng(ofertas[idOferta].getAttribute("dX"),ofertas[idOferta].getAttribute("dY"));

		zoom = 14;

		map.setCenter(puntoOferta, zoom);

	}

}

function irAOferta(idOferta){

	//GLog.write(idOferta);

	//alert('llega de createmarker2 con '+idOferta);

	//alert("id en array : "+idOferta+" , tam array : "+ofertas.length +" p : "+ ofertas[idOferta].getAttribute("dX")+" , "+ofertas[idOferta].getAttribute("dY"));

	//alert("id : " + ofertas[idOferta].getAttribute("dx"));

	map.closeInfoWindow();

	//activaBusqueda();

	idOfertaSelec = ofertas[idOferta].getAttribute("id");

	puntoOferta = new GLatLng(ofertas[idOferta].getAttribute("dX"),ofertas[idOferta].getAttribute("dY"));

	zoom = 17;

	map.setCenter(puntoOferta, zoom);

	

		// javi, para que actualice datos al pinchar en el listado (cuando el evento es dragend en lugar de moveend)

		cargaDatos();

		marcas = null;

		marcasW = null;

		ofertas = null;

		actualizaBarraDir();

	

}

function cargaDatos(){

//alert('cargadatos');

	//alert("selec : " + idOfertaSelec);

	//if(idOfertaSelec == "-1") 
//PONEMOS A "" Y OCULTAMOS LA CAPA DE AVISO
	document.getElementById('avisoPm').style.display='none';														
	document.getElementById('avisoPm').innerHTML="";
	
	map.clearOverlays();

	document.getElementById('stats').innerHTML = "";		

	document.getElementById("res_buscador").innerHTML = '<span id=cargando_masdatos style="color:#FFFFFF"><img src=images/loader.gif></span>';

	var cmbCategoria = getCategoria();

	//alert(cmbCategoria);

	var auxEsquinas = map.getBounds();

	var max = auxEsquinas.getNorthEast();

	var min = auxEsquinas.getSouthWest();

	var zoom = map.getZoom();

	var ruta = "./panel/vista.php?new=vista";

	ruta += filtroDireccion();

	ruta += "&xmin="+min.lat();

	ruta += "&xmax="+max.lat();

	ruta += "&ymin="+min.lng();

	ruta += "&ymax="+max.lng();

	ruta += "&zoom="+zoom;

	ruta += "&tOferta="+tipoOferta;

	if(cmbCategoria != "0") ruta += "&idCat="+cmbCategoria;

	

//	alert(ruta);		

	//GLog.write("cargaDatos - ruta : "+ruta);

	//document.getElementById("izda").innerHTML = '<hr>'+ruta;

	GDownloadUrl(ruta, function(data){

		//resetArray(markers);

		//GLog.write(data);

		var xml = GXml.parse(data);

		var NingunaOfer=0;

		markers = xml.documentElement.getElementsByTagName("punto");

		var vista = xml.getElementsByTagName("puntos");

		var resultados = '';

		var tipOF='';

		var resultados2 = '';		

		var SetIcon=0;

		var tOfer = vista[0].getAttribute("tipoOferta");

		zoom = vista[0].getAttribute("zoom");

		//alert("tamaño de markers : "+ markers.length + "\n tamaño de zoom : " + vista[0].getAttribute("zoom"));

		//document.getElementById("izda").innerHTML += '<hr>encontrados : '+markers.length;

		//alert(vista[0].getAttribute("tipoOferta"))

		ofSel = -1;

		marcaSel = -1;

		ofertas = new Array();

		marcas = new Array();

		marcasW = new Array();

		resetArray(ofertas);

		resetArray(marcasW);

		

		if(markers.length > 0)

		{

		  var nOfertas = 0;

		  var nMarcas = 0;

		  //stats

		  

		  for (var i = 0; i < markers.length; i++) 

		  {

				if(markers[i].getAttribute("nofertas")!=0)

				{

					NingunaOfer=1;

					marcas[nMarcas] = markers[i];

	

					var ofertasTemp = markers[i].getElementsByTagName("oferta");

					resultados2='';

					var markLeng='';

					markLeng=markers[i].getElementsByTagName("oferta").length;

					SetIcon=0;

					for(var j=0; j < ofertasTemp.length; j++)

					{

	

						if (SetIcon==0)

					    {

						   SetIcon=1;

						   var latlng = new GLatLng( parseFloat(markers[i].getAttribute("x")),	parseFloat(markers[i].getAttribute("y")));

						   var iconoAmarillo = new GIcon(G_DEFAULT_ICON);

						   iconoAmarillo.iconSize = new GSize(44, 61);

						   if (ofertasTemp[j].getAttribute("tipo")=="empresa")

							   iconoAmarillo.image = "images/ico.php?ico=rosa.png&txt="+markLeng;

						   if (ofertasTemp[j].getAttribute("tipo")=="inmueble")

							   iconoAmarillo.image = "images/ico.php?ico=rojo.png&txt="+markLeng;

						   if (ofertasTemp[j].getAttribute("tipo")=="3d")				   

							   iconoAmarillo.image = "images/ico.php?ico=amarillo.png&txt="+markLeng;	
							   
						  if (ofertasTemp[j].getAttribute("tipo")=="3di")				   
						  {
							   iconoAmarillo.image = "images/ico.php?ico=azul.png&txt="+markLeng;	
						  }

							marcasW[nMarcas] = new GMarker(latlng, iconoAmarillo);

						}

						

					

						ofertas[nOfertas] = ofertasTemp[j];

						if(ofertasTemp[j].getAttribute("id") == idOfertaSelec){

							ofSel = nOfertas;

							marcaSel = nMarcas;

							tipOF='';

							tipOF=ofertasTemp[j].getAttribute("tipo");

						}

						resultados += infoWindow(nOfertas, tOfer);

						if(j<numeroOfertasListado)

						{

						resultados2 += infoMiniWindow(nOfertas, tOfer);

						}

						

						// miro si hay uno o varios registros en la gota para mandar a info o a listado

						totalenGota = ofertasTemp.length;

						if(totalenGota==1){idofUno = nOfertas;}

						else{

								if(totalenGota>5){idofUno = nOfertas;}else{idofUno = null;}

							}

						if(ofertasTemp.length>4){infolist = "<div id='listitems'>"+resultados2+"</div>";}else{infolist = resultados2;}

						map.addOverlay(createMarker2(marcasW[nMarcas],infolist,idofUno,totalenGota)); 

						//if (ofertasTemp[j].getAttribute("tipo")!='3d' || tipoOferta=='3d')

						nOfertas++;

					}

					

					/* PUNTO DEL CLIC*/

					// si la gota contiene 1 lanza info general, sino listado :: le paso a createmarker2 parametro con total

					//totalenGota = markers[i].getElementsByTagName("oferta").length;

					//if(totalenGota==1){idofUno = ofertasTemp[0].getAttribute("id");}else{idofUno = 0;}

					// miro cuantas ofertas vienen para el alto en el css

					//if(ofertasTemp.length==1){vectOfertas = resultados;}else{vectOfertas = resultados2;}

					//if(ofertasTemp.length>4){infolist = "<div id='listitems'>"+vectOfertas+"</div>";}else{infolist = vectOfertas;}

					//if(ofertasTemp.length>4){infolist = "<div id='listitems'>"+resultados2+"</div>";}else{infolist = resultados2;}

					//map.addOverlay(createMarker2(marcasW[nMarcas],infolist)); 

					

				    if(ofSel > -1)

					{

				  	  muestraInfo(ofSel, marcaSel ,tipOF);

					  desactivaBusqueda();

						GEvent.addListener(marcasW[nMarcas], "infowindowclose", function(){

							activaBusqueda();

							idOfertaSelec = -1;

							cargaDatos();	

						});

						GEvent.addListener(marcasW[nMarcas], "infowindowopen", function(){

							desactivaBusqueda();

						});

					}

					

					nMarcas++;

					document.getElementById('pm').style.display='block';

					document.getElementById('pm').innerHTML =escribeMasivo();					

					

				}

		

		  }

		  dibujaStats(nOfertas);

		  //alert(nOfertas);

		  document.getElementById("res_buscador").innerHTML = resultados;

		  //----------------------------------

/*			  

	if(idOfertaSelec != 0){

		for(var i=0; i < ofertas.length; i++){

			if(ofertas[i].getAttribute("id") == idOfertaSelec){

				muestraInfo(i);

				break;

			}

		}

	}

*/

		  //----------------------------------

		}

		else

		{

			//alert("No hay resultados para el area y los filtros proporcionados.");

			document.getElementById("res_buscador").innerHTML = noResultados();

			document.getElementById('stats').innerHTML = "Ofertas de "+tipoOferta+": 0 ";											

		}

		if (NingunaOfer==0)

		{

			document.getElementById("res_buscador").innerHTML = noResultados();

			dibujaStats(0);						

		}

		//scrollNow();

		/*

		if(formbuscador){

			

		}

		*/

	});

}

function escribeMasivo()

{

	return "";

}

function resetArray(arr){

	while(arr.length) arr.pop();

}

function noResultados(){

	var html = '';

	html += '<li><div class="outer"> <div class="inner"><div class="contenidos">';

	html += '<span class="txt_res1">Sin resultados</span><br>';

	html += '<span class="txt_res2">No hay resultados para el area y los filtros proporcionados.</span> <br>';

	html += '<span class="txt_res3"></span><br>';

	html += '</div></div></div></li>';

	return html;

}

function escondeInfo(){

	for(var i=0; i<marcasW.length;i++) marcasW[i].closeInfoWindow();

	//idOfertaSelec = -1;

}

function frContacto(idOferta){

		html = '<div id="infoTab">';

		html += '<div id="lft"><div id="lftF">';

		html += '<form method="post" action="javascript:void(0);" name="formulario" id="formulario" onSubmit="gotaContacto(\'lftF\',\'contacto/contacto.php\');return false;">';

		html += '<ul id="contacto">';

		html += '<li>*Nombre</li>';

		html += '<li><input type="text" name="nombre" id="nombre"></li>';

		html += '<li>*Email</li>';

		html += '<li><input type="text" name="email" id="email"></li>';

		html += '<li>Consulta</li>';

		html += '<li><textarea name="consulta" id="consulta"></textarea></li>';

		html += '<li class="IbtnEnv"><input type="hidden" name="idOferta" id="idOferta" value="'+ofertas[idOferta].getAttribute("id")+'"><input class="btnEnv" type="submit" value="Enviar"></li>';

		html += '</ul>';

		html += '</form>';

		html += '</div></div>';

		

		if(ofertas[idOferta].getAttribute("imagene")!=''){imagen=ofertas[idOferta].getAttribute("imagene");}else{imagen='images/sinimagen.gif';}

		html += '<div id="rgt"><img class="peq" src="'+imagen+'"/></div>';

		html += '</div>';

	return html;

}

function infoHTML(idOferta){

	tipodeOferta = ofertas[idOferta].getAttribute("tipo");

	html = '<div id="infoTab">';

	

	

	if(tipodeOferta == "empresa"){

		html += '<div id="lft">';

		html += '<ul>';

		html += '<li class="ppal">'+ofertas[idOferta].getAttribute("nombre").toUpperCase()+'</li>';

		html += '<li>'+ofertas[idOferta].getAttribute("calle")+' '+ofertas[idOferta].getAttribute("numero")+' '+ofertas[idOferta].getAttribute("piso")+'</li>';

		html += '<li> tlf 34 '+ofertas[idOferta].getAttribute("telefono")+'</li>';

		html += '<li> fax +34 '+ofertas[idOferta].getAttribute("fax")+'</li>';

		html += '<li class="otrosDatos">'+ofertas[idOferta].getAttribute("email")+'</li>';

		html += '<li><a href="'+ofertas[idOferta].getAttribute("web")+'" target="_blank">'+ofertas[idOferta].getAttribute("web")+'</a></li>';

		if(ofertas[idOferta].getAttribute("tags")!='')

		{

			html += '<li class="tags"><span>Tags:</span>'+ofertas[idOferta].getAttribute("tags")+'</li>';

		}

		if(ofertas[idOferta].getAttribute("id_modulo")!=0)

		{

			html += '<li class="tags"><span>Calle 3d:</span><a href="ver3d.php?id_emp='+ofertas[idOferta].getAttribute("id_modulo")+'" target="_blank">Ver calle</li>';

		}

		html += '</ul>';

		html += '</div>';

		

		if(ofertas[idOferta].getAttribute("imagen")!=''){imagen=ofertas[idOferta].getAttribute("imagen");}else{imagen='images/sinimagen.gif';}

		html += '<div id="rgt"><img src="'+imagen+'"/></div>';

		html += '</div>';

	}

	else if(tipodeOferta == "inmueble"){

		

		html += '<div id="lft">';

		html += '<ul>';

		html += '<li class="ppal">'+ofertas[idOferta].getAttribute("calle").toUpperCase()+' '+ofertas[idOferta].getAttribute("numero").toUpperCase()+' '+ofertas[idOferta].getAttribute("piso").toUpperCase()+'</li>';

		html += '<li>'+ofertas[idOferta].getAttribute("n_habitaciones")+' habitaciones</li>';

		html += '<li>'+ofertas[idOferta].getAttribute("tamano")+'m <super>2</super></li>';

		html += '<li>'+ofertas[idOferta].getAttribute("precio")+' &euro; / '+ofertas[idOferta].getAttribute("regimen")+'</li>';

		if(ofertas[idOferta].getAttribute("g_comunidad")!='')

		{

			html += '<li class="otrosDatos">Comunidad: '+ofertas[idOferta].getAttribute("g_comunidad")+' &euro;</li>';

		}

		//html += '<li><a href="'+ofertas[idOferta].getAttribute("web")+'" target="_blank">'+ofertas[idOferta].getAttribute("web")+'</a></li>';

		if(ofertas[idOferta].getAttribute("exteriores")!='')

		{

			html += '<li class="tags"><span>Exteriores:</span>'+ofertas[idOferta].getAttribute("exteriores")+'</li>';

		}

		if(ofertas[idOferta].getAttribute("id_modulo")!=0)

		{

			html += '<li class="tags"><span>Calle 3d:</span><a href="ver3d.php?id_inmu='+ofertas[idOferta].getAttribute("id_modulo")+'" target="_blank">Ver calle</li>';

		}

		html += '</ul>';

		html += '</div>';

		

		if(ofertas[idOferta].getAttribute("imagen")!=''){imagen=ofertas[idOferta].getAttribute("imagen");}else{imagen='images/sinimagen.gif';}

		html += '<div id="rgt"><img src="'+imagen+'"/></div>';

		html += '</div>';

	}

	else if(tipodeOferta == "3d"){

		html += '<div id="lft">';
		html += '<ul>';
		html += '<li>'+ofertas[idOferta].getAttribute("calle")+' '+ofertas[idOferta].getAttribute("numero")+' '+ofertas[idOferta].getAttribute("piso")+'</li>';
		html += '<li>'+ofertas[idOferta].getAttribute("codpostal")+', '+ofertas[idOferta].getAttribute("localidad")+'</li>';
		html += '<li class="otrosDatos">'+ofertas[idOferta].getAttribute("email")+'</li>';
		html += '<li><a href="'+ofertas[idOferta].getAttribute("web")+'" target="_blank">'+ofertas[idOferta].getAttribute("web")+'</a></li>';
		html += '<li style="padding-top:10px;">'+limitarCarac(ofertas[idOferta].getAttribute("descripcion"),95)+'</li>';

		if(ofertas[idOferta].getAttribute("tags")!='')
		{
			html += '<li class="tags"><span>Tags:</span>'+ofertas[idOferta].getAttribute("tags")+'</li>';
		}
		html += '</ul>';
		html += '</div>';
		
		if(ofertas[idOferta].getAttribute("imagen")!=''){imagen=ofertas[idOferta].getAttribute("imagen");}else{imagen='images/sinimagen.gif';}
		html += '<div id="rgt"><img src="'+imagen+'"/></div>';
		html += '</div>';
	}
	
	else if(tipodeOferta == "3di"){

		html += '<div id="lft">';
		html += '<ul>';
		html += '<li>'+ofertas[idOferta].getAttribute("calle")+' '+ofertas[idOferta].getAttribute("numero")+' '+ofertas[idOferta].getAttribute("piso")+'</li>';
		html += '<li>'+ofertas[idOferta].getAttribute("codpostal")+', '+ofertas[idOferta].getAttribute("localidad")+'</li>';
		html += '<li class="otrosDatos">'+ofertas[idOferta].getAttribute("email")+'</li>';
		html += '<li><a href="'+ofertas[idOferta].getAttribute("web")+'" target="_blank">'+ofertas[idOferta].getAttribute("web")+'</a></li>';
		html += '<li style="padding-top:10px;">'+limitarCarac(ofertas[idOferta].getAttribute("descripcion"),95)+'</li>';

		if(ofertas[idOferta].getAttribute("tags")!='')
		{
			html += '<li class="tags"><span>Tags:</span>'+ofertas[idOferta].getAttribute("tags")+'</li>';
		}
		html += '</ul>';
		html += '</div>';
		
		if(ofertas[idOferta].getAttribute("imagen")!=''){imagen=ofertas[idOferta].getAttribute("imagen");}else{imagen='images/sinimagen.gif';}
		html += '<div id="rgt"><img src="'+imagen+'"/></div>';
		html += '</div>';
	}

	

	//html += '<br>'+ofertas[idOferta].getAttribute("id");+'<br>';

	return html;

}

/*function infoHTML(idOferta){

	html = '<table style="color:black;"><tr><td width="50%"><table>'

	

	

	if(tipoOferta == "empresa"){

		html += '<tr><td class="etiqueta">'+ofertas[idOferta].getAttribute("nombre").toUpperCase()+'</td></tr>';

		html += '<tr><td class="etiqueta"> tlf 34 '+ofertas[idOferta].getAttribute("telefono")+'</td></tr>';

		html += '<tr><td class="etiqueta"> fax +34 '+ofertas[idOferta].getAttribute("fax")+'</td></tr>';

		html += '<tr><td class="etiqueta">'+ofertas[idOferta].getAttribute("calle")+' '+ofertas[idOferta].getAttribute("numero")+' '+ofertas[idOferta].getAttribute("piso")+' </td></tr>';

		html += '<tr><td class="etiqueta">'+ofertas[idOferta].getAttribute("email")+'</td></tr>';

		html += '<tr><td class="etiqueta">'+ofertas[idOferta].getAttribute("web")+'</td></tr>';

		html += '</table></td>';

		html += '<td><img src="'+ofertas[idOferta].getAttribute("imagen")+'" border="0" width="100%" height="100px"/>';

		html += '</td></tr></table>';

	}

	else if(tipoOferta == "inmueble"){

		html += '<tr><td class="etiqueta">'+ofertas[idOferta].getAttribute("calle").toUpperCase()+' '+ofertas[idOferta].getAttribute("numero").toUpperCase()+' '+ofertas[idOferta].getAttribute("piso").toUpperCase()+'</td></tr>';

		html += '<tr><td class="etiqueta">'+ofertas[idOferta].getAttribute("n_habitaciones")+' habitaciones  |  exteriores '+ ofertas[idOferta].getAttribute("exteriores") +' </td></tr>';

		html += '<tr><td class="etiqueta">'+ofertas[idOferta].getAttribute("tamano")+'m <super>2</super> </td></tr>';

		html += '</table></td>';

		html += '<td><img src="'+ofertas[idOferta].getAttribute("imagen")+'" border="0" width="100%" height="100px"/>';

		html += '</td></tr></table>';

	}

	else if(tipoOferta == "3d"){

		html += '<tr><td class="etiqueta">'+ofertas[idOferta].getAttribute("calle").toUpperCase()+' '+ofertas[idOferta].getAttribute("codpostal").toUpperCase()+'</td></tr>';

		html += '<tr><td class="etiqueta"><img src="'+ofertas[idOferta].getAttribute("imagen")+' width="200px" height="200px"/> </td></tr></table>';

	}

	

	//html += '<br>'+ofertas[idOferta].getAttribute("id");+'<br>';

	return html;

}*/

function enviaForm(){

	

}

function MuestraExteriores3d(idOferta)

{

	html = '<div id="infoTab">';

	html += '<ul>';

	html += '<li class="ppal">';	

	html += ''+ofertas[idOferta].getAttribute("calle").toUpperCase()+' '+ofertas[idOferta].getAttribute("codpostal").toUpperCase()+'</li></ul>';

	html += '</div>';	

	if(ofertas[idOferta].getAttribute("imagen")!=''){imagen=ofertas[idOferta].getAttribute("imagen");}else{imagen='images/sinimagen.gif';}	

	html += '<div id="rgt"><img src="'+imagen+'" /> </div>';

	return html;

}

function muestraInfo(idOferta, idMarca,tipOf){

	var tabs= new Array();

	/*if(tipOf == "3d") 

	{

		tabs[0] = new GInfoWindowTab("Visor de calles 3D", MuestraExteriores3d(idOferta));

	}

	else{

		tabs[0] = new GInfoWindowTab("Informacion", infoHTML(idOferta));

		tabs[1] = new GInfoWindowTab("Contacto", frContacto(idOferta));

	}*/
	tabs[0] = new GInfoWindowTab("Informacion", infoHTML(idOferta));
	tabs[1] = new GInfoWindowTab("Contacto", frContacto(idOferta));
	marcasW[idMarca].openInfoWindowTabsHtml(tabs);

}

function ok(){return true}

function buscaOfertasEnPunto(punto){

	var result = false;

	if(ofertas.length > 0){

		for(var i=0;i<ofertas.length; i++){

			ofertas[i].getAttribute("id")

		}

	}

	

}

function irAMarca(idMarca){

	var punto = marcasW[idMarca].getPoint();

	if(zoom > 14){

		//agrupamos segun el zoom (9-17)

		var idOfertaSimple = buscaOfertasEnPunto(punto);

		//GLog.write(idOfertaSimple);

	}

	else if(zoom > 12){

		//mostramos codpostal vamos a zoom 14

		map.setCenter();

		auxzoom = 14;

		map.setCenter(punto, auxzoom);

	}

	else{

		//mostramos localidad vamos a zoom 12

		auxzoom = 12;

		map.setCenter(punto, auxzoom);

	}

	zoom = auxzoom;

}

/*function irAOferta(idOferta){

	//alert("id en array : "+idOferta+" , tam array : "+ofertas.length +" p : "+ ofertas[idOferta].getAttribute("dX")+" , "+ofertas[idOferta].getAttribute("dY"));

	//alert("id : " + ofertas[idOferta].getAttribute("dx"));

	map.closeInfoWindow();

	//activaBusqueda();

	idOfertaSelec = ofertas[idOferta].getAttribute("id");

	puntoOferta = new GLatLng(ofertas[idOferta].getAttribute("dX"),ofertas[idOferta].getAttribute("dY"));

	zoom = 17;

	map.setCenter(puntoOferta, zoom);

	

		// javi, para que actualice datos al pinchar en el listado (cuando el evento es dragend en lugar de moveend)

		cargaDatos();

		marcas = null;

		marcasW = null;

		ofertas = null;

		actualizaBarraDir();

	

}

*/

function infoWindow(i, tipoOfer, idMarca){

	//alert(ofertas.length);

//	<input type="button" onclick="alert(document.getElementById(\'mass\').value);"><input type="text" name="mass" id="mass">

	var html = '';

	html += '<li><div class="outer"><div class="inner"><div class="contenidos">';



	if(ofertas[i].getAttribute("tipo") == "empresa"){
if (dibujaMas==1)
		html += '<span class="txt_res3_1">Presupuesto masivo<input id="chk'+ofertas[i].getAttribute("id")+'" type="checkbox" value="'+ofertas[i].getAttribute("id")+'" onclick="llenarMasivo(this.value);" ></span>';			

		html += '<span class="txt_res1" onClick="irAOferta('+i+')"><font color=violet>EMPRESA</font> - '+ofertas[i].getAttribute("nombre").toUpperCase()+'</span>';

		html += '<span class="txt_res2">'+ofertas[i].getAttribute("calle")+' '+ofertas[i].getAttribute("numero")+' '+ofertas[i].getAttribute("piso")+' - '+ofertas[i].getAttribute("localidad")+', '+ ofertas[i].getAttribute("codpostal") +'</span>';

		html += '<span class="txt_res2"> +34 '+ofertas[i].getAttribute("telefono")+'  |  +34 '+ofertas[i].getAttribute("fax")+'</span>';

		html += '<span class="txt_res3">'+ofertas[i].getAttribute("email")+'  |  '+ofertas[i].getAttribute("web")+'</span>';

		html += '</div></div></div></li>';

	}

	else if(ofertas[i].getAttribute("tipo") == "inmueble"){

		//html += '<span class="txt_res3_1">Presupuesto masivo<input id="chk'+ofertas[i].getAttribute("id")+'" type="checkbox" value="'+ofertas[i].getAttribute("id")+'" onclick="llenarMasivo(this.value);" ></span>';						

		html += '<span class="txt_res1" onClick="irAOferta('+i+')"><font color=#E78684>INMUEBLE</font> - '+ofertas[i].getAttribute("calle").toUpperCase()+' '+ofertas[i].getAttribute("numero").toUpperCase()+' '+ofertas[i].getAttribute("piso").toUpperCase()+'</span>';

		html += '<span class="txt_res2">'+ofertas[i].getAttribute("n_habitaciones")+' habitaciones  |  exteriores '+ ofertas[i].getAttribute("exteriores") +' </span>';

		html += '<span class="txt_res2">'+ofertas[i].getAttribute("localidad")+', '+ ofertas[i].getAttribute("codpostal") +' </span>';

		html += '<span class="txt_res3">'+ofertas[i].getAttribute("tamano")+'m <super>2</super> </span></div></div></li>';

	}

	else if(ofertas[i].getAttribute("tipo") == "3d")

	{

		html += '<span class="txt_res1" onClick="irAOferta('+i+')"><font color=yellow>CALLE 3D</font> - '+ofertas[i].getAttribute("titulo").toUpperCase()+'</span>';

		html += '<span class="txt_res2">'+ofertas[i].getAttribute("calle")+' '+ofertas[i].getAttribute("numero")+' '+ofertas[i].getAttribute("piso")+' - '+ofertas[i].getAttribute("localidad")+', '+ ofertas[i].getAttribute("codpostal") +'</span>';

		html += '<span class="txt_res3">'+limitarCarac(ofertas[i].getAttribute("descripcion"),130)+'</span></div></div></li>';

	}
	
	else if(ofertas[i].getAttribute("tipo") == "3di")

	{

		html += '<span class="txt_res1" onClick="irAOferta('+i+')"><font color=yellow>INTERIOR 3D</font> - '+ofertas[i].getAttribute("titulo").toUpperCase()+'</span>';

		html += '<span class="txt_res2">'+ofertas[i].getAttribute("calle")+' '+ofertas[i].getAttribute("numero")+' '+ofertas[i].getAttribute("piso")+' - '+ofertas[i].getAttribute("localidad")+', '+ ofertas[i].getAttribute("codpostal") +'</span>';

		html += '<span class="txt_res3">'+limitarCarac(ofertas[i].getAttribute("descripcion"),130)+'</span></div></div></li>';

	}

	return html;

}



function limitarCarac(str,num)

{

	str = str.substring(0,num);

	str+= "...";

	return str;

}

/*function infoWindow(i, tipoOfer, idMarca){

	//alert(ofertas.length);

//	<input type="button" onclick="alert(document.getElementById(\'mass\').value);"><input type="text" name="mass" id="mass">

	var html = '';

	html += '<li><div class="outer"><div class="inner"><div class="contenidos"><span class="txt_res3_1">Presupuesto masivo<input id="chk'+ofertas[i].getAttribute("id")+'" type="checkbox" value="'+ofertas[i].getAttribute("id")+'" onclick="llenarMasivo(this.value);" ></span>';

	

	if(tipoOfer == "empresa"){

		html += '<span class="txt_res1" onClick="irAOferta('+i+')">'+ofertas[i].getAttribute("nombre").toUpperCase()+'</span>';

		html += '<span class="txt_res2">'+ofertas[i].getAttribute("calle")+' '+ofertas[i].getAttribute("numero")+' '+ofertas[i].getAttribute("piso")+' |  +34 '+ofertas[i].getAttribute("telefono")+'  |  +34 '+ofertas[i].getAttribute("fax")+'</span>';

		html += '<span class="txt_res3">'+ofertas[i].getAttribute("email")+'  |  '+ofertas[i].getAttribute("web")+'</span>';

		html += '</div></div></div></li>';

	}

	else if(tipoOfer == "inmueble"){

		html += '<span class="txt_res1" onClick="irAOferta('+i+')">'+ofertas[i].getAttribute("calle").toUpperCase()+' '+ofertas[i].getAttribute("numero").toUpperCase()+' '+ofertas[i].getAttribute("piso").toUpperCase()+'</span>';

		html += '<span class="txt_res2">'+ofertas[i].getAttribute("n_habitaciones")+' habitaciones  |  exteriores '+ ofertas[i].getAttribute("exteriores") +' </span><br>';

		html += '<span class="txt_res3">'+ofertas[i].getAttribute("tamano")+'m <super>2</super> </span><br></div></div></li>';

	}

	else if(tipoOfer == "3d"){

		html += '<span class="txt_res1" onClick="irAOferta('+i+')">'+ofertas[i].getAttribute("calle").toUpperCase()+' '+ofertas[i].getAttribute("numero").toUpperCase()+' </span> <br>';

		html += '<span class="txt_res2">[ '+ofertas[i].getAttribute("dX")+' , '+ ofertas[i].getAttribute("dY") +' ] </span><br>';

		html += '<span class="txt_res3">c.p '+ofertas[i].getAttribute("codpostal")+'</span><br></div></div></li>';

	}

	return html;

}

*/

function buscadorHTML(){

//	var contenedor = document.getElementById("izda");

	var contenedor = document.getElementById("buscador");

	var html = '';

//	html += '<div id="buscador"><table>';

	html += '<table>';

	html += '<tr><td>Piso</td><td><input type="text" name="piso" id="inputPiso" value="" /></td></tr>';

	html += '<tr><td>N\xFAmero (<span id="numero"></span>)</td><td><input type="text" name="numero" id="inputNumero" onChange="localizaNumero()" value="" /></td></tr>';

	html += '<tr><td>Calle</td><td><input type="text" name="calle" id="inputCalle" value="" /></td></tr>';

	html += '<tr><td>Localidad</td><td><input type="text" name="localidad" id="inputLocalidad" value="" /></td></tr>';

	html += '<tr><td>C\xF3digo Postal</td><td><input type="text" name="codPostal" id="inputCodPostal" value="" /></td></tr>';

	html += '</table>';

	//html += '<input type="button" onclick="localiza();" value="Buscar"/>';

	html += '<div id="boton_buscar"><a href="javascript:;" onclick="localiza();"><img src="images/buscar.gif" border="0"></a></div>';

	html += '<div id="capaEnviar"><input type="button" onclick="nuevaDireccion();" value="guardar"/></div>';

//	html += '</div>';

	contenedor.innerHTML = html;

	//alert(html);

	

}

function IsNumeric(sText)

{

   var ValidChars = "0123456789.";

   var IsNumber=true;

   var Char;

 

   for (i = 0; i < sText.length && IsNumber == true; i++) 

      { 

      Char = sText.charAt(i); 

      if (ValidChars.indexOf(Char) == -1) 

         {

         IsNumber = false;

         }

      }

   return IsNumber;

   

   }

function filtroDireccion(){

	var ruta = "";

	 if (tipoOferta=="empresa")

	 {

		if(document.getElementById("inputlocalidadEmpresa").options[document.getElementById("inputlocalidadEmpresa").options.selectedIndex].value != 0)

		{

			ruta += "&localidad="+document.getElementById("inputlocalidadEmpresa").options[document.getElementById("inputlocalidadEmpresa").options.selectedIndex].value;

		}	

		if(document.getElementById("inputcalleEmpresa").value != '' && document.getElementById("inputcalleEmpresa").value != 'calle')

		{

			ruta += "&calle="+document.getElementById("inputcalleEmpresa").value;	

		}	

		if(document.getElementById("inputcodpostalEmpresa").value != '' && document.getElementById("inputcodpostalEmpresa").value != 'c.postal')

		{

			ruta += "&codpostal="+document.getElementById("inputcodpostalEmpresa").value;	

		}		

		if(document.getElementById("inputnombreEmpresa").value != '' && document.getElementById("inputnombreEmpresa").value != 'nombre')

		{

			ruta += "&nombreempresa="+document.getElementById("inputnombreEmpresa").value;	

		}					

	 }

	 if (tipoOferta=="inmueble")

	 {

		if(document.getElementById("inputlocalidadInmueble").options[document.getElementById("inputlocalidadInmueble").options.selectedIndex].value != 0)

		{

			ruta += "&localidad="+document.getElementById("inputlocalidadInmueble").options[document.getElementById("inputlocalidadInmueble").options.selectedIndex].value;

		}		 

		if(document.getElementById("inputcalleInmueble").value != '' && document.getElementById("inputcalleInmueble").value != 'calle')

		{

			ruta += "&calle="+document.getElementById("inputcalleInmueble").value;	

		}	

		if(document.getElementById("inputcodpostalInmueble").value != '' && document.getElementById("inputcodpostalInmueble").value != 'c.postal')

		{

			ruta += "&codpostal="+document.getElementById("inputcodpostalInmueble").value;	

		}

	

		if( document.getElementById("inputtamanoInmueblesMin").value != '' && IsNumeric(document.getElementById("inputtamanoInmueblesMin").value))

		{

			ruta += "&tamanomin="+document.getElementById("inputtamanoInmueblesMin").value;	

		}	

		if(document.getElementById("inputtamanoInmueblesMax").value != '' && IsNumeric(document.getElementById("inputtamanoInmueblesMax").value))

		{

			ruta += "&tamanomax="+document.getElementById("inputtamanoInmueblesMax").value;	

		}			

		

		if(document.getElementById("inputprecioInmuebleMin").value != '' && document.getElementById("inputprecioInmuebleMin").value != 'Precio Min.')

		{

			ruta += "&preciomin="+document.getElementById("inputprecioInmuebleMin").value;	

		}	

		if(document.getElementById("inputprecioInmuebleMax").value != '' && document.getElementById("inputprecioInmuebleMax").value != 'Precio Max.')

		{

			ruta += "&preciomax="+document.getElementById("inputprecioInmuebleMax").value;	

		}			

		

		if(document.getElementById("inputhabitacionesInmueble").value != '' && document.getElementById("inputhabitacionesInmueble").value != 'Habitaciones' && document.getElementById("inputhabitacionesInmueble").value != 'Habitaciones')

		{

			ruta += "&habitaciones="+document.getElementById("inputhabitacionesInmueble").value;	

		}	

		

		if(document.getElementById("inputregimenInmueble").options[document.getElementById("inputregimenInmueble").options.selectedIndex].value != 0)

		{

			ruta += "&regimen="+document.getElementById("inputregimenInmueble").options[document.getElementById("inputregimenInmueble").options.selectedIndex].value;

		}			

		

							

	 }

	

	 if (tipoOferta=="3d")

	 {
		 
		 if(document.getElementById("inputlocalidad3d").options[document.getElementById("inputlocalidad3d").options.selectedIndex].value != 0)

		{

			ruta += "&localidad="+document.getElementById("inputlocalidad3d").options[document.getElementById("inputlocalidad3d").options.selectedIndex].value;

		}

		if(document.getElementById("inputcalle3dExt").value != '' && document.getElementById("inputcalle3dExt").value != 'calle')

		{

			ruta += "&calle="+document.getElementById("inputcalle3dExt").value;	

		}	

		if(document.getElementById("inputcodpostal3dExt").value != '' && document.getElementById("inputcodpostal3dExt").value != 'c.postal')

		{

			ruta += "&codpostal="+document.getElementById("inputcodpostal3dExt").value;	

		}	

	 }
	 
	if (tipoOferta=="3di")

	 {
		 
		if(document.getElementById("inputlocalidad3di").options[document.getElementById("inputlocalidad3di").options.selectedIndex].value != 0)

		{

			ruta += "&localidad="+document.getElementById("inputlocalidad3di").options[document.getElementById("inputlocalidad3di").options.selectedIndex].value;

		}

		if(document.getElementById("inputcalleInteriores").value != '' && document.getElementById("inputcalleInteriores").value != 'calle')

		{

			ruta += "&calle="+document.getElementById("inputcalleInteriores").value;	

		}	

		if(document.getElementById("inputcodigoInteriores").value != '' && document.getElementById("inputcodigoInteriores").value != 'c.postal')

		{

			ruta += "&codpostal="+document.getElementById("inputcodigoInteriores").value;	

		}	

	 }

				   

	if(ruta) ruta += "&enbuscador=1";

//alert(ruta);

	return ruta;

}

function nuevaDireccion(){

	

	var ruta = "panel/alta.php?new=dir";

	var datosOk = false;

	if(getValor("Piso") != '' && getValor("Piso") != 'piso') {

		ruta += "&piso="+getValor("Piso");

		datosOk = true;

	}else{

		datosOk = false;

	}

	

	if(getValor("Numero") != '') {

		ruta += "&numero="+getValor("Numero");

		datosOk = true;

	}else{

		datosOk = false;

	}

	if(getValor("Calle") != '' && getValor("Calle") != 'calle') {

		ruta += "&calle="+getValor("Calle");

		datosOk = true;

	}else{

		datosOk = false;

	}

	if(getValor("Localidad") != '' && getValor("Localidad") != 'localidad') {

		ruta += "&localidad="+getValor("Localidad");

		datosOk = true;

	}else{

		datosOk = false;

	}

	if(getValor("CodPostal") != '' && getValor("CodPostal") != 'c.postal') {

		ruta += "&codpostal="+getValor("CodPostal");

		datosOk = true;

	}else{

		datosOk = false;

	}

	

	var paux = marcador.getLatLng();

	if(true){

		ruta += "&x=" + paux.lat();

		ruta += "&y=" + paux.lng();

	}

	

	ajax=objetoAjax();

	ajax.open("GET", Utf8.encode(ruta),true);

	ajax.onreadystatechange=function() {

	if (ajax.readyState==1){

		//cargando

	}

	else if (ajax.readyState==4) {

			if(ajax.status==200){

				if(ajax.responseText == 1) alert("direccion guardada")

				else alert("error guardando direccion, respuesta\n"+ajax.responseText);

			}

		}

	}

	ajax.send(null);

}

function getValor(nombre){

	if(document.getElementById('input'+nombre) != null)	return document.getElementById('input'+nombre).value

	else return false;

}

function input(nombre){

	if(document.getElementById('input'+nombre) != null)	return document.getElementById('input'+nombre);

	else return false;

}

function localizaNumero(){

	document.getElementById("capaEnviar").style.display = "block";

	localiza();

}

/*

function cambiaInput(nombreInput){

	if(nombreInput == "calle"){

		//input("Localidad").value = "";

		input("Calle").value = "";

	}

	else if(nombreInput == "codpostal"){

		input("CodPostal").value = "";

		input("Calle").value = "calle";

		input("Localidad").value = "localidad";

	}

	else if(nombreInput == "localidad"){

		input("Calle").value = "calle";

		input("CodPostal").value = "c.postal";

		input("Localidad").value = "";

	}

}

*/

function localiza(){

	var cadena = '';

	var nuevoZoom = false;

	zoom = 9;

	if(getValor("Numero") != '' && getValor("Numero")){

		cadena += ', '+getValor("Numero");

		if(zoom<17) zoom = 17;

		nuevoZoom = true;

		numeroForm = true;

	}else numeroForm = false;

	

	if(getValor("Calle") != '' && getValor("Calle") != 'calle'){

		cadena += ', '+getValor("Calle");

		if(zoom<16) zoom = 16;

		nuevoZoom = true;

	}

//	alert('no');

	if(getValor("Localidad") != '' && getValor("Localidad") != 'localidad'){

		cadena += ', '+getValor("Localidad");

		if(zoom<13) zoom = 13;

		nuevoZoom = true;

	}

	if(getValor("CodPostal") != '' && getValor("CodPostal") != 'c.postal'){

		cadena += ', '+getValor("CodPostal");

		if(zoom<14)zoom = 15;

		nuevoZoom = true;

	}

	

	if(!nuevoZoom) zoom = 9;

	

	cadena += ', ' + provincia + ' , '+ pais;

	//alert(cadena);

	

	//document.getElementById("izda").innerHTML += "<br>"+cadena;

	

	muestraDireccion(cadena);

}

function muestraDireccion(address){

  if (geocoder) {

	geocoder.getLatLng(

	  address,

	  function(point) {

		if (!point) {

			alert(address + " no encontrada");

			zoom = 9;

			map.clearOverlays();

			map.setCenter(puntoInicio, zoom);

		} else {

		  map.setCenter(point, zoom);

		  //hay que devolver la direccion de ese punto

		  getAddress(map, point);

		  //---------------------------

		  	map.clearOverlays();

			/*

			marcador = new GMarker(point, {draggable: true, title: "+"});

			GEvent.addListener(marcador, "dragstart", function() {

			  //map.closeInfoWindow();

			});

	

			GEvent.addListener(marcador, "dragend", function() {

			  //marker.openInfoWindowHtml("<input type='button' name='' id='' value='aceptar'/>");

			  numeroForm = false;

			  //input("Numero").value = '';

			  getAddress(map, marcador.getLatLng());

			  //setTimeout("clearInterval("+id+")",15000);

			  //nuevoPunto = new GLatLng();

			  //marker.getPointAsync(nuevoPunto);

			  //var latlng = marker.getLatLng();

		      //var lat = latlng.lat();

		      //var lng = latlng.lng();

			  //alert("nuevo : " + marker.getPointAsync());

			});

	

			map.addOverlay(marcador);

			*/

		  //---------------------------

		  

		  /*

		  var marker = new GMarker(point);

		  map.addOverlay(marker);

		  marker.openInfoWindowHtml(address);

		  */

		}

	  }

	);

  }

}

function getAddress(overlay, latlng) {

  if (latlng != null) {

	address = latlng;

	geocoder.getLocations(latlng, capturaDireccion);

  }

}

function capturaDireccion(response) {

  //map.clearOverlays();

  if (!response || response.Status.code != 200) {

	alert("Status Code:" + response.Status.code);

  } else {

	place = response.Placemark[0];

	point = new GLatLng(place.Point.coordinates[1],	place.Point.coordinates[0]);

	//alert(dir(place));

	//muestraFormulario(place);

	//actualizaFormulario(place);

  }

}

function actualizaFormulario(place){

	var intervaloNum = intervaloNumeros(place);

	var direccion = dir(place);

	if(intervaloNum.length > 1) {

		//input("SpanNumero").value = intervaloNum[0] +' - '+ intervaloNum[1];

		//document.getElementById("numero").innerHTML = intervaloNum[0] +' - '+ intervaloNum[1];

	}

	else {

		//if(intervaloNum[0] != null) document.getElementById("numero").innerHTML = intervaloNum[0];

		//else document.getElementById("numero").innerHTML = '';

	}

	if(direccion.length == 4) input("Calle").value = direccion[3];

	input("CodPostal").value = direccion[2];

	input("Localidad").value = direccion[1];

}

function quitaEspacio(cadena){

	if(cadena[0] == " ") cadena = cadena.substring(1, cadena.length );

	return cadena;

}

function dir(place){

	var dir = new String(place.address.toString());

	var aux = dir.split(",");

	var rdo = new Array();

	if (aux.length > 0) {

		rdo[0] = quitaEspacio(aux[aux.length - 1].toString());

		rdo[1] = quitaEspacio(aux[aux.length - 2].toString());

		rdo[2] = quitaEspacio(aux[aux.length - 3].toString());

		if (aux.length > 3) {

			rdo[3] = quitaEspacio(aux[0].toString());

		}

	}else alert("no hay respuesta coherente");

	return rdo;

}

function intervaloNumeros(place){

	var dir = new String(place.address.toString());

	var aux = dir.split(", ");

	var rdo = new Array();

	if(aux.length == 5){

		//alert("primero : " + dir + "\nultimo : "+ aux.length + "\ntodo : " + aux[1]);

		var intervalo = aux[1].toString();

		if(intervalo.indexOf("-") > -1) {

			rdo = null;

			rdo = intervalo.split("-");

			//alert("primero : " + rdo[0] + "\nultimo : "+ rdo[1]);

		}

		else rdo = intervalo;

	}

	return rdo;

}

function objetoAjax(){

	var xmlhttp=false;

	try {

		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

	} catch (e) {

		try {

		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

		} catch (E) {

			xmlhttp = false;

  		}

	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {

		xmlhttp = new XMLHttpRequest();

	}

	return xmlhttp;

}

function objetoAjax2(){

	var xmlhttp=false;

	try {

		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

	} catch (e) {

		try {

		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

		} catch (E) {

			xmlhttp = false;

  		}

	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {

		xmlhttp = new XMLHttpRequest();

	}

	return xmlhttp;

}

function gotaContacto(capa,pag)

 {

	 //alert(capa+' - '+pag);

	document.getElementById(capa).style.display='block';

	nombre = document.getElementById('nombre').value;

	email = document.getElementById('email').value;

	consulta = document.getElementById('consulta').value;

	idOferta = document.getElementById('idOferta').value;

	val = "nombre="+nombre+"&email="+email+"&consulta="+consulta+"&idOferta="+idOferta+"";

	//alert(pag+' / '+capa+' / '+val+' / post');

	envio(pag,capa,''+val+'','post');

 }

 

function envio(datos,divID,valores,metodo) 

{ 

	//alert(datos+' - '+divID+' - '+valores+' - '+metodo);

	ajax=objetoAjax2();

	if(ajax) 

	{

     	var obj = document.getElementById(divID); 

	 	if(metodo.toUpperCase()=='POST')

		{

     		ajax.open("POST", datos, true); 

     		ajax.onreadystatechange = function()  

				{ 

					if (ajax.readyState==1) 

					{

                          obj.innerHTML="<div id=loader><img src=images/loaderN.gif></div>";

        			 }

         			else if (ajax.readyState == 4) 

					{ 

						//alert(ajax.responseText);

               			obj.innerHTML = ajax.responseText;

          			} 

    		 } 

         ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

         ajax.send(valores);

		}

	}

}

function reemplaza_cadena(cadena)

{

		cadena = cadena.replace(/œ/g,"oe");

		cadena = cadena.replace(/–/g,"-");

		cadena = cadena.replace(/—/g,"-");

		cadena = cadena.replace(/’/g,"´");

		cadena = cadena.replace(/&/g,"#");

		return cadena;

}

var Utf8 = {

	// public method for url encoding

	encode: function(string){

		string = string.replace(/\r\n/g, "\n");

		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {

				utftext += String.fromCharCode(c);

			}

			else 

				if ((c > 127) && (c < 2048)) {

					utftext += String.fromCharCode((c >> 6) | 192);

					utftext += String.fromCharCode((c & 63) | 128);

				}

				else {

					utftext += String.fromCharCode((c >> 12) | 224);

					utftext += String.fromCharCode(((c >> 6) & 63) | 128);

					utftext += String.fromCharCode((c & 63) | 128);

				}

		}

		return utftext;

	},

	// public method for url decoding

	decode: function(utftext){

		var string = "";

		var i = 0;

		var c = c1 = c2 = 0;

		while (i < utftext.length) {

			c = utftext.charCodeAt(i);

			if (c < 128) {

				string += String.fromCharCode(c);

				i++;

			}

			else 

				if ((c > 191) && (c < 224)) {

					c2 = utftext.charCodeAt(i + 1);

					string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));

					i += 2;

				}

				else {

					c2 = utftext.charCodeAt(i + 1);

					c3 = utftext.charCodeAt(i + 2);

					string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));

					i += 3;

				}

		}

		return string;

		

	}

}

//Borra el input que se le pasa

function borraDatos(inp)

{

	document.getElementById(inp.id).value='';	

}


