function createRequestObject() {
		var ro;
		var browser = navigator.appName;

		if(browser == "Microsoft Internet Explorer"){
			ro = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else{
			ro = new XMLHttpRequest();
		}
		return ro;
	}  


	function getParametros(formu) {
		var parametros = "";
		for(var i=0;i<formu.length;i++) {
			if(formu.elements[i].type == "button" || formu.elements[i].type == "reset" || formu.elements[i].type == "submit") continue;
			
			if(parametros != "") {
				if (formu.elements[i].type == "radio" || formu.elements[i].type == "checkbox") {
					if (formu.elements[i].checked) {
						parametros += "&" + formu.elements[i].name + "=" + formu.elements[i].value;	
					}
				}
				else {
					parametros += "&" + formu.elements[i].name + "=" + encodeURIComponent(formu.elements[i].value);
				}
			}
			else {
				if (formu.elements[i].type == "radio" || formu.elements[i].type == "checkbox") {
					if (formu.elements[i].checked) {
						parametros += formu.elements[i].name + "=" + formu.elements[i].value;	
					}
				}
				else {
					parametros += formu.elements[i].name + "=" + encodeURIComponent(formu.elements[i].value);
				}
			}
		}	
		return parametros;
	}

	function selTipoInmueble(frm) {
		var seleccionado = frm.sel_tipos.value;
		if(seleccionado != 9 && seleccionado != 13 && seleccionado != 12) {
			document.getElementById('div_campos_tipoinmueble_2').style.display = 'none';
			document.getElementById('div_campos_tipoinmueble_3').style.display = 'none';
			document.getElementById('div_campos_tipoinmueble_1').style.display = 'block';
			return;
		}
		if(seleccionado == 9) {
			document.getElementById('div_campos_tipoinmueble_1').style.display = 'none';
			document.getElementById('div_campos_tipoinmueble_3').style.display = 'none';
			document.getElementById('div_campos_tipoinmueble_2').style.display = 'block';
			return;
		}
		if(seleccionado == 12 || seleccionado == 13) {
			document.getElementById('div_campos_tipoinmueble_1').style.display = 'none';
			document.getElementById('div_campos_tipoinmueble_2').style.display = 'none';
			document.getElementById('div_campos_tipoinmueble_3').style.display = 'block';
			return;
		}
	}


	function registro() {
		var frm = document.frmRegistro;
		frm.accion.value = 'alta-usuario';

		var httpPost = createRequestObject();
		httpPost.open("post", "/acciones-bbdd.php", true);
		httpPost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpPost.onreadystatechange = function () {
			if(httpPost.readyState == 4){
				if (httpPost.responseText) {
						var resp = httpPost.responseText;
						//alert(resp);
						if(resp.indexOf("###") != -1) {
							var arr = resp.split("###");
							document.getElementById('div_aux').style.display = 'block';
							document.getElementById('div_aux').innerHTML = arr[0];
							if(arr[1] != '') {
								eval("var element = document.getElementById('" + arr[1] + "');");
								if(element) {
									frm.elements[arr[1]].focus();
								}
							}
						} else {
							document.getElementById('formulario-registro').style.display = 'none';
							document.getElementById('formulario-registro-OK').style.display = 'block';
						}
				}
			}
		};
		httpPost.send(getParametros(frm));

	}

	function registroMod() {
		var frm = document.frmRegistro;
		frm.accion.value = 'modificacion-usuario';

		var httpPost = createRequestObject();
		httpPost.open("post", "/acciones-bbdd.php", true);
		httpPost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpPost.onreadystatechange = function () {
			if(httpPost.readyState == 4){
				if (httpPost.responseText) {
						var resp = httpPost.responseText;
						//alert(resp);
						if(resp.indexOf("###") != -1) {
							var arr = resp.split("###");
							document.getElementById('div_aux').style.display = 'block';
							document.getElementById('div_aux').innerHTML = arr[0];
							if(arr[1] != '') {
								eval("var element = document.getElementById('" + arr[1] + "');");
								if(element) {
									frm.elements[arr[1]].focus();
								}
							}
						} else {
							document.getElementById('formulario-registro').style.display = 'none';
							document.getElementById('formulario-registro-OK').style.display = 'block';
						}
				}
			}
		};
		httpPost.send(getParametros(frm));

	}

	function confirmar() {
		var frm = document.frmConfirmacion;
		
		if(frm.fecha_alta.value == '' || frm.clave_confirmacion.value == '') {
			alert();
			return;
		}
		frm.accion.value = 'confirmar-alta-usuario';

		var httpPost = createRequestObject();
		httpPost.open("post", "/acciones-bbdd.php", true);
		httpPost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpPost.onreadystatechange = function () {
			if(httpPost.readyState == 4){
				if (httpPost.responseText) {
						return;
				}
			}
		};
		httpPost.send(getParametros(frm));

	}

	function login() {
		var frm = document.frmLogin;
		frm.accion.value = 'validar-usuario';
		var url = document.location.href;

		var httpPost = createRequestObject();
		httpPost.open("post", "/acciones-bbdd.php", true);
		httpPost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpPost.onreadystatechange = function () {
			if(httpPost.readyState == 4){
				if (httpPost.responseText) {
						var resp = httpPost.responseText;
						//alert(resp);
						if(resp.indexOf("###") != -1) {
							var arr = resp.split("###");
							document.getElementById('div_aux').style.display = 'block';
							document.getElementById('div_aux').innerHTML = arr[0];
							if(arr[1] != '') {
								eval("var element = document.getElementById('" + arr[1] + "');");
								if(element) {
									frm.elements[arr[1]].focus();
								}
							}
						} else {
							//alert(url);
							if(url.indexOf("login?datos") != -1) {
								document.location.href = '/registro/datos';
							} else if(url.indexOf("login?anuncios") != -1) {
								document.location.href ='/registro/anuncios';
							} else {
								document.location.href ='/registro/login';
							}
						}
				}
			}
		};
		httpPost.send(getParametros(frm));
	}

	function modificarAnuncio(id_anuncio) {
		var frm = document.frmAnuncio;
		frm.accion.value = "modificar-anuncio";
		frm.id_anuncio.value = id_anuncio;
		frm.action = "/registro/anuncios";
		frm.submit();
	}

	function nuevoAnuncio() {
		document.location.href = "/registro/nuevo-anuncio";
	}

	function selProvincia() {
		var frm = document.frmAnuncio;
		if(frm.sel_provincia.value == '') return;
		var http = createRequestObject();
		http.open("get", "/acciones-bbdd.php?accion=obtener-municipios&id_provincia=" + frm.sel_provincia.value + "&r=" + Math.random());
		http.onreadystatechange = function () {
			if(http.readyState == 4){
				if (http.responseText) {
						var resp = http.responseText;
						document.getElementById('div_municipios').innerHTML = resp;
						
				}
			}
		};
		http.send(null);
	}

	function selProvinciaBuscador() {
		var frm = document.frmBuscadorMapa;
		if(frm.sel_provincia.value == '') return;
		var datos_provincia = frm.sel_provincia.value;
		var arr = datos_provincia.split("###");
		var id_provincia = arr[0];
		var http = createRequestObject();
		http.open("get", "/acciones-bbdd.php?accion=obtener-municipios&id_provincia=" + id_provincia + "&buscador=1&r=" + Math.random());
		http.onreadystatechange = function () {
			if(http.readyState == 4){
				if (http.responseText) {
						var resp = http.responseText;
						document.getElementById('div_municipios').innerHTML = resp;
						
				}
			}
		};
		http.send(null);
	}

	function selProvinciaTexto() {
		var frm = document.frmBuscadorTexto;
		if(!frm) {
			var frm = document.frmBuscadorRefina;
		}
		if(!frm) {
			var frm = document.frmDemandas;
		}
		if(!frm) {
			var frm = document.frmNewsletter;
		}

		if(frm.sel_provincia.value == '') return;
		var datos_provincia = frm.sel_provincia.value;
		var arr = datos_provincia.split("###");
		var id_provincia = arr[0];
		var http = createRequestObject();
		http.open("get", "/acciones-bbdd.php?accion=obtener-municipios&id_provincia=" + id_provincia + "&buscador=2&r=" + Math.random());
		http.onreadystatechange = function () {
			if(http.readyState == 4){
				if (http.responseText) {
						var resp = http.responseText;
						//alert(resp);
						document.getElementById('div_municipios_buscador_texto').innerHTML = resp;
						
				}
			}
		};
		http.send(null);
	}

	function selProv(id_provincia) {
		
		if(id_provincia == '') return;
		var frm = document.frmAnuncio;
		if(!frm) {
			var frm = document.frmBuscadorRefina;
		}
		if(!frm) {
			var frm = document.frmDemandas;
		}
		if(!frm) {
			var frm = document.frmNewsletter;
		}
		var valor = '';		
		for(var i=0; i<frm.sel_provincia.options.length; i++) {
			valor = frm.sel_provincia.options[i].value;
				
			if(frm.sel_provincia.options[i].value == id_provincia || valor.indexOf(id_provincia + '###') != -1) {
				frm.sel_provincia.selectedIndex = i;
				break;
			}
		}
	}
	function selMun(id_municipio) {
		if(id_municipio == '') return;
		var frm = document.frmAnuncio;
		if(!frm) {
			var frm = document.frmBuscadorRefina;
		}
		if(!frm) {
			var frm = document.frmDemandas;
		}
		if(!frm) {
			var frm = document.frmNewsletter;
		}

		var valor = '';
		
		for(var i=0; i<frm.sel_municipio.options.length; i++) {
			valor = frm.sel_municipio.options[i].value;

			if(frm.sel_municipio.options[i].value == id_municipio  || valor.indexOf(id_municipio + '###') != -1) {
				frm.sel_municipio.selectedIndex = i;
				break;
			}
		}
	}

	function calculaOferta() {
		var frm = document.frmAnuncio;
		if(frm.txtvaloracion.value == '' || isNaN(frm.txtvaloracion.value)) {
			alert("Rellena la valoración de la propiedad con un valor numérico");	
			return;
		}
		var valor = frm.txtvaloracion.value;
		valor = valor.replace('.', '');
		valor = valor.replace(',', '');
		frm.txtvaloracion.value = valor;
		var porc = frm.sel_oferta.value;
		valor = frm.txtvaloracion.value*porc;
		valor = valor/100;
		frm.txtoferta_minima.value = valor;
	}

	function subidaFoto() {
		var frm = document.frmFotoAnuncio;
		if(checkForm(frm)) {
			document.getElementById("div_subiendo").innerHTML = "Subiendo la foto. Espera unos segundos...";
			setTimeout("verSubiendo()", 1000);
			frm.action = '/foto-anuncio.php?id_anuncio=' + frm.id_anuncio.value + '&accion=subir-foto&cont_foto=' + frm.cont_foto.value;
			frm.submit();
		}
	}

	function verSubiendo() {
		setTimeout("verSubiendo()", 1000);
		document.getElementById("div_subiendo").innerHTML = document.getElementById("div_subiendo").innerHTML != "" ? "" : "Subiendo la foto. Espera unos segundos...";
	}

	function eliminarFoto(id_anuncio, id_foto) {
		if(confirm("¿Seguro que quieres eliminar esta foto del anuncio?")) {
			var frm = document.frmFotoAnuncio;
			frm.target = "ifr_foto";
			frm.action = "/foto-anuncio.php?id_anuncio="+id_anuncio+"&id_foto=" + id_foto + "&accion=eliminar-foto";
			frm.submit();

			
		}
	}

	function getFotosAnuncio() {
		var frm = window.document.frmAnuncio;

		var http = createRequestObject();
		http.open("get", "/fotos-anuncio.php?r=" + Math.random());
		http.onreadystatechange = function () {
			if(http.readyState == 4){
				if (http.responseText) {
						var resp = http.responseText;
						window.top.document.getElementById('div_fotos').innerHTML = resp;
				}
			}
		};
		http.send(null);
	} 

	function datosInmueble(id_anuncio) {
		//var frm = document.frmAnuncio;
		eval("var elem = document.getElementById('div_fotos');");
		if(elem) {
			var frm = window.top.document.forms['frmAnuncio'];
			//frm.target = 'parent';
		} else {
			var frm = document.frmAnuncio;
		}
		frm.id_anuncio.value = id_anuncio;
		frm.action = '/registro/anuncios';
		frm.submit();
	}

	function fotosInmueble(id_anuncio) {
		if(id_anuncio == '') {
			alert('Tienes que dar de alta el inmueble para poder subir sus fotos');
			return;
		}
		var frm = document.frmAnuncio;
		frm.id_anuncio.value = id_anuncio;
		frm.action = '/registro/anuncios?fotos';
		frm.submit();

	}

	function fotoPrincipal(id_foto, id_anuncio) {
		var http = createRequestObject();
		http.open("get", "/acciones-bbdd.php?accion=foto-principal&id_foto=" + id_foto + "&id_anuncio=" + id_anuncio + "&r=" + Math.random());
		/*
		http.onreadystatechange = function () {
			if(http.readyState == 4){
				alert(http.responseText);
			}
		};
		*/
		http.send(null);
	}

	function modAnuncio() {
		var frm = window.document.frmAnuncio;

		if(frm.sel_provincia.value == '') {
			alert("Selecciona una provincia");
			return;
		}

		if(frm.sel_municipio.value == '') {
			alert("Selecciona un municipio");
			return;
		}

		if(frm.sel_tipos.value == '') {
			alert("Selecciona un tipo de Inmueble");
			return;
		}
		if(frm.sel_tipos.value == 9) { // GARAJES
			frm.txtmetros_utiles.value = 0;
			frm.txtmetros_construidos.value = 0;
			frm.txtmetros_cuadrados2.value = 0;
		}
		if(frm.sel_tipos.value == 12 || frm.sel_tipos.value == 13) { // PARCELAS Y TERRENOS
			frm.txtmetros_utiles.value = 0;
			frm.txtmetros_construidos.value = 0;
			frm.txtmetros_cuadrados.value = 0;
		}

		if(checkForm(frm)) {
			if(frm.id_anuncio.value != '') {
				frm.accion.value = 'modificar-anuncio';
			} else {
				frm.accion.value = 'nuevo-anuncio';
			}

			var httpPost = createRequestObject();
			httpPost.open("post", "/acciones-bbdd.php", true);
			httpPost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			httpPost.onreadystatechange = function () {
				if(httpPost.readyState == 4){
					if (httpPost.responseText) {
							var resp = httpPost.responseText;
							//alert(resp);
							if(resp.indexOf('OK#') != -1) {
								if(frm.id_anuncio.value == '') {
									alert("Tu anuncio ha sido dado de alta correctamente. Ahora puedes insertar las fotografías del inmueble");
									//getFotosAnuncio();
									var arr = resp.split("#");
									frm.id_anuncio.value = arr[1];
									frm.txtoferta_minima.value = arr[2];
									frm.action = '/registro/anuncios?fotos';
									frm.submit();
								} else {
									alert("Los datos de tu anuncio se han modificado correctamente");
									var arr = resp.split("#");
									frm.txtoferta_minima.value = arr[1];
								}
							} else {
								if(frm.id_anuncio.value != '') {
									alert("Ha ocurrido un error al intentar modificar los datos de tu anuncio. Por favor, inténtalo más tarde");
								} else if(resp.indexOf('KOEXISTE#') != -1) {
									alert("No se ha dado de alta el anuncio porque ya tienes un anuncio publicado con los mismos datos.");
								} else {
									alert("Ha ocurrido un error al intentar dar de alta tu anuncio. Por favor, inténtalo más tarde");
								}
							}
							
					}
				}
			};
			httpPost.send(getParametros(frm));
		}
	}


	function eliminarAnuncio(id_anuncio) {
		if(!confirm("¿Seguro que quieres eliminar este anuncio?")) {
			return;
		}

		var frm = document.frmAnuncio;
		frm.id_anuncio.value = id_anuncio;
		frm.accion.value = 'eliminar-anuncio';
		var url = document.location.href;


		var httpPost = createRequestObject();
		httpPost.open("post", "/acciones-bbdd.php", true);
		httpPost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpPost.onreadystatechange = function () {
			if(httpPost.readyState == 4){
				if (httpPost.responseText) {
						var resp = httpPost.responseText;
						//alert(resp);
						if(resp.indexOf('OK#') != -1) {
							alert("Tu anuncio ha sido eliminado correctamente");
							document.location.href = url;
						} else {
							alert("Ha ocurrido un error al intentar eliminar el anuncio. Por favor, inténtalo más tarde");
						}
						
				}
			}
		};
		httpPost.send(getParametros(frm));
		
	}

	function enviarDemanda() {
		

		var frm = document.frmDemandas;
		if(checkForm(frm)) {
			
			frm.accion.value = 'enviar-demanda';
			var url = document.location.href;


			var httpPost = createRequestObject();
			httpPost.open("post", "/acciones-bbdd.php", true);
			httpPost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			httpPost.onreadystatechange = function () {
				if(httpPost.readyState == 4){
					if (httpPost.responseText) {
							var resp = httpPost.responseText;
							//alert(resp);
							if(resp.indexOf('OK') != -1) {
								alert("Hemos recibido correctamente tu demanda. En breve recibirás los anuncios que se ajusten a los criterios que nos has indicado.");
								document.location.href = url;
							} else {
								var arr = resp.split("###");
								if(arr[0]) {
									alert(arr[0]);
									if(arr[1] != '') {
										eval("var element = document.getElementById('" + arr[1] + "');");
										if(element) {
											frm.elements[arr[1]].focus();
										}
									}
								} else {
									alert("Ha ocurrido un error al intentar enviar tu demanda. Por favor, inténtalo más tarde");
								}
							}
							
					}
				}
			};
			httpPost.send(getParametros(frm));
		}
		
	}

	function enviarSuscripcionNewsletter() {
		

		var frm = document.frmNewsletter;
		if(checkForm(frm)) {
			
			frm.accion.value = 'enviar-suscripcion';
			var url = document.location.href;


			var httpPost = createRequestObject();
			httpPost.open("post", "/acciones-bbdd.php", true);
			httpPost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			httpPost.onreadystatechange = function () {
				if(httpPost.readyState == 4){
					if (httpPost.responseText) {
							var resp = httpPost.responseText;
							//alert(resp);
							if(resp.indexOf('OK') != -1) {
								alert("Hemos recibido correctamente tu suscripción. En breve recibirás en tu email los últimos anuncios publicados en SIO.");
								document.location.href = url;
							} else {
								var arr = resp.split("###");
								if(arr[0]) {
									//alert(arr[0]);
									if(arr[1] != '') {
										eval("var element = document.getElementById('" + arr[1] + "');");
										if(element) {
											frm.elements[arr[1]].focus();
										}
									}
								} else {
									alert("Ha ocurrido un error al intentar enviar tu suscripción. Por favor, inténtalo más tarde");
								}
							}
							
					}
				}
			};
			httpPost.send(getParametros(frm));
		}
		
	}



	var formatoFecha = 'dd/mm/yyyy';	// Formato de fecha que vamos a utilizar
  
  // Función de validación de email
  function emailValido(valor) {
	var EmailOk = true;
	var AtSym = valor.indexOf('@');
	var Period = valor.lastIndexOf('.');
	var Space = valor.indexOf(' ');
	var Length = valor.length - 1;
	if ((AtSym < 1) || (Period <= AtSym+1) || (Period == Length ) || (Space  != -1)) {  
		  EmailOk = false;
	}
	return EmailOk;
  }
  
  // Función de validación de fecha
  function fechaValida(valor) {
  	var formatoFechaReg = formatoFecha;
  	formatoFechaReg = formatoFechaReg.replace('dd','([0-2][0-9]|3[0-1])');
  	formatoFechaReg = formatoFechaReg.replace('mm','(0[0-9]|1[0-2])');
  	formatoFechaReg = formatoFechaReg.replace(/y/g,'[0-9]');
  	formatoFechaReg = "^" + formatoFechaReg + "$";
  	var ExpReg = new RegExp(formatoFechaReg);
  	var fechaOK = ExpReg.test(valor);
  	return fechaOK;
  }
  
  // Función de validación de fotos
  /*function fotoValida(valor) {
	var formatoFoto = "^(.*)(\\\\|/)[\\w:/_-]+\\.(jpeg|jpg|gif)$";
  	var ExpRegFoto = new RegExp(formatoFoto,"i");
  	var fotoOK = ExpRegFoto.test(valor);
  	return fotoOK;
  }*/

  function fotoValida(valor) {
	  if(valor.indexOf("€") > 0) {
			alert("El nombre de la foto no puede contener el caracter €");
			return;
	  }
	  if(valor.indexOf("$") > 0) {
			alert("El nombre de la foto no puede contener el caracter $");
			return;
	  }
	  if(valor.indexOf("ª") > 0) {
			alert("El nombre de la foto no puede contener el caracter ª");
			return;
	  }
	  if(valor.indexOf("º") > 0) {
			alert("El nombre de la foto no puede contener el caracter º");
			return;
	  }
	  valor = valor.replace("%20", "");
		var formatoFile = "[\\w-]+\\.*[gif|png|jpg|GIF|PNG|JPG]$";
		var ExpRegFile = new RegExp(formatoFile,"i");
		var fileOK = ExpRegFile.test(valor);
		return fileOK;
	}
  
  // Función de validación de fotos
  function precioValido(valor) {
	var formatoPrecio = "^[0-9]+(,[0-9]{1,2})?$";
  	var ExpRegPrecio = new RegExp(formatoPrecio,"i");
  	var precioOK = ExpRegPrecio.test(valor);
  	return precioOK;
  }
  
  function checkForm(frm) {
    for(i=0;i<frm.length;i++) {
    	campoForm = frm.elements[i];
		if(campoForm.disabled == false) {
			var datosCheck = campoForm.id.split('#');
			texto_explicativo = "";
			if(datosCheck[2])
				texto_explicativo = datosCheck[2];
			if(datosCheck[0].indexOf('*') != -1) {
				if(campoForm.value == "") {
					alert('No has rellenado el campo ' + datosCheck[1]);
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('numero') != -1) {
				if(isNaN(campoForm.value)) {
					alert('El campo ' + datosCheck[1] + ' tiene que ser numérico.' + texto_explicativo);
					campoForm.focus();
					return false;
				}
			}
			if((datosCheck[0].indexOf('email') != -1) && (campoForm.value != "")) {
				if(!emailValido(campoForm.value)) {
					alert('El campo ' + datosCheck[1] + ' tiene que ser un email');
					campoForm.focus();
					return false;
				}
			}
			if((datosCheck[0].indexOf('fecha') != -1) && (campoForm.value != "")) {
				if(!fechaValida(campoForm.value)) {
					alert('El formato del campo ' + datosCheck[1] + ' no es válido');
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('checkbox') != -1) {
				if(campoForm.checked == false) {
					alert('No has rellenado el campo ' + datosCheck[1]);
					return false;
				}
			}
			if(datosCheck[0].indexOf('radio') != -1) {
				var radioCheck = 0;
				eval('var radioElemento = frm.' + campoForm.name);
				for(j=0;j<radioElemento.length;j++) {
					if(radioElemento[j].checked) {
						radioCheck = 1;
						break;
					}
				}
				if(radioCheck == 0) {
					alert('No has rellenado el campo ' + datosCheck[1]);
					return false;
				}
			}
			if(datosCheck[0].indexOf('select') != -1) {
				if(campoForm.selectedIndex == 0) {
					if ((datosCheck[1]=="Colegio" && frm.equipo_colegio_new.value!="") || (datosCheck[1]=="Club" && frm.equipo_club_new.value!="")) {
						//Tengo relleno el campo colegio_new
					}
				else {
					alert('No has rellenado el campo ' + datosCheck[1]);
					return false;
				}
				}
			}
			if(datosCheck[0].indexOf('selectMultiple') != -1) {
				seleccion = 0
				for(j=1;j<campoForm.length;j++) {
					if(campoForm.options[j].selected == true)
						seleccion = 1
				}
				if(seleccion == 0) {
					alert('No has rellenado el campo ' + datosCheck[1]);
					return false;
				}
			}
			var expReg = /[^A-Za-z0-9ñÑáéíóúÁÉÍÓÚüÜ_\s\¿\?\¡\!\<\>\.\,\:\;\(\)\@\#\$\€\%\&\\\/\*\=\+\-\{\}\[\]\ç\º\ª]/i;
			if(datosCheck[0].indexOf('parsear') != -1) {
				if(expReg.test(campoForm.value)) {
					alert('El campo ' + datosCheck[1] + ' no es válido\n');
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('min') != -1) {
				posicion = datosCheck[0].indexOf('min') + 3;
				limite = "0";
				while((!isNaN(datosCheck[0].substring(posicion,posicion + 1))) && (posicion < datosCheck[0].length)) {
					limite = limite + datosCheck[0].substring(posicion,posicion + 1);
					posicion = posicion + 1;
				}
				limite = parseInt(limite,10);
				if(campoForm.value.length < limite) {
					alert('El campo ' + datosCheck[1] + ' tiene que tener al menos ' + limite + ' caracteres\n');
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('max') != -1) {
				posicion = datosCheck[0].indexOf('max') + 3;
				limite = "0";
				while((!isNaN(datosCheck[0].substring(posicion,posicion + 1))) && (posicion < datosCheck[0].length)) {
					limite = limite + datosCheck[0].substring(posicion,posicion + 1);
					posicion = posicion + 1;
				}
				limite = parseInt(limite,10);
				if(campoForm.value.length > limite) {
					alert('El campo ' + datosCheck[1] + ' tiene que como máximo ' + limite + ' caracteres\n');
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('foto') != -1) {
				if((campoForm.value != "") && !fotoValida(campoForm.value)) {
					alert('El formato de la foto no es correcta. Verifique que es un JPEG o un GIF o que el nombre no tiene espacios, acentos o caracteres extraños.');
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('acepto') != -1) {
				if(campoForm.checked == false) {
					alert('Tienes que aceptar las condiciones');
					return false;
				}
			}
			if(datosCheck[0].indexOf("DNI") != -1) {
				if(campoForm.value == "") {
					alert('No has rellenado el campo ' + datosCheck[1]);
					campoForm.focus();
					return false;
				}
				var numDni = campoForm.value;
				numDni = numDni.substring(0, 8);
				if(isNaN(numDni)) {
					window.alert("El DNI introducido no es válido.");
					campoForm.focus();
					return false;
				}	
				if(numDni.length < 8) {
					window.alert("El DNI introducido no es válido.");
					campoForm.focus();
					return false;
				}	
			}
			if(datosCheck[0].indexOf("movil") != -1) {
				var numMov = campoForm.value;
				if(numMov.length < 9) {
					window.alert("El Teléfono introducido no es válido.");
					campoForm.focus();
					return false;
				}	
			}

			if(datosCheck[0].indexOf('precio') != -1) {
				if((campoForm.value != "") && !precioValido(campoForm.value)) {
					alert('El formato del precio no es correcto. El formato correcto es 1000,11.');
					campoForm.focus();
					return false;
				}
			}
		}
    }
    return true;
  }

  function cambioFoto(id_foto) {
		var frm = document.frmAnuncio;

		var http = createRequestObject();
		http.open("get", "/acciones-bbdd.php?accion=obtener-fotos&id_anuncio=" + frm.id_anuncio.value + "&id_foto=" + id_foto + "&r=" + Math.random());
		http.onreadystatechange = function () {
			if(http.readyState == 4){
				if (http.responseText) {
						var resp = http.responseText;
						document.getElementById('div_fotos').innerHTML = resp;
						
				}
			}
		};
		http.send(null);
  }

  function contactar() {
		var frm = document.frmContacto;
		frm.accion.value = 'contactar';


		var httpPost = createRequestObject();
		httpPost.open("post", "/acciones-bbdd.php", true);
		httpPost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpPost.onreadystatechange = function () {
			if(httpPost.readyState == 4){
				if (httpPost.responseText) {
						var resp = httpPost.responseText;
						//alert(resp);
						if(resp.indexOf("###") != -1) {
							var arr = resp.split("###");
							alert(arr[0]);
							if(arr[1] != '') {
								eval("var element = document.getElementById('" + arr[1] + "');");
								if(element) {
									frm.elements[arr[1]].focus();
								}
							}
						} else {
							document.getElementById('formulario-contacto').style.display = 'none';
							document.getElementById('formulario-contacto-OK').style.display = 'block';
						}
				}
			}
		};
		httpPost.send(getParametros(frm));
  }

  function pujar() {
		var frm = document.frmPuja;
		frm.accion.value = 'pujar';


		var httpPost = createRequestObject();
		httpPost.open("post", "/acciones-bbdd.php", true);
		httpPost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpPost.onreadystatechange = function () {
			if(httpPost.readyState == 4){
				if (httpPost.responseText) {
						var resp = httpPost.responseText;
						//alert(resp);
						if(resp.indexOf("###") != -1) {
							var arr = resp.split("###");
							alert(arr[0]);
							if(arr[1] != '') {
								eval("var element = document.getElementById('" + arr[1] + "');");
								if(element) {
									frm.elements[arr[1]].focus();
								}
							}
						} else {
							document.getElementById('formulario-contacto').style.display = 'none';
							document.getElementById('formulario-contacto-OK').style.display = 'block';
						}
				}
			}
		};
		httpPost.send(getParametros(frm));
  }

  function contactarSIO() {
		var frm = document.frmContacto;
		frm.accion.value = 'contactar-sio';


		var httpPost = createRequestObject();
		httpPost.open("post", "/acciones-bbdd.php", true);
		httpPost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpPost.onreadystatechange = function () {
			if(httpPost.readyState == 4){
				if (httpPost.responseText) {
						var resp = httpPost.responseText;
						//alert(resp);
						if(resp.indexOf("###") != -1) {
							var arr = resp.split("###");
							//alert(arr[0]);
							if(arr[1] != '') {
								eval("var element = document.getElementById('" + arr[1] + "');");
								if(element) {
									frm.elements[arr[1]].focus();
								}
							}
						} else {
							document.getElementById('formulario-contacto').style.display = 'none';
							document.getElementById('formulario-contacto-OK').style.display = 'block';
						}
				}
			}
		};
		httpPost.send(getParametros(frm));
  }

  function sugerirSIO() {
		var frm = document.frmSugerencias;
		frm.accion.value = 'sugerir-sio';


		var httpPost = createRequestObject();
		httpPost.open("post", "/acciones-bbdd.php", true);
		httpPost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpPost.onreadystatechange = function () {
			if(httpPost.readyState == 4){
				if (httpPost.responseText) {
						var resp = httpPost.responseText;
						//alert(resp);
						if(resp.indexOf("###") != -1) {
							var arr = resp.split("###");
							//alert(arr[0]);
							if(arr[1] != '') {
								eval("var element = document.getElementById('" + arr[1] + "');");
								if(element) {
									frm.elements[arr[1]].focus();
								}
							}
						} else {
							document.getElementById('formulario-contacto').style.display = 'none';
							document.getElementById('formulario-contacto-OK').style.display = 'block';
						}
				}
			}
		};
		httpPost.send(getParametros(frm));
  }

  function recordarContrasenia() {
		var frm = document.frmLogin;
		frm.accion.value = 'recordar-pass';


		var httpPost = createRequestObject();
		httpPost.open("post", "/acciones-bbdd.php", true);
		httpPost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpPost.onreadystatechange = function () {
			if(httpPost.readyState == 4){
				if (httpPost.responseText) {
						var resp = httpPost.responseText;
						//alert(resp);
						if(resp.indexOf("###") != -1) {
							var arr = resp.split("###");
							alert(arr[0]);
							if(arr[1] != '') {
								eval("var element = document.getElementById('" + arr[1] + "');");
								if(element) {
									frm.elements[arr[1]].focus();
								}
							}
						} else {
							alert("Te hemos enviado un email con tu contraseña de registro en SubastasInmobiliariasOnLine.com");
							//document.getElementById('formulario-registro').style.display = 'none';
							
							//document.getElementById('formulario-registro-OK').style.display = 'block';
						}
				}
			}
		};
		httpPost.send(getParametros(frm));
  }

  function buscarMapa() {
		var frm = document.frmBuscadorMapa;
		var datos_tipo = frm.sel_tipos.value;
		var datos_provincia = frm.sel_provincia.value;
		var datos_municipio = frm.sel_municipio.value;
		var regimen = frm.sel_alquilersubasta.value;
		
		if(datos_tipo.indexOf("###") > 0) {
			var arr1 = datos_tipo.split("###");
			var id_tipo = arr1[0];
			var tipo = arr1[1];
		} else {
			var id_tipo = 15000;
			var tipo = 'todos-tipos';
		}
		if(datos_provincia.indexOf("###") > 0) {
			var arr2 = datos_provincia.split("###");
			var id_provincia = arr2[0];
			var provincia = arr2[1];
		} else {
			var id_provincia = 25000;
			var provincia = 'todas-provincias';
		}
		if(datos_municipio.indexOf("###") > 0) {
			var arr3 = datos_municipio.split("###");
			var id_municipio = arr3[0];
			var municipio = arr3[1];
		} else {
			var id_municipio = 35000;
			var municipio = 'todos-municipios';
		}

		if(tipo == 'todos-tipos' && provincia == 'todas-provincias' && municipio == 'todos-municipios' && regimen == 'alquileres-subastas') {
			alert('Selecciona algún criterio de búsqueda');
			return;
		}

		document.location.href = '/buscador/mapa/' + tipo + '/' + id_tipo + '/' + provincia + '/' + id_provincia + '/' + municipio + '/' + id_municipio + '/' + regimen;
  }

  function buscarPrecio() {
		var frm = document.frmBuscadorTexto;
		var datos_tipo = frm.sel_tipos.value;
		var datos_provincia = frm.sel_provincia.value;
		var datos_municipio = frm.sel_municipio.value;
		var datos_precios = frm.sel_precios.value;
		var regimen = frm.sel_alquilersubasta.value;
		
		if(datos_tipo.indexOf("###") > 0) {
			var arr1 = datos_tipo.split("###");
			var id_tipo = arr1[0];
			var tipo = arr1[1];
		} else {
			var id_tipo = 15000;
			var tipo = 'todos-tipos';
		}
		if(datos_provincia.indexOf("###") > 0) {
			var arr2 = datos_provincia.split("###");
			var id_provincia = arr2[0];
			var provincia = arr2[1];
		} else {
			var id_provincia = 25000;
			var provincia = 'todas-provincias';
		}
		if(datos_municipio.indexOf("###") > 0) {
			var arr3 = datos_municipio.split("###");
			var id_municipio = arr3[0];
			var municipio = arr3[1];
		} else {
			var id_municipio = 35000;
			var municipio = 'todos-municipios';
		}
		if(datos_precios != '') {
			var id_precio = datos_precios;
			var precio = 'precio';
		} else {
			var id_precio = 45000;
			var precio = 'todos-precios';
		}

		if(tipo == 'todos-tipos' && provincia == 'todas-provincias' && municipio == 'todos-municipios' && precio == 'todos-precios'  && regimen == 'alquileres-subastas') {
			alert('Selecciona algún criterio de búsqueda');
			return;
		}

		document.location.href = '/buscador/otros/' + tipo + '/' + id_tipo + '/' + provincia + '/' + id_provincia + '/' + municipio + '/' + id_municipio + '/' + precio + '/' + id_precio + '/' + regimen;
  }

  function buscarRefina() {
		var frm = document.frmBuscadorRefina;
		var datos_tipo = frm.sel_tipos.value;
		var datos_provincia = frm.sel_provincia.value;
		var datos_municipio = frm.sel_municipio.value;
		var regimen = "alquileres-subastas";
		var datos_precios = frm.sel_precios.value;
		var datos_habitaciones = frm.sel_habitaciones.value;
		var datos_banios = frm.sel_banios.value;
		
		if(datos_tipo.indexOf("###") > 0) {
			var arr1 = datos_tipo.split("###");
			var id_tipo = arr1[0];
			var tipo = arr1[1];
		} else {
			var id_tipo = 15000;
			var tipo = 'todos-tipos';
		}
		if(datos_provincia.indexOf("###") > 0) {
			var arr2 = datos_provincia.split("###");
			var id_provincia = arr2[0];
			var provincia = arr2[1];
		} else {
			var id_provincia = 25000;
			var provincia = 'todas-provincias';
		}
		if(datos_municipio.indexOf("###") > 0) {
			var arr3 = datos_municipio.split("###");
			var id_municipio = arr3[0];
			var municipio = arr3[1];
		} else {
			var id_municipio = 35000;
			var municipio = 'todos-municipios';
		}
		if(datos_precios != '') {
			var id_precio = datos_precios;
			var precio = 'precio';
		} else {
			var id_precio = 45000;
			var precio = 'todos-precios';
		}
		if(datos_habitaciones != '') {
			var id_habitaciones = datos_habitaciones;
			var habitaciones = 'habitaciones';
		} else {
			var id_habitaciones = 45000;
			var precio = 'todos-habitaciones';
		}
		if(datos_banios != '') {
			var id_banios = datos_banios;
			var banios = 'banios';
		} else {
			var id_banios = 45000;
			var banios = 'todos-banios';
		}

		if(tipo == 'todos-tipos' && provincia == 'todas-provincias' && municipio == 'todos-municipios' && precio == 'todos-precios' && habitaciones == 'todos-habitaciones' && banios == 'todos-banios' && regimen == 'alquileres-subastas') {
			alert('Selecciona algún criterio de búsqueda');
			return;
		}

		document.location.href = '/buscador/mapa/' + tipo + '/' + id_tipo + '/' + provincia + '/' + id_provincia + '/' + municipio + '/' + id_municipio + '/' + regimen + '/' + precio + '/' + id_precio + '/' + habitaciones + '/' + id_habitaciones + '/' + banios + '/' + id_banios;
  }

  function agregarFav() { 
	if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) { 
		var url="http://www.subastasinmobiliariasonline.com"; 
		var titulo=" SubastasInmobiliariasOnLine.com"; 
		window.external.AddFavorite(url,titulo); 
	} else { 
		if(navigator.appName == "Netscape") 
		alert (" Presiona Crtl+D para agregar esta web a tus Favoritos "); 
	} 
 } 


	