function entrada_usuarios() {
	var email = document.getElementById("correo").value;
	var clave = document.getElementById("clave").value;
	
	
	var errores = false;
	
	if ((email == "") && (errores == false)) {
		alert("Introduce tu dirección de correo electrónico");
		errores = true;
	}
	
	if ((clave == "") && (errores == false)) {
		alert("Introduce tu contraseña de acceso");
		errores = true;
	}
	
	if (errores == false) {
		$("#zona_usuarios").load("includes/ajax_login.php?email=" + email + "&clave=" + clave);
	}
	
}

function salida_usuarios() {
	
	if (confirm("¿Desea realmente cerrar la sesión abierta en Yocambio.com?")) {
		$("#zona_usuarios").load("includes/ajax_logout.php");
	}
}

function chg_correo() {
		if (document.getElementById("correo").value == "correo:") {
			document.getElementById("correo").value = "";
		}	
	}
	
function obl_correo() {
	if (document.getElementById("correo").value == "") {
		document.getElementById("correo").value = "correo:";
	}	
}

function chg_clave() {
		$("#clave1").hide();
		$("#clave2").show();
		document.getElementById("clave").focus();
}


function obl_clave() {
	if (document.getElementById("clave").value == "") {
		$("#clave2").hide();
		$("#clave1").show();
	}	
}

function chg_avatar(avatar) {
	var imagen = "<img src='/avatares/" + avatar + "' border='0'>";
	$("#foto_avatar").html(imagen);
	document.formulario.avatar.value = avatar;
	tb_remove();
}

function recordar_contrasena() {
	var email = document.recordar.email.value;
	
	$("#zona_recordar").load("includes/ajax_recordar.php?email=" + email);
	
}

function validar_respuesta(id) {
	var mensaje = document.getElementById("mensaje_" + id).value;
	var errores = false;
	
	if ((mensaje == "") && (errores == false)) {
		alert("Introduce tu mensaje de respuesta a este intercambio");
		errores = true;
	}

	if (errores == false) {
		$("#zona_mensaje_" + id).load("includes/ajax_cambio_mensaje.php","id=" + id + "&mensaje=" + mensaje);
	}
	
}


function entrada_usuarios_enter(e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;

	if (keycode == 13) { // Ha pulsado enter
		entrada_usuarios();
	}
}

function busquedaPalabras() {
	var txt = document.getElementById("busca_palabra").value;
	if (txt != "") {
		document.location.href = "intercambios.php?txt=" + txt;	
	}else{
		alert("Introduce un término de búsqueda...");	
	}
}
	
function busquedaProvincia() {
		var combo = document.getElementById("busca_provincia");
		var pro = combo.options[combo.selectedIndex].value;
			if (pro != "---") { 
				document.location.href = "intercambios.php?pro=" + pro;	
			}
}


function entrada_busqueda_enter(e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;

	if (keycode == 13) { // Ha pulsado enter
		busquedaPalabras();
	}
}

function cambios_usuario(id, nick) {
	
	if (confirm("¿Deseas ver todos los intercambios de " + nick + "?")) {
		document.location.href="intercambios.php?usr=" + id;
		
	}
	
}

function cambios_usuario_sin(id) {
	
	if (confirm("¿Deseas ver todos los anuncios de este usuario?")) {
		document.location.href="intercambios.php?usr=" + id;
		
	}
	
}