// JavaScript Document
// Crea el objeto AJAX
var oficina=41;

  function AJAXCrearObjeto(){
    var obj;
    if(window.XMLHttpRequest) { // no es IE
      obj = new XMLHttpRequest();
    } else { // Es IE o no tiene el objeto
      try {
        obj = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e) {
        alert('El navegador utilizado no está soportado');
      }
    }
    return obj;
  }
  
// Rellena los grupos
  function cargarGrupos(){
	  oXML = AJAXCrearObjeto();
	  oXML.open('get', '../xml/clases_inmueble.php');
	  oXML.onreadystatechange = function () {
		   if (oXML.readyState == 4) {
			  // Accedemos al XML recibido
			  var xml  = oXML.responseXML.documentElement;
			  // Accedemos al DIV
			  document.busqueda.grupo_inmueble.options[0] = new Option("----",'');
			  
			  for (i = 0; i < xml.getElementsByTagName('clase').length; i++){
				// Accedemos al objeto XML usuario
				var item = xml.getElementsByTagName('clase')[i];
				// Recojemos el id
				var id = item.getElementsByTagName('id')[0].firstChild.data;
				// Recojemos el nombre
				var nombre = item.getElementsByTagName('nombre')[0].firstChild.data;
				// Mostramos el enlace
				document.busqueda.grupo_inmueble.options[i+1] = new Option(nombre,id); 
			  }
			 
			}
			
	  };
	  oXML.send('');
    // Comprobamos que se han recibido los datos
  }
  function cargarTipos(grupo_inmueble){
	 if(grupo_inmueble.length>0){
		 	//alert(grupo_inmueble.value);
		  
		  oXML = AJAXCrearObjeto();
		  oXML.open('get', '../xml/tipos_inmueble.php?id_clase='+grupo_inmueble.value);
		  oXML.onreadystatechange = function () {
			   if (oXML.readyState == 4) {
				  // Accedemos al XML recibido
				  var xml  = oXML.responseXML.documentElement;
				  // Accedemos al DIV
				 document.busqueda.tipo_inmueble.length=0;
				 document.busqueda.tipo_inmueble.options[0] = new Option("----",'');
				 if(xml.getElementsByTagName('tipo').length>0){
					 for (i = 0; i < xml.getElementsByTagName('tipo').length; i++){
						// Accedemos al objeto XML usuario
						var item = xml.getElementsByTagName('tipo')[i];
						// Recojemos el id
						var id = item.getElementsByTagName('id')[0].firstChild.data;
						// Recojemos el nombre
						var nombre = item.getElementsByTagName('nombre')[0].firstChild.data;
						// Mostramos el enlace
						document.busqueda.tipo_inmueble.options[i+1] = new Option(nombre,id); 
					  }
				 }else{
					  document.busqueda.tipo_inmueble.length=0;
					  //document.busqueda.tipo_inmueble.options[0] = new Option("----",0);
				 }
				 
				}
				
		  };
		  oXML.send('');
	 }
    // Comprobamos que se han recibido los datos
  }  
  
  function cargarProvincias(){
	  oXMLprov = AJAXCrearObjeto();
	  oXMLprov.open('get', '../xml/provincias.php?id_oficina='+oficina);
	  oXMLprov.onreadystatechange = function () {
		   if (oXMLprov.readyState == 4) {
			  // Accedemos al XML recibido
			  var xml  = oXMLprov.responseXML.documentElement;
			  // Accedemos al DIV
			  document.busqueda.provincia_inmueble.options[0] = new Option("----",'');
			 if(xml.getElementsByTagName('provincia').length>0){
				 for (i = 0; i < xml.getElementsByTagName('provincia').length; i++){
					// Accedemos al objeto XML usuario
					var item = xml.getElementsByTagName('provincia')[i];
					// Recojemos el id
					var id = item.getElementsByTagName('id')[0].firstChild.data;
					// Recojemos el nombre
					var nombre = item.getElementsByTagName('nombre')[0].firstChild.data;
					// Mostramos el enlace
					document.busqueda.provincia_inmueble.options[i+1] = new Option(nombre,id); 
				  }
			 }else{
				  document.busqueda.provincia_inmueble.length=0;
				  //document.busqueda.tipo_inmueble.options[0] = new Option("----",0);
			 }
			 
			}
			
	  };
	  oXMLprov.send('');
  }  
  
  function cargarCiudades(provincia_inmueble){
	 if(provincia_inmueble.length>0){
		 	//alert(grupo_inmueble.value);
		  
		  oXMLciu = AJAXCrearObjeto();
		  oXMLciu.open('get', '../xml/ciudades.php?id_provincia='+provincia_inmueble.value+'&id_oficina='+oficina);
		  oXMLciu.onreadystatechange = function () {
			   if (oXMLciu.readyState == 4) {
				   //alert("recibido "+'../xml/ciudades.php?id_provincia='+provincia_inmueble.value+'&id_oficina='+oficina);
				  // Accedemos al XML recibido
				  var xml  = oXMLciu.responseXML.documentElement;
				  // Accedemos al DIV
				 document.busqueda.ciudad_inmueble.length=0;
				document.busqueda.ciudad_inmueble.options[0] = new Option("----",'');
				if(xml.getElementsByTagName('ciudad').length>0){
					 for (i = 0; i < xml.getElementsByTagName('ciudad').length; i++){
						// Accedemos al objeto XML usuario
						var item = xml.getElementsByTagName('ciudad')[i];
						// Recojemos el id
						var id = item.getElementsByTagName('id')[0].firstChild.data;
						// Recojemos el nombre
						var nombre = item.getElementsByTagName('nombre')[0].firstChild.data;
						// Mostramos el enlace
						document.busqueda.ciudad_inmueble.options[i+1] = new Option(nombre,id); 
					  }
				 }else{
					  document.busqueda.ciudad_inmueble.length=0;
					  //document.busqueda.tipo_inmueble.options[0] = new Option("----",0);
				 }
				 
				}
				
		  };
		  oXMLciu.send('');
	 }
    // Comprobamos que se han recibido los datos
  }
  
  function cargarZonas(ciudad_inmueble){
	 if(ciudad_inmueble.length>0){
		 //alert(ciudad_inmueble.value);
		  oXMLzon = AJAXCrearObjeto();
		  oXMLzon.open('get', '../xml/distritos.php?id_ciudad='+ciudad_inmueble.value+'&id_oficina='+oficina);
		  oXMLzon.onreadystatechange = function () {
			   if (oXMLzon.readyState == 4) {
				   //alert("recibido "+'../xml/ciudades.php?id_provincia='+provincia_inmueble.value+'&id_oficina='+oficina);
				  // Accedemos al XML recibido
				  var xml  = oXMLzon.responseXML.documentElement;
				  // Accedemos al DIV
				  document.busqueda.zona_inmueble.length=0;
				  document.busqueda.zona_inmueble.options[0] = new Option("----",'');
				 if(xml.getElementsByTagName('distrito').length>0){
					 for (i = 0; i < xml.getElementsByTagName('distrito').length; i++){
						// Accedemos al objeto XML usuario
						var item = xml.getElementsByTagName('distrito')[i];
						// Recojemos el id
						var id = item.getElementsByTagName('id')[0].firstChild.data;
						// Recojemos el nombre
						var nombre = item.getElementsByTagName('nombre')[0].firstChild.data;
						// Mostramos el enlace
						document.busqueda.zona_inmueble.options[i+1] = new Option(nombre,id); 
					  }
				 }else{
					  document.busqueda.zona_inmueble.length=0;
					  //document.busqueda.tipo_inmueble.options[0] = new Option("----",0);
				 }
				 
				}
				
		  };
		  oXMLzon.send('');
	 }
    // Comprobamos que se han recibido los datos
  } 
  
  function cargarZonasAvanzadas(ciudad_inmueble){
	 if(ciudad_inmueble.length>0){
		 	//alert(grupo_inmueble.value);
		  for(k = 0; k <ciudad_inmueble.length; k++){
			  //alert(ciudad_inmueble.options[k].value);
			  oXMLzon = AJAXCrearObjeto();
			  oXMLzon.open('get', '../xml/distritos.php?id_ciudad='+ciudad_inmueble.options[k].value+'&id_oficina='+oficina);
			  oXMLzon.onreadystatechange = function () {
				   if (oXMLzon.readyState == 4) {
					   //alert("recibido "+'../xml/ciudades.php?id_provincia='+provincia_inmueble.value+'&id_oficina='+oficina);
					  // Accedemos al XML recibido
					  var xml  = oXMLzon.responseXML.documentElement;
					  // Accedemos al DIV
					 // document.busqueda.zona_inmueble.options[0] = new Option("----",'');
					 if(xml.getElementsByTagName('distrito').length>0){
						 for (i = 0; i < xml.getElementsByTagName('distrito').length; i++){
							// Accedemos al objeto XML usuario
							var item = xml.getElementsByTagName('distrito')[i];
							// Recojemos el id
							var id = item.getElementsByTagName('id')[0].firstChild.data;
							// Recojemos el nombre
							var nombre = item.getElementsByTagName('nombre')[0].firstChild.data;
							// Mostramos el enlace
							document.busqueda.zona_inmueble.options[i+1] = new Option(nombre,id); 
						  }
					 }else{
						  document.busqueda.zona_inmueble.length=0;
						  //document.busqueda.tipo_inmueble.options[0] = new Option("----",0);
					 }
					 
					}
					
			  };
			  oXMLzon.send('');
		  }
	 }
    // Comprobamos que se han recibido los datos
  }  
  
  function cargarInmueblesAleatorio(){
	  	  var id_array=new Array();
		  var numero_inmuebles=0;
		  oXMLalea = AJAXCrearObjeto();
		  oXMLalea.open('get', '../xml/inmuebles_aleatorios.php?modo=comprar&id_oficina='+oficina+'&maximo=6');
		  oXMLalea.onreadystatechange = function () {
		   if (oXMLalea.readyState == 4 ) {
			   //alert("recibido "+'../xml/ciudades.php?id_provincia='+provincia_inmueble.value+'&id_oficina='+oficina);
			  // Accedemos al XML recibido
			  var xmlInmo  = oXMLalea.responseXML.documentElement;
			  // Accedemos al DIV
			if(xmlInmo.getElementsByTagName('inmueble').length>0){
				 for (i = 0; i < xmlInmo.getElementsByTagName('inmueble').length; i++){
					// Accedemos al objeto XML usuario
					var item = xmlInmo.getElementsByTagName('inmueble')[i];
					// Recojemos el id
					var idinmueble = item.getElementsByTagName('id_inmueble')[0].firstChild.data;
					if(item.getElementsByTagName('ciudad')[0].firstChild){
						var ciudad = item.getElementsByTagName('ciudad')[0].firstChild.data;
					}else{
						var ciudad = '';
					}
					if(item.getElementsByTagName('clase')[0].firstChild){
						var clase = item.getElementsByTagName('clase')[0].firstChild.data;
					}else{
						var clase = '';
					}
					if(item.getElementsByTagName('tipo')[0].firstChild){
						var tipo = item.getElementsByTagName('tipo')[0].firstChild.data;
					}else{
						var tipo = '';
					}
					if(item.getElementsByTagName('precio')[0].firstChild){
						var precio = item.getElementsByTagName('precio')[0].firstChild.data;
					}else{
						var precio = '';
					}
					
					if(item.getElementsByTagName('superficie')[0].firstChild){
						var superficie = item.getElementsByTagName('superficie')[0].firstChild.data;
					}else{
						var precio = '';
					}
					var referencia = item.getElementsByTagName('referencia')[0].firstChild.data;
					if(clase=='Vivienda'){
						var banyos = item.getElementsByTagName('banyos')[0].firstChild.data;
						var aseos = item.getElementsByTagName('aseos')[0].firstChild.data;
						var habitaciones = item.getElementsByTagName('habitaciones')[0].firstChild.data;
						if(banyos.length>0){
							retretes=banyos+" ba&ntilde;os";	
							if(aseos.length>0){
								retretes+=" y "+aseos+" aseos";
							}
						}else if(aseos.length>0){
							retretes=aseos+" aseos";
						}
					}else{
						retretes='';
						habitaciones='';
					}
					
					//alert(idinmueble);
					// Mostramos el enlace
					document.getElementById('destacado_'+i).innerHTML='<table width="92%" border="0" align="center" cellpadding="0" cellspacing="2"><tr><td colspan="2" align="center"><a href="#" onclick="Vernoticias(\'../ficha_inmueble2_xml.php?id_inmueble='+idinmueble+'\',\'scrollbars=yes,resizable=no,width=650,height=500\');return false;"><img border="0" src="../../funciones/imagen_inmueble.php?id='+idinmueble+'&num=1&ancho=150&cortar=si&alto_corte=100"></a></td></tr><tr><td width="50%" class="texto_nomral" align="center" bgcolor="#F8F8FC">'+ciudad+'</td><td width="50%" class="texto_nomral" bgcolor="#F8F8FC" align="center" >'+tipo+'</td></tr><tr><td class="texto_nomral" bgcolor="#F8F8FC" align="center" >'+habitaciones+' Hab.</td><td class="texto_nomral" bgcolor="#F8F8FC" align="center" >'+superficie+' m<sup>2</sup></td></tr><tr><td class="texto_nomral" bgcolor="#F8F8FC" align="center" >'+referencia+'</td><td class="texto_nomral" bgcolor="#F8F8FC" align="center">'+retretes+'</td></tr><tr><td colspan="2" class="texto_nomral" bgcolor="#F8F8FC" align="center">'+precio+' &euro;</td></tr></table>';
					
				 }
			 }else{
				 // document.busqueda.ciudad_inmueble.length=0;
				  //document.busqueda.tipo_inmueble.options[0] = new Option("----",0);
				 // alert("no hay");
			 }
			 
		  }
			
	  };
	  oXMLalea.send('');
		//alert(numero_inmuebles);
  }
  
  function cargarDatosOficina(){
		  oXMLofi = AJAXCrearObjeto();
		  oXMLofi.open('get', '../xml/datos_oficina.php?id_oficina='+oficina);
		  oXMLofi.onreadystatechange = function () {
			   if (oXMLofi.readyState == 4) {
				  // Accedemos al XML recibido
				  var xml  = oXMLofi.responseXML.documentElement;
				 //alert(xml.getElementsByTagName('oficina').firstChild);
				if(xml.getElementsByTagName('oficina').length>0){
						// Accedemos al objeto XML usuario
						var item = xml.getElementsByTagName('oficina')[0];
						// Recojemos el id
						var nombre = item.getElementsByTagName('nombre')[0].firstChild.data;
						var cif = item.getElementsByTagName('cif')[0].firstChild.data;
						var domicilio = item.getElementsByTagName('domicilio')[0].firstChild.data;
						var provincia = item.getElementsByTagName('provincia')[0].firstChild.data;
						var ciudad = item.getElementsByTagName('ciudad')[0].firstChild.data;
						// Mostramos el enlace
						document.getElementById('datos_oficina').innerHTML=nombre+' C.I.F. '+cif+'<br>'+domicilio+' '+ciudad+' ('+provincia+')';
					 //alert(nombre);
					  //numero=aleatorio(0,i);
					 // alert(id_array[numero]);
				}else{
					 // document.busqueda.ciudad_inmueble.length=0;
					  //document.busqueda.tipo_inmueble.options[0] = new Option("----",0);
				 }
				 
				}
				
		  };
		  oXMLofi.send('');
  }
  
  function aleatorio(inferior,superior){
    numPosibilidades = superior - inferior
    aleat = Math.random() * numPosibilidades
    aleat = Math.round(aleat)
    return parseInt(inferior) + aleat
  }
  
  
  function cargarPromociones(){
	  	  var id_array=new Array();
		  oXMLpromos = AJAXCrearObjeto();
		  oXMLpromos.open('get', '../xml/promociones.php?id_oficina='+oficina);
		  oXMLpromos.onreadystatechange = function () {
			   if (oXMLpromos.readyState == 4) {
				   //alert("recibido "+'../xml/ciudades.php?id_provincia='+provincia_inmueble.value+'&id_oficina='+oficina);
				  // Accedemos al XML recibido
				  var xml  = oXMLpromos.responseXML.documentElement;
				  // Accedemos al DIV
				if(xml.getElementsByTagName('promocion').length>0){
					 for (i = 0; i < xml.getElementsByTagName('promocion').length; i++){
						// Accedemos al objeto XML usuario
						var item = xml.getElementsByTagName('promocion')[i];
						// Recojemos el id
						var id = item.getElementsByTagName('id')[0].firstChild.data;
						// Mostramos el enlace
						id_array[i] = id; 
					  }
					  //numero=aleatorio(0,i);
					 return id_array;
				 }else{
					 // document.busqueda.ciudad_inmueble.length=0;
					  //document.busqueda.tipo_inmueble.options[0] = new Option("----",0);
				 }
				 
				}
				
		  };
		  oXMLpromos.send('');
  }
  
  function mostrarPromocion(){
		  oXMLpromo = AJAXCrearObjeto();
		  oXMLpromo.open('get', '../xml/todas_promociones.php?id_oficina='+oficina);
		  oXMLpromo.onreadystatechange = function () {
			   if (oXMLpromo.readyState == 4) {
				   //alert("recibido "+'../xml/ciudades.php?id_provincia='+provincia_inmueble.value+'&id_oficina='+oficina);
				  // Accedemos al XML recibido
				  var xmlpromo  = oXMLpromo.responseXML.documentElement;
				  // Accedemos al DIV
				if(xmlpromo.getElementsByTagName('promocion').length>0){
					 for (i = 0; i < xmlpromo.getElementsByTagName('promocion').length; i++){
						// Accedemos al objeto XML usuario
						var item = xmlpromo.getElementsByTagName('promocion')[i];
						// Recojemos el id
						var idpromo = item.getElementsByTagName('id')[0].firstChild.data;
						var ciudad = item.getElementsByTagName('ciudad')[0].firstChild.data;
						var detalles = item.getElementsByTagName('detalles')[0].firstChild.data;
						// Mostramos el enlace
						document.getElementById('lista_promociones').innerHTML+="<table width='98%' border='0' align='center' cellpadding='0' cellspacing='0'><tr><td class='texto_nomral' align='center'>"+ciudad+"</td></tr><tr><td class='texto_nomral' align='center'><a href='#' onClick=\"Vernoticias('../ficha_promocion_xml.php?id_inmueble="+idpromo+"&buscador=no','scrollbars=yes,resizable=no,width=750,height=500');return false;\"><img src='../../funciones/imagen_logo_promocion2.php?codpromo="+idpromo+"&ancho=100' border='0'></a></td></tr><tr><td class='texto_nomral' align='center'>"+detalles+"</td></tr></table><br>";
					 }
				 }else{
					 // document.busqueda.ciudad_inmueble.length=0;
					  //document.busqueda.tipo_inmueble.options[0] = new Option("----",0);
					 // alert("no hay");
				 }
				 
				}
				
		  };
		  oXMLpromo.send('');
  }
  
  function mostrarDestacado(){
		  oXMLdest = AJAXCrearObjeto();
		  oXMLdest.open('get', '../xml/destacados.php?id_oficina='+oficina);
		  oXMLdest.onreadystatechange = function () {
			   if (oXMLdest.readyState == 4) {
				var xmldes  = oXMLdest.responseXML.documentElement;
				if(xmldes.getElementsByTagName('inmueble').length>0){
					 for (i = 0; i < xmldes.getElementsByTagName('inmueble').length; i++){
						// Accedemos al objeto XML usuario
						var item = xmldes.getElementsByTagName('inmueble')[i];
						// Recojemos el id
						var idinmueble = item.getElementsByTagName('id_inmueble')[0].firstChild.data;
						var ciudad = item.getElementsByTagName('ciudad')[0].firstChild.data;
						var tipo = item.getElementsByTagName('tipo')[0].firstChild.data;
						var precio = item.getElementsByTagName('precio')[0].firstChild.data;
						// Mostramos el enlace
						document.getElementById('destacados_oficina').innerHTML+="<table width='98%' border='0' align='center' cellpadding='0' cellspacing='0'><tr><td class='texto_nomral' align='center'>"+ciudad+"</td></tr><tr><td class='texto_nomral' align='center'><a href='#' onclick=\"Vernoticias('../ficha_inmueble2_xml.php?id_inmueble="+idinmueble+"','scrollbars=yes,resizable=no,width=650,height=500');return false;\"><img border='0' src='../../funciones/imagen_inmueble.php?id="+idinmueble+"&num=1&ancho=100'></a></td></tr><tr><td class='texto_nomral' align='center'>"+tipo+"</td></tr><tr><td class='texto_nomral' align='center'>"+precio+" &euro;<br><img src='img/linea_separador.png'></td></tr></table><br>";
					 }
				 }else{
					 // document.busqueda.ciudad_inmueble.length=0;
					  //document.busqueda.tipo_inmueble.options[0] = new Option("----",0);
					 // alert("no hay");
				 }
				 
				}
				
		  };
		  oXMLdest.send('');
  }
  
  function cargarDondeEstamos(){
		  oXMLdndes = AJAXCrearObjeto();
		  oXMLdndes.open('get', '../xml/datos_oficina.php?id_oficina='+oficina);
		  oXMLdndes.onreadystatechange = function () {
			   if (oXMLdndes.readyState == 4) {
				  // Accedemos al XML recibido
				  var xml  = oXMLdndes.responseXML.documentElement;
				 //alert(xml.getElementsByTagName('oficina').firstChild);
				if(xml.getElementsByTagName('oficina').length>0){
						// Accedemos al objeto XML usuario
						var item = xml.getElementsByTagName('oficina')[0];
						// Recojemos el id
						var nombre = item.getElementsByTagName('nombre')[0].firstChild.data;
						var cif = item.getElementsByTagName('cif')[0].firstChild.data;
						var domicilio = item.getElementsByTagName('domicilio')[0].firstChild.data;
						var provincia = item.getElementsByTagName('provincia')[0].firstChild.data;
						var ciudad = item.getElementsByTagName('ciudad')[0].firstChild.data;
						var telefono = item.getElementsByTagName('telefono')[0].firstChild.data;
						var fax = item.getElementsByTagName('fax')[0].firstChild.data;
						var codigo_postal = item.getElementsByTagName('codigo_postal')[0].firstChild.data;
						var email = item.getElementsByTagName('email')[0].firstChild.data;
						var foto = item.getElementsByTagName('foto')[0].firstChild.data;
						// Mostramos el enlace
						document.getElementById('donde_estamos_texto').innerHTML=nombre+'<br>'+domicilio+'<br>Tel&eacute;fono '+telefono+' Fax '+fax+'<br>'+codigo_postal+''+ciudad+' ('+provincia+')';
						document.getElementById('donde_estamos_email').innerHTML=email;
						document.getElementById('donde_estamos_foto').innerHTML='<img src="../../funciones/foto_oficina.php?id_oficina='+oficina+'&ancho=70&alto=50&cortar=si&alto_corte=50">';
						
						
				}else{
					 // document.busqueda.ciudad_inmueble.length=0;
					  //document.busqueda.tipo_inmueble.options[0] = new Option("----",0);
				 }
				 
				}
				
		  };
		  oXMLdndes.send('');
  }
  
  function buscador(){
		 
	document.getElementById('Layer1').style.visibility='visible';
	document.getElementById('resultados_busqueda').innerHTML='<iframe height="460" name="layer_buscador" width="100%" frameborder="0" allowtransparency="yes" scrolling="no"></iframe>';
  	document.getElementById('busqueda').submit();
  }
  
  function buscadorAvanzado(){
	
	if(document.getElementById('grupo_inmueble').value!=0){
		document.getElementById('Layer1').style.visibility='visible';
		document.getElementById('provincia_inmueble').style.visibility='hidden';
		document.getElementById('ciudad_inmueble').style.visibility='hidden';
		document.getElementById('ciudades').style.visibility='hidden';
		document.getElementById('zona_inmueble').style.visibility='hidden';
		document.getElementById('barrios').style.visibility='hidden';
		document.getElementById('resultados_busqueda').innerHTML='<iframe height="460" name="layer_buscador" width="100%" frameborder="0" allowtransparency="yes" scrolling="no"></iframe>';
		document.getElementById('busqueda').submit();
	}else{
		alert('Debe al menos seleccionar la clase de inmueble.');
	}
  }
  
  function cerrarBuscador(){
	  document.getElementById('Layer1').style.visibility='hidden';
  }
  
  function cerrarBuscadorAvanzado(){
		document.getElementById('provincia_inmueble').style.visibility='visible';
		document.getElementById('ciudad_inmueble').style.visibility='visible';
		document.getElementById('ciudades').style.visibility='visible';
		document.getElementById('zona_inmueble').style.visibility='visible';
		document.getElementById('barrios').style.visibility='visible';
	  document.getElementById('Layer1').style.visibility='hidden';
  }
  
  function cargarQuienesSomos(){
		  oXMLquien = AJAXCrearObjeto();
		  oXMLquien.open('get', '../xml/datos_oficina.php?id_oficina='+oficina);
		  oXMLquien.onreadystatechange = function () {
			   if (oXMLquien.readyState == 4) {
				  // Accedemos al XML recibido
				  var xml  = oXMLquien.responseXML.documentElement;
				 //alert(xml.getElementsByTagName('oficina').firstChild);
				if(xml.getElementsByTagName('oficina').length>0){
						// Accedemos al objeto XML usuario
						var item = xml.getElementsByTagName('oficina')[0];
						// Recojemos el id
						var texto_quienes_somos = item.getElementsByTagName('texto_quienes_somos')[0].firstChild.data;
						var cif = item.getElementsByTagName('cif')[0].firstChild.data;
						// Mostramos el enlace
						document.getElementById('quienes_somos_texto').innerHTML=texto_quienes_somos;
						document.getElementById('quienes_somos_foto').innerHTML='<img src="../../funciones/foto_quienes_somos.php?id_oficina='+oficina+'&ancho=200">';
						
					 //alert(nombre);
					  //numero=aleatorio(0,i);
					 // alert(id_array[numero]);
				}else{
					 // document.busqueda.ciudad_inmueble.length=0;
					  //document.busqueda.tipo_inmueble.options[0] = new Option("----",0);
				 }
				 
				}
				
		  };
		  oXMLquien.send('');
  }
  
  function contactarOficina(){
	  oXMLcontac = AJAXCrearObjeto();
	  oXMLcontac.open('post', '../xml/contactar_oficina.php');
	  oXMLcontac.onreadystatechange = function () {
		   if (oXMLcontac.readyState == 4) {
			  // Accedemos al XML recibido
			  var xml  = oXMLcontac.responseXML.documentElement;
			 //alert(xml.getElementsByTagName('oficina').firstChild);
			if(xml.getElementsByTagName('oficina').length>0){
					// Accedemos al objeto XML usuario
					var item = xml.getElementsByTagName('oficina')[0];
					// Recojemos el id
					var estado = item.getElementsByTagName('estado')[0].firstChild.data;
					var descripcion = item.getElementsByTagName('descripcion')[0].firstChild.data;
					//alert(id);
					alert(descripcion);

			}else{
				 // document.busqueda.ciudad_inmueble.length=0;
				  //document.busqueda.tipo_inmueble.options[0] = new Option("----",0);
			 }
			 
			}
			
	  };
	  oXMLcontac.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	  var valores='id_oficina='+oficina+'&nombre='+document.getElementById('nombre').value+'&apellidos='+document.getElementById('apellidos').value+'&telefono='+document.getElementById('telefono').value+'&email='+document.getElementById('email').value+'&conociste='+document.getElementById('conociste').value+'&observaciones='+document.getElementById('observaciones').value;
	  oXMLcontac.send(valores);
  }
  
   function recomendarOficina(){
	  oXMLrecom = AJAXCrearObjeto();
	  oXMLrecom.open('post', '../xml/recomendar_oficina.php');
	  oXMLrecom.onreadystatechange = function () {
		   if (oXMLrecom.readyState == 4) {
			  // Accedemos al XML recibido
			  var xml  = oXMLrecom.responseXML.documentElement;
			 //alert(xml.getElementsByTagName('oficina').firstChild);
			if(xml.getElementsByTagName('oficina').length>0){
					// Accedemos al objeto XML usuario
					var item = xml.getElementsByTagName('oficina')[0];
					// Recojemos el id
					var estado = item.getElementsByTagName('estado')[0].firstChild.data;
					var descripcion = item.getElementsByTagName('descripcion')[0].firstChild.data;
					//alert(id);
					alert(descripcion);

			}else{
				 // document.busqueda.ciudad_inmueble.length=0;
				  //document.busqueda.tipo_inmueble.options[0] = new Option("----",0);
			 }
			 
			}
			
	  };
	  oXMLrecom.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	  var valores='id_oficina='+oficina+'&tu_nombre='+document.getElementById('tu_nombre').value+'&tu_email='+document.getElementById('tu_email').value+'&nombre_amigo='+document.getElementById('nombre_amigo').value+'&email_amigo='+document.getElementById('email_amigo').value+'&observaciones='+document.getElementById('observaciones').value;
	  oXMLrecom.send(valores);
  }
  
  
  function copyToList(formulario,from,to){
	  
	  fromList = eval('document.'+formulario+'.' + from);
	  toList = eval('document.'+formulario+'.' + to);
	  if (toList.options.length > 0 && toList.options[0].value == 'temp'){
		toList.options.length = 0;
	  }
	  
	  var sel = false;
	  for (i=0;i<fromList.options.length;i++){
		var current = fromList.options[i];
		if (current.selected){
		  sel = true;
		  if (current.value == 'temp')
		  {
			alert ('No puedes mover este texto!');
			return;
		  }
		  txt = current.text;
		  val = current.value;
		  toList.options[toList.length] = new Option(txt,val,true,true);
		  fromList.options[i] = null;
		  i--;
		}
	  }
	  
	  if(!sel){
		 alert('¡No has seleccionado ninguna opci&oacute;n!'); 
	   }
	  
  }
  
  
  function prueba(){
	  document.busqueda.grupo_inmueble.options[0] = new Option("algo",2); 
  }