function fbuscar(){
	cadena = document.getElementById('textobusqueda').value;
	if(cadena.length < 2){
		alert('Por favor, escriba al menos 2 caracteres para realizar la búsqueda.');
		return false;
	} else {
		cadena = cadena.replace(/ /g, "-");
		//document.getElementById('buscador').action = "/buscar/"+cadena+"/";
		document.location.href = "/buscar/"+cadena+"/";
		return false;
	}
}

function alta(){
	nuevaventana('/alta/index.htm',400,320,'no','ventana1');
}

function nuevaventana(archivo,ancho,alto,barras,nombreventana) {
	var ventana;
	if (document.all || document.layers || document.getElementById){
		w=screen.availWidth; h=screen.availHeight;}
	else {w=800; H=600;}
	if (!barras) {var barras = "yes";} 
	if (!nombreventana) {var nombreventana = "";} 
	if (barras=="yes") {ancho=ancho+25;} 
	ventana = window.open(archivo,nombreventana,"toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars="+barras+",resizable=no,width="+ancho+",height="+alto);
	ventana.moveTo(parseInt((w-ancho)/2),parseInt((h+40-alto)/2)-40);
	ventana.focus();
}

function confirm_logout(){
	if(confirm("¿Desea cerrar la sesión actual?")){
		document.location.href = "/usuario/index.php?logout";
	}
}

function compruebaDatosUsuario(){
	var nombre = document.getElementById('fornombre').value;
	var correo = document.getElementById('forcorreo').value;
	var usuario = document.getElementById('forusuario').value;
	var clave = document.getElementById('forclave').value;
	var clave2 = document.getElementById('forclave2').value;
	
	if(nombre!="" && correo!="" && usuario!="" && clave!="" && clave2!=""){
		if(usuario.length<4 || usuario.length>10){
			alert("El nombre de usuario debe tener entre 4 y 10 caracteres");
			return false;
		} else {
			if(clave.length<4 || clave.length>10){
				alert("La clave debe tener entre 4 y 10 caracteres");
				return false;
			} else {
				if(clave != clave2){
					alert("Las dos claves no coinciden.");
					return false
				} else return true;
			}
		}
	} else {
		alert("Debe rellenar todos los campos antes de enviar el formulario.");
		return false;
	}
}

function compruebaFormValoracion(){
	if(document.getElementById('v_comentario').value != ""){
		return true;
	} else {
		alert("Debe escribir algún comentario acerca de este establecimiento.");
		return false;
	}
}

function compruebaFormNuevoMensaje(){
	if(document.getElementById('m_texto').value == ""){
		alert("Debe rellenar el campo correspondiente al mensaje.");
		return false;
	} else if(document.getElementById('m_captcha').value == ""){
		alert("Debe escribir el código de seguridad.");
		return false;
	} else return true;
}

function compruebaFormNuevaClave(){
	if(document.getElementById('clave1').value != document.getElementById('clave2').value){
		alert("Debe escribir dos veces la misma contraseña.");
		return false;
	} else return true;
}

function irA(carpeta){
	document.location.href = "/"+carpeta+".html";
}

function chat(){ nuevaventana('/chat',800,600,'no','chatwindow');}

function anunciese(){ nuevaventana('/anunciese',800,600,'si','anunciesewindow');}

function responder(logged){
	if(logged){
		document.getElementById('div_citamensaje').innerHTML = "";
		document.getElementById('idcita').value = 0;
	}
	document.location.href = urlactual+"#nuevomensaje";
}

function responder_citando(id,logged){
	if(logged){
		var usuario = document.getElementById('mensajeusuario'+id).innerHTML;
		var texto = document.getElementById('mensajetexto'+id).innerHTML;		
		document.getElementById('div_citamensaje').innerHTML = "<div style='padding:10px;'>Cita:<br><div class='foros_mensajecita'>Iniciado por <b>"+usuario+"</b><br><i>"+texto+"</i></div></div>";
		document.getElementById('idcita').value = id;
	}
	document.location.href = urlactual+"#nuevomensaje";
}

function mostrarListado(){
	document.getElementById('pestanaListado').className = "pestanaAct";
	document.getElementById('pestanaMapa').className = "pestanaInact";
	document.getElementById('bordeipestana1').src = "/images/bordeipestanaac.gif";
	document.getElementById('bordedpestana1').src = "/images/bordedpestanaac.gif";
	document.getElementById('bordeipestana2').src = "/images/bordeipestanain.gif";
	document.getElementById('bordedpestana2').src = "/images/bordedpestanain.gif";
	document.getElementById('capaListado').style.display = 'block';
	document.getElementById('capaMapa').style.display = 'none';
	document.getElementById('imprimir1').style.display = 'block';
	document.getElementById('imprimir2').style.display = 'block';
	document.getElementById('framecambiomodo').src = "/portal/cambiomodo.php?modo=listado";
}

function mostrarMapa(n,pag,textual){
	document.getElementById('pestanaListado').className = "pestanaInact";
	document.getElementById('pestanaMapa').className = "pestanaAct";
	document.getElementById('bordeipestana2').src = "/images/bordeipestanaac.gif";
	document.getElementById('bordedpestana2').src = "/images/bordedpestanaac.gif";
	document.getElementById('bordeipestana1').src = "/images/bordeipestanain.gif";
	document.getElementById('bordedpestana1').src = "/images/bordedpestanain.gif";
	document.getElementById('capaListado').style.display = 'none';
	document.getElementById('capaMapa').style.display = 'block';
	document.getElementById('imprimir1').style.display = 'none';
	document.getElementById('imprimir2').style.display = 'none';
	document.getElementById('framecambiomodo').src = "/portal/cambiomodo.php?modo=mapa";
	if(!mapaCargado){
		if(n==2) cargarMapa2(pag,textual);
		else cargarMapa(pag,textual);
		mapaCargado = true;
	}
}

function cargarMapa(pag,textual){
	document.getElementById('mapagoogle').src = "/portal/portal.buscar_mapa_google.php?&pag="+pag+"&textual="+textual;
}

function cargarMapa2(pag,textual){
	document.getElementById('mapagoogle').src = "/portal/portal.buscar_mapa_google.php?provincias&pag="+pag+"&textual="+textual;
}

function moverse(dir){
	document.location.href = dir;
}

function ses(variable,valor){
	document.getElementById('framecambiomodo').src = "/portal/cambiomodo.php?"+variable+"="+valor;
}

function ses(variable,valor,alcargar){
	document.getElementById('framecambiomodo').src = "/portal/cambiomodo.php?"+variable+"="+valor+"&alcargar="+alcargar;
}
